开发者

How to play video from sd folder

开发者 https://www.devze.com 2023-02-03 12:01 出处:网络
So I hope it\'s not a repeated question but, from the following code File f = new File(Environment.getExternalStorageDirectory(), TRYVID);

So I hope it's not a repeated question but, from the following code

File f = new File(Environment.getExternalStorageDirectory(), TRYVID);  
Uri uri = Uri.fromFile(f);
mc = new MediaController(this);
mp.setMediaController(mc);
mp.setVideoPath("/sdcard/try2.mp4");

this is part of a function that's called when a button is pressed, what i'm hoping to achieve is that when the user presses a key, the video plays but i've learned that the videoview does not play anything from the raw folder so i copied the video into the sdcard, but then after i press on the button on the emulator, it just crashes says it has to be close unexpectedly. I tried both the .setVideoPath as we开发者_开发百科ll as the .setUri but both does not work hmm anyone can point to my problem here?


Ok so first off you need to make sure that you use the .setAnchorView(View v) on your mediaController or else it wont correctly control the videoView. Also your missing your .start() to actually start the video. Having recently done something similar with streaming from an rstp video file i can tell you there there is a chance its not working because your running it on an emulator, the video playback on AVD's often doesn't work. Try running it on a physical device if you have access to one, also read the logcat to get a better idea of where the errors are happening.

I hope this helps.


For playing video files an from SD card you can try this:

String filepath = Environment.getExternalStorageDirectory()+"/a.mp4";
VideoView vv = new VideoView(getApplicationContext());
setContentView(vv);
vv.setVideoPath(filepath);
vv.setMediaController(new MediaController(this));
vv.requestFocus();
vv.start();


Try this below code this wii surely solve your problem, Make videoView,

VideoView videoView;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    videoView = (VideoView)findViewById(R.id.VideoView);        
    videoView.setVideoPath("/sdcard/blonde_secretary.3gp");
    videoView.start();  
}

I wish it will help you.


I had the same question and found the solution. My code in the link works fine. Check this question of mine

0

精彩评论

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