Created
July 15, 2013 08:37
-
-
Save checko/5998407 to your computer and use it in GitHub Desktop.
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
diff --git a/samples/ApiDemos/src/com/example/android/apis/media/MediaPlayerDemo_Video.java b/samples/ApiDemos/src/com/example/android/apis/media/MediaPlayerDemo_Video.java | |
index 9853d67..de5a1ac 100644 | |
--- a/samples/ApiDemos/src/com/example/android/apis/media/MediaPlayerDemo_Video.java | |
+++ b/samples/ApiDemos/src/com/example/android/apis/media/MediaPlayerDemo_Video.java | |
@@ -30,9 +30,13 @@ import android.util.Log; | |
import android.view.SurfaceHolder; | |
import android.view.SurfaceView; | |
import android.widget.Toast; | |
+import android.media.MediaScannerConnection; | |
+import android.net.Uri; | |
+import android.content.Context; | |
public class MediaPlayerDemo_Video extends Activity implements | |
+ MediaScannerConnection.OnScanCompletedListener, | |
OnBufferingUpdateListener, OnCompletionListener, | |
OnPreparedListener, OnVideoSizeChangedListener, SurfaceHolder.Callback { | |
@@ -71,14 +75,12 @@ public class MediaPlayerDemo_Video extends Activity implements | |
private void playVideo(Integer Media) { | |
doCleanUp(); | |
- try { | |
- | |
switch (Media) { | |
case LOCAL_VIDEO: | |
/* | |
* TODO: Set the path variable to a local media file path. | |
*/ | |
- path = ""; | |
+ path = "/mnt/sdcard/udisk1/batman4.mp4"; | |
if (path == "") { | |
// Tell the user to provide a media file URL. | |
Toast | |
@@ -118,9 +120,19 @@ public class MediaPlayerDemo_Video extends Activity implements | |
} | |
- // Create a new media player and set the listeners | |
+ MediaScannerConnection.scanFile(this,new String[] {path}, null,this); | |
+ | |
+ | |
+ } | |
+ | |
+ public void onScanCompleted(String path, Uri uri) | |
+ { | |
+ Log.i(TAG,"path: " + path); | |
+ Log.i(TAG,"uri: " + uri); | |
+ try { | |
+ // Create a new media player and set the listeners | |
mMediaPlayer = new MediaPlayer(); | |
- mMediaPlayer.setDataSource(path); | |
+ mMediaPlayer.setDataSource(getApplicationContext(),uri); | |
mMediaPlayer.setDisplay(holder); | |
mMediaPlayer.prepare(); | |
mMediaPlayer.setOnBufferingUpdateListener(this); | |
@@ -161,7 +173,7 @@ public class MediaPlayerDemo_Video extends Activity implements | |
public void onPrepared(MediaPlayer mediaplayer) { | |
Log.d(TAG, "onPrepared called"); | |
mIsVideoReadyToBePlayed = true; | |
- if (mIsVideoReadyToBePlayed && mIsVideoSizeKnown) { | |
+ if (mIsVideoReadyToBePlayed /*&& mIsVideoSizeKnown*/) { | |
startVideoPlayback(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment