如何从与Android设备的原始文件夹播放视频? [英] How to play video from raw folder with Android device?
问题描述
请帮忙,
如何从原始文件夹中起到的Android设备的视频离线模式?
Please help, How to play videos in android device from raw folder for offline mode?
成功例1:我可以播放视频从SD卡用下面的code。
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水库/原始文件夹?
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文件夹下的文件夹原料。它必须是支持的格式(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屋!