Pot*_*ang 17 android android-layout android-videoview
请帮忙,如何在原始文件夹中播放Android设备中的视频以进行离线模式?
成功示例1:我可以使用以下代码从SDcard播放视频.
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);
Run Code Online (Sandbox Code Playgroud)
失败的示例2:问题:我可以将test.mp4放到res/raw文件夹中吗?
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);
Run Code Online (Sandbox Code Playgroud)
有谁可以帮助我?请.
Aka*_*shG 47
将视频复制到项目的res/raw文件夹中.在res文件夹下创建原始文件夹.它必须采用支持的格式(3gp,wmv,mp4),并在其文件名中以小写,数字,下划线和点命名: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();
Run Code Online (Sandbox Code Playgroud)
在xml文件中创建videoView.
小智 5
// To get files from any resource folder (eg: raw, drawable, etc.)
// Use the resource id
int rawId = getResources().getIdentifier(file_name_without_extension, "raw", getPackageName());
// URI formation
String path = "android.resource://" + getPackageName() + "/" + rawId;
// Set the URI to play video file
videoView.setVideoURI(Uri.parse(path));
Run Code Online (Sandbox Code Playgroud)
检查此解决方案How to play video in android from assetsfolder or rawfolder?
VideoView videoHolder = new VideoView(this);
//if you want the controls to appear
videoHolder.setMediaController(new MediaController(this));
Uri video = Uri.parse("android.resource://" + getPackageName() + "/"
+ R.raw.your_raw_file); //do not add any extension
//if your file is named sherif.mp4 and placed in /raw
//use R.raw.sherif
Run Code Online (Sandbox Code Playgroud)