|
35 | 35 | import android.filterfw.format.ImageFormat; |
36 | 36 | import android.graphics.SurfaceTexture; |
37 | 37 | import android.media.MediaPlayer; |
| 38 | +import android.net.Uri; |
38 | 39 | import android.os.ConditionVariable; |
39 | 40 | import android.opengl.Matrix; |
40 | 41 | import android.view.Surface; |
@@ -64,6 +65,12 @@ public class MediaSource extends Filter { |
64 | 65 | @GenerateFieldPort(name = "sourceAsset", hasDefault = true) |
65 | 66 | private AssetFileDescriptor mSourceAsset = null; |
66 | 67 |
|
| 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 | + |
67 | 74 | /** Whether the media source is a URL or an asset file descriptor. Defaults |
68 | 75 | * to false. |
69 | 76 | */ |
@@ -459,7 +466,11 @@ synchronized private boolean setupMediaPlayer(boolean useUrl) { |
459 | 466 | try { |
460 | 467 | if (useUrl) { |
461 | 468 | 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 | + } |
463 | 474 | } else { |
464 | 475 | if (mLogVerbose) Log.v(TAG, "Setting MediaPlayer source to asset " + mSourceAsset); |
465 | 476 | mMediaPlayer.setDataSource(mSourceAsset.getFileDescriptor(), mSourceAsset.getStartOffset(), mSourceAsset.getLength()); |
|
0 commit comments