This repository has been archived by the owner on Apr 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Android] Support third part media player on Crosswalk
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
Showing
2 changed files
with
138 additions
and
9 deletions.
There are no files selected for viewing
123 changes: 123 additions & 0 deletions
123
media/base/android/java/src/org/chromium/media/ExMediaPlayer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
// Copyright (c) 2016 Intel Corporation. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package org.chromium.media; | ||
|
||
import android.content.Context; | ||
import android.media.MediaPlayer; | ||
import android.media.MediaPlayer.TrackInfo; | ||
import android.net.Uri; | ||
import android.view.Surface; | ||
|
||
import org.chromium.base.Log; | ||
|
||
import java.io.FileDescriptor; | ||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
/** | ||
* Use Android system MediaPlayer by default. | ||
*/ | ||
public class ExMediaPlayer { | ||
private static final String TAG = "ExMediaPlayer"; | ||
|
||
private MediaPlayer mPlayer; | ||
|
||
protected MediaPlayer getLocalPlayer() { | ||
if (mPlayer == null) { | ||
mPlayer = new MediaPlayer(); | ||
Log.d(TAG, "Create a Android System Media Player"); | ||
} | ||
return mPlayer; | ||
} | ||
|
||
public void setSurface(Surface surface) { | ||
getLocalPlayer().setSurface(surface); | ||
} | ||
|
||
public void setDataSource(Context context, Uri uri, Map<String, String> headers) | ||
throws Exception { | ||
getLocalPlayer().setDataSource(context, uri, headers); | ||
} | ||
|
||
public void setDataSource(FileDescriptor fd, long offset, long length) throws IOException { | ||
getLocalPlayer().setDataSource(fd, offset, length); | ||
} | ||
|
||
public void setDataSource(Context context, Uri uri) throws IOException { | ||
getLocalPlayer().setDataSource(context, uri); | ||
} | ||
|
||
public void prepareAsync() throws IllegalStateException { | ||
getLocalPlayer().prepareAsync(); | ||
} | ||
|
||
public TrackInfo[] getTrackInfo() throws RuntimeException { | ||
return getLocalPlayer().getTrackInfo(); | ||
} | ||
|
||
public boolean isPlaying() { | ||
return getLocalPlayer().isPlaying(); | ||
} | ||
|
||
public int getVideoWidth() { | ||
return getLocalPlayer().getVideoWidth(); | ||
} | ||
|
||
public int getVideoHeight() { | ||
return getLocalPlayer().getVideoHeight(); | ||
} | ||
|
||
public int getCurrentPosition() { | ||
return getLocalPlayer().getCurrentPosition(); | ||
} | ||
|
||
public int getDuration() { | ||
return getLocalPlayer().getDuration(); | ||
} | ||
|
||
public void release() { | ||
getLocalPlayer().release(); | ||
} | ||
|
||
public void setVolume(float volume1, float volume2) { | ||
getLocalPlayer().setVolume((float) volume1, (float) volume2); | ||
} | ||
|
||
public void start() { | ||
getLocalPlayer().start(); | ||
} | ||
|
||
public void pause() { | ||
getLocalPlayer().pause(); | ||
} | ||
|
||
public void seekTo(int msec) { | ||
getLocalPlayer().seekTo(msec); | ||
} | ||
|
||
public void setOnBufferingUpdateListener(MediaPlayer.OnBufferingUpdateListener listener) { | ||
getLocalPlayer().setOnBufferingUpdateListener(listener); | ||
} | ||
|
||
public void setOnCompletionListener(MediaPlayer.OnCompletionListener listener) { | ||
getLocalPlayer().setOnCompletionListener(listener); | ||
} | ||
|
||
public void setOnErrorListener(MediaPlayer.OnErrorListener listener) { | ||
getLocalPlayer().setOnErrorListener(listener); | ||
} | ||
|
||
public void setOnPreparedListener(MediaPlayer.OnPreparedListener listener) { | ||
getLocalPlayer().setOnPreparedListener(listener); | ||
} | ||
|
||
public void setOnSeekCompleteListener(MediaPlayer.OnSeekCompleteListener listener) { | ||
getLocalPlayer().setOnSeekCompleteListener(listener); | ||
} | ||
|
||
public void setOnVideoSizeChangedListener(MediaPlayer.OnVideoSizeChangedListener listener) { | ||
getLocalPlayer().setOnVideoSizeChangedListener(listener); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters