Skip to content Skip to sidebar Skip to footer

How Do I Use Custom Android.media.mediadatasource Along With Android.media.mediaplayer?

I know Android's MediaPlayer is a great thing. It allows us to play local files as well as media streams. And it is quite easy to use (just for example): MediaPlayer mediaPlayer =

Solution 1:

The main point is that the MediaPlayer does playback audio/mpeg (both ways - through URL and through custom MediaDataSource), but audio/aacp streams could be played back only via URL as DataSource.

So, let's understand what's happening under the hoods.

When you are passing an URL as a data source, then this check is being performed:

if ("file".equals(scheme)) {
        path = uri.getPath();
    } elseif (scheme != null) {
        // handle non-file sources
        nativeSetDataSource(
            MediaHTTPService.createHttpServiceBinderIfNecessary(path),
            path,
            keys,
            values);
        return;
    }

MediaPlayerusesMediaHTTPService class, which is responsible for providing data from http, https and widevine protocols. MediaHTTPService internally uses MediaHTTPConnection, which takes all the heavy lifting for working with that type of streams. Unfortunately, these APIs are not public (yet), but you can see how connection establishing is done in MediaHTTPConnection sources (particularly seekTo method). So, the custom data source that you provide to MediaPlayer should depict approximately the logics, that MediaHTTPConnection class implements.

Post a Comment for "How Do I Use Custom Android.media.mediadatasource Along With Android.media.mediaplayer?"