Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
[Android] Support third part media player on Crosswalk
Browse files Browse the repository at this point in the history
A requirement from an important customer who want to forward web resources with proxy
on Crosswalk, but android system MediaPlayer can't set a proxy with a standard API.
The ExoMediaPlayer is playing videos and music is a popular activity on Android devices,
and it can be configured with proxy.
https://developer.android.com/guide/topics/media/exoplayer.html

BUG=XWALK-6770
  • Loading branch information
fujunwei committed Aug 31, 2016
1 parent 7e0c695 commit 8fcaeac
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,18 @@
*/
@JNINamespace("media")
public class MediaPlayerBridge {

/**
* Give the host application a chance to take over MeidaPlayer.
*/
public static class ResourceLoadingFilter {
public boolean shouldOverrideResourceLoading(
MediaPlayer mediaPlayer, Context context, Uri uri) {
return false;
}

public MediaPlayer getExternalMediaPlayer() {
return null;
}
}

private static ResourceLoadingFilter sResourceLoadFilter = null;
Expand Down Expand Up @@ -80,7 +86,8 @@ protected void destroy() {

protected MediaPlayer getLocalPlayer() {
if (mPlayer == null) {
mPlayer = new MediaPlayer();
mPlayer = sResourceLoadFilter.getExternalMediaPlayer();
if (mPlayer == null) mPlayer = new MediaPlayer();
}
return mPlayer;
}
Expand Down Expand Up @@ -202,9 +209,9 @@ protected boolean setDataSource(
headersMap.put("allow-cross-domain-redirect", "false");
}
try {
if (sResourceLoadFilter != null &&
sResourceLoadFilter.shouldOverrideResourceLoading(
getLocalPlayer(), context, uri)) {
if (sResourceLoadFilter != null
&& sResourceLoadFilter.shouldOverrideResourceLoading(
getLocalPlayer(), context, uri)) {
return true;
}
getLocalPlayer().setDataSource(context, uri, headersMap);
Expand Down

0 comments on commit 8fcaeac

Please sign in to comment.