如何播放sd文件夹中的视频

发布于 2024-10-12 02:34:52 字数 440 浏览 3 评论 0原文

所以我希望这不是一个重复的问题,但是,从下面的代码来看,

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

清音悠歌 2024-10-19 02:34:52

好的,首先您需要确保在 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.

我只土不豪 2024-10-19 02:34:52

要播放 SD 卡中的视频文件,您可以尝试以下操作:

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();

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();
糖粟与秋泊 2024-10-19 02:34:52

试试下面的代码,这个wii肯定可以解决你的问题,
制作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();  
}

希望对你有帮助。

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.

远昼 2024-10-19 02:34:52

我有同样的问题并找到了解决方案。我在链接中的代码工作正常。
检查我的这个问题

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文