问题
I want to play a video file on android emulator that I have stored in sd card. This is my code..
public class AndroidVideoViewActivity extends Activity {
private VideoView videoView=null;
private String PATH="mnt/sdcard/bmxskills.3gp";
private MediaPlayer mediaPlayer=null;
private MediaController mediaController=null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
VideoView videoView=(VideoView)findViewById(R.id.videoView);
videoView.setVideoPath("mnt/sdcard/bmxskills.3gp");
videoView.setMediaController(mediaController);
videoView.requestFocus();
videoView.start();
}
}
But when I run on emulator it shows blank screen.Please help.I have added the permissions required that is internet and external storage.
回答1:
Please check this link
OR
Replace videoView.setVideoPath("mnt/sdcard/bmxskills.3gp");
with videoView.setVideoPath("/sdcard/bmxskills.3gp");
回答2:
Use below code for that.
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<VideoView
android:id="@+id/myvideoview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
MainActivity.java
public class MainActivity extends Activity {
String SrcPath = "/sdcard/Video/Android in Spaaaaaace!_low.mp4";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
VideoView myVideoView = (VideoView)findViewById(R.id.myvideoview);
myVideoView.setVideoPath(SrcPath);
myVideoView.setMediaController(new MediaController(this));
myVideoView.requestFocus();
myVideoView.start();
}
}
回答3:
You should not test running video on the emulator itself, if you have a device laying around, use that instead. The Android emulator is quite terrible when it coming to handling videos correctly, so you may get a lot of problems that wouldn't normally be there on any Android device.
来源:https://stackoverflow.com/questions/11406603/how-to-play-a-video-file-from-sd-card