Skip to content

Commit 2253eea

Browse files
Teng-Hui ZhuAndroid (Google) Code Review
authored andcommitted
Add context support into the filter framework.
Basically we need the context to pass the content URI into MediaPlayer. bug:6837809 Change-Id: I9390b57baff06f80246584fb3a4b746e1a308ff2
1 parent 02df84a commit 2253eea

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

media/mca/filterpacks/java/android/filterpacks/videosrc/MediaSource.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import android.filterfw.format.ImageFormat;
3636
import android.graphics.SurfaceTexture;
3737
import android.media.MediaPlayer;
38+
import android.net.Uri;
3839
import android.os.ConditionVariable;
3940
import android.opengl.Matrix;
4041
import android.view.Surface;
@@ -64,6 +65,12 @@ public class MediaSource extends Filter {
6465
@GenerateFieldPort(name = "sourceAsset", hasDefault = true)
6566
private AssetFileDescriptor mSourceAsset = null;
6667

68+
/** The context for the MediaPlayer to resolve the sourceUrl.
69+
* Make sure this is set before the sourceUrl to avoid unexpected result.
70+
* If the sourceUrl is not a content URI, it is OK to keep this as null. */
71+
@GenerateFieldPort(name = "context", hasDefault = true)
72+
private Context mContext = null;
73+
6774
/** Whether the media source is a URL or an asset file descriptor. Defaults
6875
* to false.
6976
*/
@@ -459,7 +466,11 @@ synchronized private boolean setupMediaPlayer(boolean useUrl) {
459466
try {
460467
if (useUrl) {
461468
if (mLogVerbose) Log.v(TAG, "Setting MediaPlayer source to URI " + mSourceUrl);
462-
mMediaPlayer.setDataSource(mSourceUrl);
469+
if (mContext == null) {
470+
mMediaPlayer.setDataSource(mSourceUrl);
471+
} else {
472+
mMediaPlayer.setDataSource(mContext, Uri.parse(mSourceUrl.toString()));
473+
}
463474
} else {
464475
if (mLogVerbose) Log.v(TAG, "Setting MediaPlayer source to asset " + mSourceAsset);
465476
mMediaPlayer.setDataSource(mSourceAsset.getFileDescriptor(), mSourceAsset.getStartOffset(), mSourceAsset.getLength());

0 commit comments

Comments
 (0)