Playback support - MShekow/stop-it GitHub Wiki
While almost all players implement basic features of the Media API (and thus, make it possible to record bookmarks), playing back a previously recorded audio bookmark is sometimes impossible, for one of two reasons:
- The
MediaMetadata
object provided by theMediaController.Callback.onPlaybackStateChanged()
callback does not provide any media ID (usingMediaMetadata.getString(MediaMetadata.METADATA_KEY_MEDIA_ID)
). This is too bad, because such a media ID is usually a globally unique identifier that can be used to start playback of an audio track, usingMediaController.TransportControls.playFromMediaId()
. - With a media ID missing, you can still try to use the
MediaController.TransportControls.playFromSearch(String query, Bundle extras)
. However, it's undocumented what exactly should be given to this function (just the name of the track? track + album? Separated by what?).
App name | Package | Supports play from media ID | Supports play from meta-data | Last tested on |
---|---|---|---|---|
PocketCasts | au.com.shiftyjelly.pocketcasts | Yes | ?? | 2020-06-25 |
Castbox | fm.castbox.audiobook.radio.podcast | No | Track name | 2020-06-25 |
Remarks:
- Castbox: the meta-data provide a lot of data, including a media ID and media URL, and claims that playback from those is possible. However, that is not actually true. The only thing that seems to work is
playFromSearch()
, providing the track name.
The YouTube app neither provides the Media ID nor a media URL.
Workaround: after a bookmark was created, Stop It! could try to make a HTTP request to the YouTube search API, providing the mediaMetadata.getString(MediaMetadataCompat.METADATA_KEY_TITLE)
, and filter for the result that has the exact same duration as the one given in the audio track's meta-data. This way, we can retrieve the YouTube video ID. Starting the playback for a bookmark could then be done by simply launching an intent with an URL such as https://youtu.be/<video-id>?t=<seconds>
The MediaController
of the Spotify app does not react to any playFromXYZ()
calls. And even if it did, Spotify only provides the playlist ID in the METADATA_KEY_MEDIA_ID
field, which is not very helpful. We would need the track ID instead.
Workaround: use the Spotify Android SDK to obtain the precise meta-data (track ID), and to start playback.
- Soundcloud
- Google Play Music
- AIMP
- Google Podcasts
- Podcast Addict
- Podbean
Using the Media Controller test app you can easily test it yourself. However, you need to make a few modifications:
- By default, the app starts with an Android TV UI which is barely usable on phones. Go to the
AndroidManifest.xml
and remove<action android:name="android.intent.action.MAIN" />
from the.tv.TvLauncherActivity
activity. - In the
MediaAppControllerActivity
infetchMediaInfo()
add the linesaddMediaInfo(mediaInfos, "Media ID", mediaMetadata.getString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID));
andaddMediaInfo(mediaInfos, "Media URI", mediaMetadata.getString(MediaMetadataCompat.METADATA_KEY_MEDIA_URI));
- After you installed the app for the first time, click the settings button at the top and grant notification access to the app.