Playback support - MShekow/stop-it GitHub Wiki

Playback support

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:

  1. The MediaMetadata object provided by the MediaController.Callback.onPlaybackStateChanged() callback does not provide any media ID (using MediaMetadata.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, using MediaController.TransportControls.playFromMediaId().
  2. 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?).

Supported apps

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.

Unsupported apps

YouTube

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>

Spotify

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.

Apps still to be tested

  • Soundcloud
  • Google Play Music
  • AIMP
  • Google Podcasts
  • Podcast Addict
  • Podbean

How to test audio apps yourself

Using the Media Controller test app you can easily test it yourself. However, you need to make a few modifications:

  1. 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.
  2. In the MediaAppControllerActivity in fetchMediaInfo() add the lines addMediaInfo(mediaInfos, "Media ID", mediaMetadata.getString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID)); and addMediaInfo(mediaInfos, "Media URI", mediaMetadata.getString(MediaMetadataCompat.METADATA_KEY_MEDIA_URI));
  3. After you installed the app for the first time, click the settings button at the top and grant notification access to the app.
⚠️ **GitHub.com Fallback** ⚠️