Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2253eeab authored by Teng-Hui Zhu's avatar Teng-Hui Zhu Committed by Android (Google) Code Review
Browse files

Add context support into the filter framework.

Basically we need the context to pass the content URI into MediaPlayer.
bug:6837809

Change-Id: I9390b57baff06f80246584fb3a4b746e1a308ff2
parent 02df84a3
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.filterfw.core.ShaderProgram;
import android.filterfw.format.ImageFormat;
import android.graphics.SurfaceTexture;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.ConditionVariable;
import android.opengl.Matrix;
import android.view.Surface;
@@ -64,6 +65,12 @@ public class MediaSource extends Filter {
    @GenerateFieldPort(name = "sourceAsset", hasDefault = true)
    private AssetFileDescriptor mSourceAsset = null;

    /** The context for the MediaPlayer to resolve the sourceUrl.
     * Make sure this is set before the sourceUrl to avoid unexpected result.
     * If the sourceUrl is not a content URI, it is OK to keep this as null. */
    @GenerateFieldPort(name = "context", hasDefault = true)
    private Context mContext = null;

    /** Whether the media source is a URL or an asset file descriptor. Defaults
     * to false.
     */
@@ -459,7 +466,11 @@ public class MediaSource extends Filter {
        try {
            if (useUrl) {
                if (mLogVerbose) Log.v(TAG, "Setting MediaPlayer source to URI " + mSourceUrl);
                if (mContext == null) {
                    mMediaPlayer.setDataSource(mSourceUrl);
                } else {
                    mMediaPlayer.setDataSource(mContext, Uri.parse(mSourceUrl.toString()));
                }
            } else {
                if (mLogVerbose) Log.v(TAG, "Setting MediaPlayer source to asset " + mSourceAsset);
                mMediaPlayer.setDataSource(mSourceAsset.getFileDescriptor(), mSourceAsset.getStartOffset(), mSourceAsset.getLength());