从SD卡播放视频文件

时间:2012-09-14 12:18:26

标签: android

我正在尝试从SD卡播放视频,我已经在eclipse中从DDMS视图将视频推送到mnt / sdcard文件夹中。但是模拟器屏幕显示空白而没有任何错误。请帮助。

public class Video extends Activity {
private MediaController mc;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    videoPlayer("mnt/sdcard","bikekid",true);
}


public void videoPlayer(String path, String fileName, boolean autoplay){
    //get current window information, and set format, set it up differently, if you need some special effects
    getWindow().setFormat(PixelFormat.TRANSLUCENT);
    //the VideoView will hold the video
    VideoView videoHolder = new VideoView(this);
    //MediaController is the ui control howering above the video (just like in the default youtube player).
    videoHolder.setMediaController(new MediaController(this));
    //assing a video file to the video holder
    videoHolder.setVideoURI(Uri.parse(path+"/"+fileName));
    //get focus, before playing the video.
    videoHolder.requestFocus();
    if(autoplay){
        videoHolder.start();
    }

 }

}/// end class

1 个答案:

答案 0 :(得分:0)

使用

.getAbsolutePath() 

而不是"mnt/sdcard"

编辑:

使用此

File file = new File(Environment.getExternalStorageDirectory(),"bikekid");
Uri mUri = Uri.fromFile(fie);
videoHolder.setVideoURI(mUri);