gpt4 book ai didi

android - 通过 phonegap videoplayer-plugin 从 res/raw 文件夹播放 mp4 视频

转载 作者:行者123 更新时间:2023-11-30 04:27:17 25 4
gpt4 key购买 nike

我正在尝试使用 phonegap 播放原始文件夹中的视频。我稍微修改了原始插件。这是代码:

       Uri uri = Uri.parse( "android.resource://" + getPackageName() + "/raw/"+R.raw.test);
// Uri uri = Uri.parse("http://www.test.sociato.de/test.mp4");

Intent intent = null;
// Display video player
intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "video/*");

this.ctx.startActivity(intent);

视频在raw文件夹中,命名为test.mp4。该代码不起作用。

我认为视频的网址不正确?如果有任何帮助,我将非常高兴。

最佳答案

我和这个纠缠了一段时间。我可以从 Android 资源播放视频的唯一方法是先将其复制到 SD 卡。这是我的代码:

File sdCard = Environment.getExternalStorageDirectory(); 

File dir = new File (sdCard.getAbsolutePath() + "/myfolder");
if(dir.isDirectory() != true) {
dir.mkdirs();

InputStream ins = getResources().openRawResource(R.raw.myvid);
int size = ins.available();
// Read the entire resource into a local byte buffer.
byte[] buffer = new byte[size];
ins.read(buffer);
ins.close();
FileOutputStream fos = new FileOutputStream(new File(dir, "myvid.m4v"));
fos.write(buffer);
fos.close();
}

File myvid = new File(dir, "myvid.m4v");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(myvid), "video/*");
this.startActivity(intent);

关于android - 通过 phonegap videoplayer-plugin 从 res/raw 文件夹播放 mp4 视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8268115/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com