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):
The main point is that the
MediaPlayerdoes playback audio/mpeg (both ways - through URL and through customMediaDataSource), but audio/aacp streams could be played back only via URL asDataSource.
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();
} else if (scheme != null) {
// handle non-file sources
nativeSetDataSource(
MediaHTTPService.createHttpServiceBinderIfNecessary(path),
path,
keys,
values);
return;
}
MediaPlayer uses MediaHTTPService 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.