<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Marc Bächinger on Medium]]></title>
        <description><![CDATA[Stories by Marc Bächinger on Medium]]></description>
        <link>https://medium.com/@bachinger?source=rss-27823e454ddd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Pm5DLIc1dYiCFhD6GqpsQA.jpeg</url>
            <title>Stories by Marc Bächinger on Medium</title>
            <link>https://medium.com/@bachinger?source=rss-27823e454ddd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 06:26:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bachinger/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Jetpack Media3 1.0.0-beta01 — What’s new]]></title>
            <link>https://medium.com/google-exoplayer/jetpack-media3-1-0-0-beta01-whats-new-2367a712f112?source=rss-27823e454ddd------2</link>
            <guid isPermaLink="false">https://medium.com/p/2367a712f112</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[exoplayer]]></category>
            <dc:creator><![CDATA[Marc Bächinger]]></dc:creator>
            <pubDate>Tue, 28 Jun 2022 21:38:01 GMT</pubDate>
            <atom:updated>2022-06-28T22:16:14.875Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Jetpack Media3 1.0.0-beta01 — What’s new?</strong></h3><p>Jetpack Media3 1.0.0-beta01 is now out! This post highlights some of the most significant changes. As always, we recommend also taking a look at the <a href="https://developer.android.com/jetpack/androidx/releases/media3#1.0.0-beta01">full release notes</a>. Please note that the Jetpack Media3 1.0.0-beta01 release corresponds to the <a href="https://github.com/google/ExoPlayer/blob/release-v2/RELEASENOTES.md">ExoPlayer 2.18.0</a> release.</p><h3>Jetpack library versioning and API stability</h3><p>Aligned with other Jetpack libraries, Media3 follows <a href="https://developer.android.com/jetpack/androidx/versions">a semantic versioning scheme</a>. One of the key benefits of using Jetpack libraries is API stability. If you use symbols that are part of the stable API, you generally don’t need to update your code to use a new release of that library within the same major version.</p><p>This implies that this first beta release is declared functionally stable and has an API surface that remains backwards compatible within the 1.x.x versions. In Media3, some of the most commonly used APIs are marked as stable, including the Player interface and media session classes.</p><p>APIs intended for more advanced use cases are marked as unstable. To use an unstable method or class without lint warnings, you’ll need to add the OptIn annotation before using it.</p><p>Opting-in in Java:</p><pre><strong>@OptIn(markerClass = UnstableApi.class)</strong><br>private void methodUsingUnstableApis() { /* … */ }</pre><p>Opting-in in Kotlin:</p><pre><strong>@OptIn(UnstableApi::class)<br></strong>private fun methodUsingUnstableApis() { /* … */ }</pre><p>If your project uses a lot of unstable methods it may be more convenient to add this suppression to your project-wide lint.xml.</p><pre>&lt;issue id=”UnsafeOptInUsageError”&gt;<br> &lt;ignore<br> regexp=”\(markerClass = androidx\.media3\.common\.util\.UnstableApi\.class\)” /&gt;<br>&lt;/issue&gt;</pre><p>Just because part of an API is marked as unstable doesn’t mean that the API is unreliable or that you shouldn’t use it — it’s just a way of informing you that it might change in the future. We also intend to stabilize additional parts of the API over time, in order to support more media use cases. If you have a use case that isn’t possible with the existing stable API, and you think it should be, please let us know the details via our <a href="https://github.com/androidx/media/issues">issue tracker</a>.</p><h3>Changes in the session module</h3><p><strong>Adding media with MediaController</strong></p><p>Adding items with MediaController has been simplified, it is now more flexible and supports asynchronously loading required data to complete a media item sent from the controller.</p><p>A new method onAddMediaItems() has been added to MediaSession.Callback. It is called when a controller has requested to add new media items to the playlist via one of the Player.addMediaItem(s) or Player.setMediaItem(s) methods. This allows for asynchronously loading media details, for instance from a local database to build a list of media items containing all the required local properties and metadata fields.</p><p>Loading media metadata is required because the media items sent from the controller to the session don’t have a MediaItem.LocalConfiguration, and so need to be replaced with a full media item that’s playable by the underlying Player. The MediaSession.Callback implementation is able to identify the correct item by its MediaItem.mediaId or MediaItem.requestMetadata.</p><p>The new callback method is further called when a legacy MediaControllerCompat client app like Google Assistant or Android Automotive OS calls one of the following methods:</p><ul><li>MediaControllerCompat.TransportControls.prepareFromUri</li><li>MediaControllerCompat.TransportControls.playFromUri</li><li>MediaControllerCompat.TransportControls.prepareFromMediaId</li><li>MediaControllerCompat.TransportControls.playFromMediaId</li><li>MediaControllerCompat.TransportControls.prepareFromSearch</li><li>MediaControllerCompat.TransportControls.playFromSearch</li><li>MediaControllerCompat.TransportControls.addQueueItem</li></ul><p>The previous MediaItemFiller based API has been removed.</p><p><strong>MediaNotification.Provider and DefaultMediaNotificationProvider</strong></p><p>The MediaNotification.Provider is responsible for providing the media notification shown in the notification drawer. Apps can provide their own implementation or customize the DefaultMediaNotificationProvider that comes with the library. Using the DefaultMediaNotificationProvider makes sure that the notification is in sync with the custom layout on all API levels.</p><p>The DefaultMediaNotificationProvider uses a BitmapLoader for downloading artwork bitmaps. By default SimpleBitmapLoader is used. If you prefer to use a specific image downloading library like for instance Glide, you can inject your own bitmap loader.</p><p><strong>Custom commands and custom layout</strong></p><p>Custom commands are generally used by Android (System UI and Android Auto/Automotive OS) to allow apps to customize the playback controls displayed on a notification or the car UI. Media3 now implements custom session commands so that custom commands and the custom layout can be used by apps to tell Media3 how to render the media notification actions. Media3 then automatically replicates custom session commands to the legacy custom PlaybackStateCompat actions of the legacy session. A Media3 session by default receives custom commands at the session callback, no matter whether these are sent from a notification via PendingIntent (prior to Android 13) or directly to the MediaSession (starting with Android 13).</p><p><strong>Interoperability improvements</strong></p><p>Besides the new features, this release includes interoperability improvements on supported API levels. Thanks everyone for early testing and filing issues! One significant improvement is that MediaLibraryService/MediaSessionService now work nicely together with Android 12 <a href="https://developer.android.com/about/versions/12/behavior-changes-12#foreground-service-launch-restrictions">since which the foreground service starting policy has been tightened</a>. The DefaultMediaNotificationProvider now provides a unified approach for interoperability with all API levels including Android 13 with which <a href="https://developer.android.com/about/versions/13/behavior-changes-13#playback-controls">system media controls start sending commands directly to the media session</a>.</p><p>If you want to see this in code, take a look at the <a href="https://github.com/androidx/media/tree/release/demos/session">session demo app</a>.</p><h3>Changes in audio track selection</h3><p>On handheld devices, the player now applies additional channel count constraints when selecting the audio track in order to save network and battery resources. Under these constraints, when the media has multiple audio tracks available:</p><ul><li>On Android 12L+ devices that support audio spatialization, the player will select a surround sound audio track only if the platform reports it will output spatialized audio. That is when audio spatialization is <a href="https://developer.android.com/reference/android/media/Spatializer#isAvailable()">available</a>, <a href="https://developer.android.com/reference/android/media/Spatializer#isEnabled()">enabled</a> and the audio format can be <a href="https://developer.android.com/reference/android/media/Spatializer#canBeSpatialized(android.media.AudioAttributes,%20android.media.AudioFormat)">spatialized</a>. Otherwise the player will prefer a stereo track. The player will listen to events reported from the <a href="https://developer.android.com/reference/android/media/Spatializer.OnSpatializerStateChangedListener">Spatializer.OnSpatializerStateChangedListener</a> and trigger a new track selection so that the selected audio track matches the current <a href="https://developer.android.com/reference/android/media/Spatializer#nested-classeshttps://developer.android.com/reference/android/media/Spatializer">Spatializer</a> properties. This will cause a short rebuffer when the spatializer properties change.</li><li>On other devices, for Dolby surround formats (Dolby Digital, Dolby Digital Plus, Dolby Atmos) the previous behavior remains and the track with the highest channel count is preferred. For other audio formats, the player will prefer a stereo track over a surround sound one.</li></ul><p>These changes are not applied on devices with a <a href="https://developer.android.com/guide/topics/resources/providing-resources#UiModeQualifier">television UI mode</a>.</p><p>You may turn off these constraints and switch back to the previous track selection logic by setting DefaultTrackSelection.Parameters.constrainAudioChannelCountToDeviceCapabilities to false.</p><h3>Platform diagnostics</h3><p>The new release integrates ExoPlayer with Android Platform Diagnostics from Android 12. This helps to provide performance and debugging information on the device, for example when using <em>sysdump</em>. If the user enabled <a href="https://support.google.com/accounts/answer/6078260">sharing usage and diagnostics data</a>, this data may also be collected by Google together with other existing platform diagnostics data from MediaCodec, AudioTrack or MediaDrm. Apps can opt-out of contributing to platform diagnostics for ExoPlayer with ExoPlayer.Builder.setUsePlatformDiagnostics(false).</p><h3>Media3 documentation pages on DAC</h3><p>At the same time as releasing the beta version, we’ve also published some <a href="https://developer.android.com/guide/topics/media/media3">initial Media3 documentation</a>. Stay tuned for future updates of these pages and a migration guide that gives developers an overview of how to migrate from the legacy MediaSessionCompat/MediaBrowserServiceCompat to the latest Media3 stable APIs.</p><p>…</p><p>As always, we recommend taking a look at the <a href="https://developer.android.com/jetpack/androidx/releases/media3#1.0.0-beta01">full release notes</a>. Please feel free to get in touch via our <a href="https://github.com/androidx/media/issues">issue tracker</a> if you have any questions or encounter problems with the new release. Thanks for reading!</p><p>p.s., <a href="https://medium.com/google-exoplayer/were-hiring-cf9ef8e62be1">we’re hiring</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2367a712f112" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-exoplayer/jetpack-media3-1-0-0-beta01-whats-new-2367a712f112">Jetpack Media3 1.0.0-beta01 — What’s new</a> was originally published in <a href="https://medium.com/google-exoplayer">AndroidX Media3</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A top-level playlist API for ExoPlayer]]></title>
            <link>https://medium.com/google-exoplayer/a-top-level-playlist-api-for-exoplayer-abe0a24edb55?source=rss-27823e454ddd------2</link>
            <guid isPermaLink="false">https://medium.com/p/abe0a24edb55</guid>
            <dc:creator><![CDATA[Marc Bächinger]]></dc:creator>
            <pubDate>Thu, 17 Sep 2020 20:34:05 GMT</pubDate>
            <atom:updated>2020-09-18T01:00:54.175Z</atom:updated>
            <content:encoded><![CDATA[<p>In ExoPlayer 2.0, <a href="https://medium.com/google-exoplayer/exoplayer-2-x-mediasource-composition-6c285fcbca1f">MediaSource composition</a> made it possible to play sequences of media items using ConcatenatingMediaSource. ExoPlayer 2.5 added the ability to dynamically edit the sequence of media items during playback. ExoPlayer 2.12 goes a step further, directly integrating playlist support into the player’s top-level API. Along with the new playlist API, a new MediaItem class is introduced to allow media to be defined and passed to the player in a convenient way, without having to build MediaSource instances in application code. When the player receives a MediaItem, it will convert it to a MediaSource internally for playback.</p><h3>Adding items to the playlist</h3><p>Creating a playlist of media items and passing it to the player is simple, as shown below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5ed819f333df2cfa5f2d9d78f470a877/href">https://medium.com/media/5ed819f333df2cfa5f2d9d78f470a877/href</a></iframe><p>In this example, media items are created with the MediaItem.fromUri convenience method. Later in this post, we’ll learn how to build more complex media items with a MediaItem.Builder , as well as how media items are converted into MediaSource instances for playback inside the player.</p><h3>Detecting playback transitions</h3><p>The currently media item can always be queried by calling getCurrentMediaItem on the player. Detecting when the player transitions from one media item to another is as simple as implementing the EventListener.onMediaItemTransition callback. An application will commonly implement this method to update its user interface to reflect the new item being played:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8e363e2f172a106f953e2461f1ee9659/href">https://medium.com/media/8e363e2f172a106f953e2461f1ee9659/href</a></iframe><p>The reason for the transition is indicated by the reason argument, with possible values defined by @MediaItemTransitionReason. Common reasons include playback transitioning automatically when the end of an item is reached (MEDIA_ITEM_TRANSITION_REASON_AUTO) and the user seeking to a different item (MEDIA_ITEM_TRANSITION_REASON_SEEK). See the <a href="https://exoplayer.dev/doc/reference/com/google/android/exoplayer2/Player.MediaItemTransitionReason.html">@MediaItemTransitionReason Javadoc</a> for other possible reasons.</p><h3>Modifying the playlist</h3><p>The playlist can be modified by calling addMediaItem(MediaItem item), moveMediaItem(int fromIndex, int toIndex) and removeMediaItem(int index) directly on the player. Playlist modifications can be performed when the player is in any state, including before the player is prepared and while media is currently playing. More details, as well as variations of these methods for adding, moving and removing multiple media items, can be found in the <a href="https://exoplayer.dev/playlists.html">developer guide</a> and <a href="https://exoplayer.dev/doc/reference/com/google/android/exoplayer2/Player.html">Player Javadoc</a> respectively.</p><p>If you previously used ConcatenatingMediaSource, you may be familiar with passing an onCompletionAction runnable to playlist modification methods, to be executed after the modification has taken place:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b6f90507b1069d511798095ec9dbef3c/href">https://medium.com/media/b6f90507b1069d511798095ec9dbef3c/href</a></iframe><p>When using the new top-level playlist API this is unnecessary. The tighter integration of playlists into the player allows modifications to be applied synchronously, meaning such an action can be executed directly after a modification is made:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7efe3b42bf0a0b588bb19cea5ae5bae5/href">https://medium.com/media/7efe3b42bf0a0b588bb19cea5ae5bae5/href</a></iframe><p>A modification of the playlist can be detected by implementing the EventListener.onTimelineChanged callback and looking for calls where the reason argument is TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED. An application may implement this callback to update its user interface to reflect the updated playlist. See the <a href="https://exoplayer.dev/playlists.html#detecting-when-the-playlist-changes">developer guide</a> for more details.</p><h3>Building more complex media items</h3><p>We’ve already seen how MediaItem.fromUri can be used to build a simple media item. To build more complex media items, MediaItem.Builder can be used. The code snippet below demonstrates how to build a media item for an HLS stream, attaching custom application data using setTag:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/af5ec3b209664768686dc4d385a38c33/href">https://medium.com/media/af5ec3b209664768686dc4d385a38c33/href</a></iframe><p>Setting a MIME type is not generally required. It’s only needed to create HLS, DASH or SmoothStreaming media items in cases where the media URI has a non-standard file extension, in which case specifying the MIME type as MimeTypes.APPLICATION_M3U8, MimeTypes.APPLICATION_MPD or MimeTypes.APPLICATION_SS respectively acts as an explicit hint to the player.</p><p>Attaching custom application data to a media item can be useful when receiving media items back from the playlist API. For example, the data attached in the example above could be retrieved and used to update the application’s user interface when playback transitions to another media item:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c88365ad1df0b7128d0654112dc994a8/href">https://medium.com/media/c88365ad1df0b7128d0654112dc994a8/href</a></iframe><p>MediaItem.Builder supports building of MediaItem instances that specify a number of additional properties, including:</p><ul><li>Protected content properties including the DRM type, license server URI and license request headers.</li><li>Side-loaded subtitle files to use during playback.</li><li>Clipping start and end positions.</li><li>An ad tag URI for ad insertion.</li></ul><p>See the <a href="http://exoplayer.dev/media-items.html">developer guide</a> for more details.</p><h3>MediaItem to MediaSource conversion</h3><p>When a MediaItem is added to the playlist, the player converts it internally into a playable MediaSource. By default the library does this using a DefaultMediaSourceFactory.</p><p>In the simple case, DefaultMediaSourceFactory will convert a MediaItem into a ProgressiveMediaSource, DashMediaSource, HlsMediaSource or SsMediaSource, depending on the type of the media. In more complicated cases, DefaultMediaSourceFactory uses MediaSource composition to build up an appropriate corresponding MediaSource. For example, the media item defined below is for a protected and clipped DASH stream:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e944acd0db255399bb991a6f65720bfd/href">https://medium.com/media/e944acd0db255399bb991a6f65720bfd/href</a></iframe><p>In this case DefaultMediaSourceFactory will build a DrmSessionManager configured for Widevine and the specified license URI. This is then injected when building a DashMediaSource. Finally, the clipping properties are applied by wrapping the DashMediaSource in a ClippingMediaSource.</p><p>DefaultMediaSourceFactory applies other media item properties similarly. For example, MergingMediaSource is used to attach side-loaded subtitle files, and wrapping with AdsMediaSource is used to apply ad tag URIs.</p><p>Sounds complicated? The good news is that users of the new top-level playlist API only need to build the media item, and can leave it to the player to take care of building the appropriate corresponding MediaSource.</p><h4>Customizing the conversion</h4><p>DefaultMediaSourceFactory covers a wide range of use cases. However, some developers may want to implement their own MediaSource or instantiate an existing implementation in a way that cannot be specified using MediaItem. For these use cases developers can implement a custom MediaSourceFactory, which can be set when building a player with SimpleExoPlayer.Builder or ExoPlayer.Builder.</p><h4>Using MediaSources directly</h4><p>In addition to the top-level playlist API based on MediaItem, the ExoPlayer interface offers methods for setting and adding to the playlist the take MediaSource instances directly (e.g., setMediaSources(List&lt;MediaSource&gt;)). This provides another alternative to specifying a custom MediaSourceFactory for advanced use cases.</p><p>We think the new top-level playlist API makes it easier and more convenient to use ExoPlayer for a wide range of use cases. The new MediaItem class makes it possible to define media items in a declarative way, including items that are clipped, that have side-loaded subtitles, and that have ad tag URIs. DefaultMediaSourceFactory takes care of converting these media items into playable MediaSource instances internally. Advanced use cases are supported by passing a custom MediaSourceFactory, or by passing MediaSource instances directly to the player.</p><p>As always, we are keen to hear your opinion of our new API. Please let us know you questions or general feedback <a href="https://github.com/google/ExoPlayer/issues/new?assignees=&amp;labels=question%2C+needs+triage&amp;template=question.md&amp;title=">on GitHub</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=abe0a24edb55" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-exoplayer/a-top-level-playlist-api-for-exoplayer-abe0a24edb55">A top-level playlist API for ExoPlayer</a> was originally published in <a href="https://medium.com/google-exoplayer">AndroidX Media3</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Playback Notifications with ExoPlayer]]></title>
            <link>https://medium.com/google-exoplayer/playback-notifications-with-exoplayer-a2f1a18cf93b?source=rss-27823e454ddd------2</link>
            <guid isPermaLink="false">https://medium.com/p/a2f1a18cf93b</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[exoplayer]]></category>
            <category><![CDATA[notifications]]></category>
            <dc:creator><![CDATA[Marc Bächinger]]></dc:creator>
            <pubDate>Mon, 19 Mar 2018 16:09:58 GMT</pubDate>
            <atom:updated>2018-03-19T20:58:41.063Z</atom:updated>
            <content:encoded><![CDATA[<p>Displaying a notification with playback controls is a best practice for media apps on Android. For audio playback in the background it’s even <a href="https://developer.android.com/about/versions/oreo/background.html">a requirement to attach a foreground service to a notification</a>. To help make this task easier, we’ve added a new PlayerNotificationManager component to ExoPlayer’s UI module (currently <a href="https://github.com/google/ExoPlayer/tree/dev-v2/library/ui/src/main/java/com/google/android/exoplayer2/ui">available in the dev-2 branch</a>). Once attached to a player, the manager will post a notification and keep it in sync with the state and the timeline of the player.</p><p>This can be achieved in three steps:</p><ol><li>Create a PlayerNotificationManager instance.</li><li>Create a PlayerNotificationManager.MediaDescriptionAdapter to provide descriptive data for the current playing media item.</li><li>Attach the player (and detach when resources are freed).</li></ol><h4>Creating the PlayerNotificationManager</h4><p>For video playback the PlayerNotificationManager is typically instantiated in the onCreate method of an activity or a fragment. Audio apps do the same when the service, which holds the player instance, is created:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9d30c8f79a29af53b1cb0fb05acb8316/href">https://medium.com/media/9d30c8f79a29af53b1cb0fb05acb8316/href</a></iframe><p>The app passes the channel and notification id as well as the PlayerNotificationManager.MediaDescriptionAdapter to the constructor. The app implements the adapter to provide descriptive data about the current playing media item:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/717d3f5d139044ebb919d1c3332a25d5/href">https://medium.com/media/717d3f5d139044ebb919d1c3332a25d5/href</a></iframe><h4>Attach and detach the player</h4><p>Once the manager is created, the player needs to be attached when it’s instantiated:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/10c858f43dc89d7d61b4d0e383b1364f/href">https://medium.com/media/10c858f43dc89d7d61b4d0e383b1364f/href</a></iframe><p>Before the player is released, it should be detached from the notification manager, which causes the notification to be cancelled:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6628b7d45a7d0c30afdc994a77f8f73b/href">https://medium.com/media/6628b7d45a7d0c30afdc994a77f8f73b/href</a></iframe><p>With these basic steps, a notification appears as soon as playback starts and is kept in sync with the state of the player.</p><h3>Customization</h3><p>There are various ways in which you may want to customize the notification to fit to the theme of your app. The manager allows you to select which playback control actions to use and provides setters for the notification properties. All of these have a (hopefully) sensible default value but can easily be changed to desired values.</p><h4>Playback control actions</h4><p>The notification shows standard playback control actions like play/pause, fast forward/rewind, next/previous and stop which can be omitted on demand:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c22368e36ba08fa5f5d76c100f8e8d4d/href">https://medium.com/media/c22368e36ba08fa5f5d76c100f8e8d4d/href</a></iframe><p>Custom actions can be provided by an app by passing a CustomActionReceiver as the fifth parameter to the PlayerNotificationManager constructor:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/886c5ffb17d673371d75a7d7169c3276/href">https://medium.com/media/886c5ffb17d673371d75a7d7169c3276/href</a></iframe><p>A CustomActionReceiver can declare and handle additional actions placed after the playback actions.</p><h4>Notification properties</h4><p>The notification manager provides setters to customize the look and behavior of the notification. The setters correspond to properties of the <a href="https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html">NotificationCompat.Builder</a>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8ebbff225f4927f5cc89353d18c83d57/href">https://medium.com/media/8ebbff225f4927f5cc89353d18c83d57/href</a></iframe><h4>MediaSession</h4><p>Finally, if your app <a href="https://medium.com/google-exoplayer/the-mediasession-extension-for-exoplayer-82b9619deb2d">integrates with the MediaSession API</a>, for instance to <a href="https://developer.android.com/guide/topics/media-apps/interacting-with-assistant.html">support Google Assistant</a>, you can set the token of the session to take full advantage of the <a href="https://developer.android.com/reference/android/app/Notification.MediaStyle.html">media style notification</a>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c244976eccb343d52b67991ca0337f99/href">https://medium.com/media/c244976eccb343d52b67991ca0337f99/href</a></iframe><p>We believe the PlayerNotificationManager makes it easy to post notifications for media playback with ExoPlayer. We are eager to hear your opinion and requirements to make it even more useful for ExoPlayer users. Let us know on the <a href="https://github.com/google/ExoPlayer/issues/new">Github issue tracker</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a2f1a18cf93b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-exoplayer/playback-notifications-with-exoplayer-a2f1a18cf93b">Playback Notifications with ExoPlayer</a> was originally published in <a href="https://medium.com/google-exoplayer">AndroidX Media3</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The MediaSession extension for ExoPlayer]]></title>
            <link>https://medium.com/google-exoplayer/the-mediasession-extension-for-exoplayer-82b9619deb2d?source=rss-27823e454ddd------2</link>
            <guid isPermaLink="false">https://medium.com/p/82b9619deb2d</guid>
            <category><![CDATA[exoplayer2]]></category>
            <category><![CDATA[mediasession]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[exoplayer]]></category>
            <dc:creator><![CDATA[Marc Bächinger]]></dc:creator>
            <pubDate>Tue, 22 Aug 2017 19:11:32 GMT</pubDate>
            <atom:updated>2020-02-02T22:15:51.847Z</atom:updated>
            <content:encoded><![CDATA[<p>The <a href="https://developer.android.com/guide/topics/media-apps/working-with-a-media-session.html">Android MediaSession API</a> provides an abstract model with which clients can interact to monitor and control media playback via MediaController and its TransportControls. Clients like Google Assistant, <a href="https://developer.android.com/training/auto/audio/index.html#implement_callback">Android Auto</a>, <a href="https://developer.android.com/training/tv/playback/now-playing.html">Android TV</a> and Android Wear use the MediaSession API to control media apps. In addition, UI components can use the same APIs rather than depend on a specific player implementation.</p><p>Roughly, a media app publishes supported playback commands, playback state and a playback queue to the media session, which in turn broadcasts these to media controllers. The <a href="https://google.github.io/ExoPlayer/doc/reference/com/google/android/exoplayer2/ext/mediasession/MediaSessionConnector.html">MediaSessionConnector</a> of <a href="https://github.com/google/ExoPlayer/tree/release-v2/extensions/mediasession">the new media session extension for ExoPlayer</a> makes integrating with the MediaSession API much easier and does all the heavy lifting for you.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/288/1*xgjqZoP67CVMAGCtOLhCPA.png" /><figcaption>MediaSession controls and meta data in Android Auto.</figcaption></figure><h3>Integrating with the MediaSession API made easy</h3><p>The MediaSession extension mediates between an ExoPlayer instance and a <a href="https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.html">MediaSession</a>. It automatically maps the player state to the playback state of the media session, and handles actions sent by controllers.</p><p><strong>Publishing the player state<br></strong>To publish the state of the player to a media session, we just need to pass the session to the constructor of the MediaSessionConnector and set a player instance:</p><pre>MediaSessionConnector mediaSessionConnector =<br>    new MediaSessionConnector(mediaSession);<br>mediaSessionConnector.setPlayer(player);</pre><p>In addition to publishing the playback state, this MediaSessionConnector automatically handles a basic set of playback actions (ACTION_PLAY_PAUSE, ACTION_PLAY, ACTION_PAUSE, ACTION_SEEK_TO, ACTION_FAST_FORWARD, ACTION_REWIND, ACTION_STOP) by calling corresponding methods on the player.</p><p><strong>Receiving media actions<br></strong>The MediaSession API <a href="https://developer.android.com/reference/android/media/session/PlaybackState.html#constants">defines a set of media actions</a> that a media controller can send. The MediaSessionConnector receives these actions and delegates them to components registered by the app. The app can register implementations of the following interfaces with the corresponding setter, depending on which actions it wishes to handle:</p><ul><li><a href="http://google.github.io/ExoPlayer/doc/reference/index.html?com/google/android/exoplayer2/ext/mediasession/MediaSessionConnector.PlaybackPreparer.html"><strong>MediaSessionConnector.PlaybackPreparer</strong></a><br>ACTION_PREPARE, ACTION_PREPARE_FROM_MEDIA_ID, ACTION_PREPARE_FROM_SEARCH, ACTION_PREPARE_FROM_URI, ACTION_PLAY_FROM_MEDIA_ID, ACTION_PLAY_FROM_SEARCH, ACTION_PLAY_FROM_URI</li><li><strong>com.google.android.exoplayer2.</strong><a href="https://exoplayer.dev/doc/reference/index.html?com/google/android/exoplayer2/ControlDispatcher.html"><strong>ControlDispatcher</strong></a><br>ACTION_PLAY_PAUSE, ACTION_PLAY, ACTION_PAUSE, ACTION_SEEK_TO, ACTION_STOP</li><li><a href="http://google.github.io/ExoPlayer/doc/reference/index.html?com/google/android/exoplayer2/ext/mediasession/MediaSessionConnector.QueueNavigator.html"><strong>MediaSessionConnector.QueueNavigator</strong></a><br>ACTION_SKIP_TO_QUEUE_ITEM, ACTION_SKIP_TO_NEXT, ACTION_SKIP_TO_PREVIOUS, ACTION_SET_SHUFFLE_MODE_ENABLED</li><li><a href="http://google.github.io/ExoPlayer/doc/reference/index.html?com/google/android/exoplayer2/ext/mediasession/MediaSessionConnector.QueueEditor.html"><strong>MediaSessionConnector.QueueEditor</strong></a><br>ACTION_SET_RATING and all commands defined through MediaSessionCompat.Callback when the flag MediaSessionCompat.FLAG_HANDLES_QUEUE_COMMAND is set.</li><li><a href="http://google.github.io/ExoPlayer/doc/reference/index.html?com/google/android/exoplayer2/ext/mediasession/MediaSessionConnector.CustomActionProvider.html"><strong>MediaSessionConnector.CustomActionProvider</strong></a><strong><br></strong>Handles custom media actions specified by the app.</li></ul><p>For some of these interfaces, the library offers customisable default implementations to be used out of the box, like the TimelineQueueNavigator.</p><h3>Preparing the player</h3><p>The MediaSession API declares media actions to initiate playback that require creating a media source and preparing the ExoPlayer for that source. Android Auto, for example, uses these actions to initiate playback when a user chooses an item in the catalogue:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/288/1*somDZhKWhRhcEnYitcHQ5w.png" /><figcaption>Android Auto browser to initiate playback.</figcaption></figure><p>A <a href="https://github.com/google/ExoPlayer/blob/r2.5.1/extensions/mediasession/src/main/java/com/google/android/exoplayer2/ext/mediasession/MediaSessionConnector.java#L80">PlaybackPreparer</a> implementation can define which actions it supports, and handle these actions when they’re received by the connector:</p><pre>private class MyPlaybackPreparer implements<br>    MediaSessionConnector.PlaybackPreparer {</pre><pre>  @Override<br>  public void onPrepare() {<br>    // Prepare.<br>    [...]<br>  }<br><br>  @Override<br>  public void onPrepareFromMediaId(final String mediaId,<br>     Bundle extras) {<br>    // Prepare player from media id.<br>    [...]<br>  }<br><br> [...]<br><br>  @Override<br>  public long getSupportedPrepareActions() {<br>    return SUPPORTED_PREPARE_ACTIONS;<br>  }<br><br>}</pre><p>A PlaybackPreparer can be registered when calling setPlayer on the connector:</p><pre> mediaSessionConnector.setPlayer(player,<br>    <strong>new MyPlaybackPreparer()</strong>);</pre><h3>Using TimelineQueueNavigator</h3><p><a href="https://github.com/google/ExoPlayer/blob/release-v2/extensions/mediasession/src/main/java/com/google/android/exoplayer2/ext/mediasession/TimelineQueueNavigator.java">TimelineQueueNavigator</a> is an implementation of the <a href="https://github.com/google/ExoPlayer/blob/release-v2/extensions/mediasession/src/main/java/com/google/android/exoplayer2/ext/mediasession/MediaSessionConnector.java#L176">QueueNavigator</a> interface that maps the <a href="https://google.github.io/ExoPlayer/doc/reference/com/google/android/exoplayer2/Timeline.html">Timeline</a> of an ExoPlayer to the media session queue. It handles the actions ACTION_SKIP_PREVIOUS, ACTION_SKIP_NEXT and ACTION_SKIP_TO_QUEUE_ITEM to navigate in the timeline. TimelineQueueNavigator is abstract and requires developers to implement the getMediaDescription(int windowIndex) method to provide the MediaDescriptionCompat for a given window index. This enables the connector and the queue navigator to maintain playback state, metadata and queue of the media session.</p><pre>TimelineQueueNavigator queueNavigator =<br>     new TimelineQueueNavigator(mediaSession) {<br>        @Override<br>        <strong>public MediaDescriptionCompat getMediaDescription(<br>            int windowIndex) {<br>          return getMediaDescriptionAtQueuePosition(windowIndex);<br>        }</strong><br>     };</pre><pre>mediaSessionConnector.setQueueNavigator(queueNavigator);</pre><p>The app interacts with the player like before, for instance to prepare the player for a list of media items:</p><pre>// <strong>Create media sources.</strong><br>MediaSource[] mediaSources = new MediaSource[queueItems.size()];<br>for (int i = 0; i &lt; queueItems.size(); i++) {<br>  mediaSources[i] = createMediaSource(queueItems.get(i));<br>}<br>// <strong>Prepare the player.</strong><br>player.prepare(new ConcatenatingMediaSource(mediaSources));</pre><p>TimelineQueueNavigator listens for changes to the player’s state or timeline, and automatically updates the media session’s state, metadata and queue accordingly. In the other direction, the navigator seeks to the requested timeline window when a media controller sends an ACTION_SKIP_* action.</p><h3>Advertising and handling custom actions</h3><p>Apps often want to provide additional custom actions to be displayed in a player UI like Android Auto or Android Wear. The MediaSession extension comes with a <a href="https://google.github.io/ExoPlayer/doc/reference/com/google/android/exoplayer2/ext/mediasession/RepeatModeActionProvider.html">RepeatModeActionProvider</a>, which provides such a custom action for cycling through the repeat modes of the player.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/288/1*Kpmw8SvK49jUGjFCO93SbQ.png" /><figcaption>Custom repeat mode action in Android Auto.</figcaption></figure><p>Custom actions can be defined by implementing the <a href="https://google.github.io/ExoPlayer/doc/reference/com/google/android/exoplayer2/ext/mediasession/MediaSessionConnector.CustomActionProvider.html">MediaSessionConnector.CustomActionProvider</a> interface. The getCustomAction method defines whether and which action should be advertised to media controllers. When a media controller sends a custom action, the connector delegates to the onCustomAction method. The <a href="https://google.github.io/ExoPlayer/doc/reference/com/google/android/exoplayer2/ext/mediasession/RepeatModeActionProvider.html">RepeatModeActionProvider</a> illustrates this approach:</p><pre>public final class RepeatModeActionProvider implements<br>    <strong>MediaSessionConnector.CustomActionProvider</strong> {</pre><pre>  [...]</pre><pre>  <strong>@Override</strong><br>  <strong>public void onCustomAction(String action, Bundle extras) </strong>{<br>    // implement action<br>    // [...]<br>  }<br><br>  <strong>@Override</strong><br>  <strong>public PlaybackStateCompat.CustomAction getCustomAction()</strong> {<br>    CharSequence actionLabel;<br>    int iconResourceId;</pre><pre>    // evaluate what label and icon is sensible at the current state<br>    // [...]</pre><pre>    PlaybackStateCompat.CustomAction.Builder repeatBuilder =<br>        new PlaybackStateCompat.CustomAction.Builder(<br>        <em>ACTION_REPEAT_MODE</em>, actionLabel, iconResourceId);<br>    return repeatBuilder.build();<br>  }<br><br>}</pre><p>Custom action providers can be registered when calling setPlayer on the connector:</p><pre>mediaSessionConnector.setPlayer(player, playbackPreparer,<br>    <strong>CustomActionProvider... customActionProviders</strong>);</pre><p>The order in which the providers are passed determines the order in which the actions are included in the playback state of the media session.</p><h3>User readable error messages</h3><p>When streaming media over a network, things can go wrong. The least we can do is provide error messages to appropriately inform our media controller clients. By using a <a href="https://google.github.io/ExoPlayer/doc/reference/com/google/android/exoplayer2/ext/mediasession/MediaSessionConnector.ErrorMessageProvider.html">MediaSessionConnector.ErrorMessageProvider</a> you can make sure these messages are human readable:</p><pre>messageProvider = <strong>new MediaSessionConnector.ErrorMessageProvider</strong>() {<br>  @Override<br>  public Pair&lt;Integer, String&gt; getErrorMessage(<br>      ExoPlaybackException playbackException) {<br>    return getHumanReadableError(playbackException);<br>  }<br>}</pre><pre>mediaSessionConnector.<strong>setErrorMessageProvider</strong>(messageProvider);</pre><p>With the MediaSessionConnector you can easily integrate your media app with the MediaSession API. The connector does all the heavy lifting for you, whilst still giving you full control over the behaviour of all of the media actions defined by the API.</p><p>We are looking forward to seeing the connector in action in your app, and are eager to hear your feedback. File feedback and feature request on our <a href="https://github.com/google/ExoPlayer/issues">Github Issue tracker</a>. We’re keen to learn more about your requirements, and how we could make integrating with MediaSession even easier!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=82b9619deb2d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-exoplayer/the-mediasession-extension-for-exoplayer-82b9619deb2d">The MediaSession extension for ExoPlayer</a> was originally published in <a href="https://medium.com/google-exoplayer">AndroidX Media3</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>