开发者

Android-Media Player

开发者 https://www.devze.com 2023-01-16 02:16 出处:网络
I am new to android. I am trying to play a video from sdcard. this is the sample code I have used: public class videoa extends Activity {

I am new to android. I am trying to play a video from sdcard.

this is the sample code I have used:

  public class videoa extends Activity {
  /** Called when the activity is first created. */
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      this.setContentView(R.layout.main);

      VideoView videoView = (VideoView)this.findViewById(R.id.videoView);
      MediaController mc = new MediaController(this);
      videoView.setMediaController(mc);
      // (1) Web
      //videoView.setVideoURI(Uri.parse(
      //"http://www.bogotobogo.com/Video/sample.3gp"));
      //"http://www.bogotobogo.com/Video/sample.mp4"));
      //"http://www.bogotobogo.com/Video/sample.mov"));

      /* (2) SD card */
      //videoView.setVideoPath("/sdcard/sample.3gp");
      videoView.setVideoPath("/sdcard/robot.avi");
      //videoView.setVideoPath("/sdcard/sample.mov");
      // videoView.开发者_如何学GosetVideoURI(Uri.parse(
        //"file:///sdcard/sample.mov"));

      videoView.requestFocus();
      videoView.start();
  }
}

I have launched manually And set the target as -sdcard C:/android-sdk-windows/tools/sdcard.img.

When i have launched the emulator it shows Video Cannot be Displayed.

Please help me out.


You try interchanging the 2 lines

 final String MEDIA_PATH = new String("/sdcard/robot.avi");


 VideoView videoView = (VideoView)this.findViewById(R.id.videoView);
 MediaController mc = new MediaController(this);

 videoView.setVideoPath(MEDIA_PATH);

 videoView.setMediaController(mc);

 videoView.requestFocus();
 videoView.start();
0

精彩评论

暂无评论...
验证码 换一张
取 消