How Do I Use Custom Android.media.mediadatasource Along With Android.media.mediaplayer?
Solution 1:
The main point is that the
MediaPlayer
does 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();
} elseif (scheme != null) {
// handle non-file sources
nativeSetDataSource(
MediaHTTPService.createHttpServiceBinderIfNecessary(path),
path,
keys,
values);
return;
}
MediaPlayer
usesMediaHTTPService
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?"