如何播放sd文件夹中的视频
所以我希望这不是一个重复的问题,但是,从下面的代码来看,
File f = new File(Environment.getExternalStorageDirectory(), TRYVID);
Uri uri = Uri.fromFile(f);
mc = new MediaController(this);
mp.setMediaController(mc);
mp.setVideoPath("/sdcard/try2.mp4");
这是按下按钮时调用的函数的一部分,我希望实现的是,当用户按下某个键时,视频会播放,但我'我了解到 videoview 不会播放原始文件夹中的任何内容,因此我将视频复制到 SD 卡中,但是当我按下模拟器上的按钮后,它只是崩溃说它必须意外关闭。我尝试了 .setVideoPath 和 .setUri 但两者都不起作用嗯任何人都可以在这里指出我的问题吗?
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 well as the .setUri but both does not work hmm anyone can point to my problem here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
好的,首先您需要确保在 mediaController 上使用 .setAnchorView(View v) ,否则它将无法正确控制 videoView。另外,您还缺少 .start() 来实际启动视频。最近做了一些与 rstp 视频文件流类似的事情,我可以告诉你它有可能不起作用,因为你在模拟器上运行它,AVD 上的视频播放通常不起作用。如果您有权访问物理设备,请尝试在物理设备上运行它,同时阅读 logcat 以更好地了解错误发生的位置。
我希望这有帮助。
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.
要播放 SD 卡中的视频文件,您可以尝试以下操作:
For playing video files an from SD card you can try this:
试试下面的代码,这个wii肯定可以解决你的问题,
制作videoView,
希望对你有帮助。
Try this below code this wii surely solve your problem,
Make videoView,
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