开发者

Android 2.2: Problem playing video from SD card

When I try to play a video on my sd card, i get the error message "Sorry, this video cannot be played". Is there anything wrong with my code? None of the commented code seems to work.

  public void PlayVideo(View view)
{       

VideoView videoView = (VideoView) findViewById(R.id.videoView);

MediaController mediaController = new MediaController(this);

mediaController.setAnchorView(videoView);

// final String MEDIA_PATH = new String("/sdcard/yu5.mp4");

//videoView.setVideoPath(MEDIA_PATH);

//videoView.setVideoURI(Uri.fromFile(new File(Environment.getExternalStorageDirectory(),"yu5.mp4")));

//videoView.set开发者_JS百科VideoURI(Uri.parse("file:///sdcard/yu5.mp4"));

videoView.setVideoURI(Uri.parse("http://www.law.duke.edu/cspd/contest/finalists/viewentry.php?file=mfog"));

videoView.setMediaController(mediaController);

videoView.start();




}

When i stream from the web like in the code, the video is lagging a lot.


Please use Environment.getExternalStorageDirectory() for the root directory of external storage, not /sdcard, which is wrong on Android 2.2+ and other devices. Here is a sample project demonstrating playing back video from external storage.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜