如何使用 Android 设备播放原始文件夹中的视频? [英] How to play video from raw folder with Android device?

查看:39
本文介绍了如何使用 Android 设备播放原始文件夹中的视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮忙,如何在离线模式下从原始文件夹播放 Android 设备中的视频?

Please help, How to play videos in android device from raw folder for offline mode?

成功示例1:我可以使用以下代码播放SD卡中的视频.

Successful example1: I can play the video from SDcard used the below code.

 Intent intent = new Intent(Intent.ACTION_VIEW);
 String type = "video/mp4";
 Uri uri = Uri.parse("file:///sdcard/test.mp4");
 intent.setDataAndType(uri, type);
 startActivity(intent); 

失败的例子2:问:我可以将 test.mp4 放到 res/raw 文件夹中吗?

Failed example2: Question: May I put the test.mp4 to res/raw folder?

 Intent intent = new Intent(Intent.ACTION_VIEW);
 String type = "video/mp4";
 Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.taipei);
 intent.setDataAndType(uri, type);
 startActivity(intent); 

有人可以帮助我吗?请.

Have anyone can help me? Please.

推荐答案

将视频复制到项目的 res/raw 文件夹中.在 res 文件夹下创建 raw 文件夹.它必须采用受支持的格式(3gp、wmv、mp4)并在其文件名中以小写、数字、下划线和点命名,同样:video_file.mp4.

Copy the video into your project's res/raw folder. Create raw folder under res folder. It must be in a supported format (3gp, wmv, mp4 ) and named with lower case, numerics, underscores and dots in its filename likewise:video_file.mp4.

VideoView view = (VideoView)findViewById(R.id.videoView);
String path = "android.resource://" + getPackageName() + "/" + R.raw.video_file;
view.setVideoURI(Uri.parse(path));
view.start();

在您的 xml 文件中创建 videoView.

Create videoView in your xml file.

这篇关于如何使用 Android 设备播放原始文件夹中的视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆