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

发布于 2024-12-18 04:01:42 字数 514 浏览 6 评论 0 原文

我正在尝试使用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。 该代码不起作用。

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

im trying to play a video from the raw folder with phonegap.
I modified the original plugin a little bit.
this is the code:

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

The video is in the raw folder and is named test.mp4.
The code doesnt work.

I think that the url to the video isnt correct?
I would be very pleased of any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

奶气 2024-12-25 04:01:42

我和这个问题斗争了一段时间。我可以播放 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); 

I wrestled with this one for awhile. The only way I could play a video from an Android resource was to copy it first to the sdcard. Here's my code:

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); 
墨离汐 2024-12-25 04:01:42

我认为您无法将应用程序私有包中的视频播放到默认视频播放器,因为您的默认视频播放器无法识别此路径。

要使其播放,您必须复制此视频文件在 sdcard 中,然后给出该文件的 URI,在这种情况下它工作正常。

I think you can't play video from application's private package to default video player,Because your default video player can't recognize this path.

To make it play you have to copy this video file in sdcard and then give URI of that file, in this case it works fine.

甜味超标? 2024-12-25 04:01:42

我已成功播放直接从该资源加载到 res/raw 文件夹中的视频文件。

这是在

Android 1.5

API Level 3

中完成的文件大小低于 50M

我的代码片段如下

        Uri video= Uri.parse("android.resource://MYPACKAGENAME/" + R.raw.presence); 
    videoView.setMediaController(mediaController);
        videoView.setVideoURI(video);
        videoView.start();

我看到发生的主要问题是让应用程序识别原始文件夹中的 mp4 文件

我是 android 开发的新手,但这就是我的我希望它有帮助吗?

在第一行中,当我输入“R.raw”时,Eclipse 将其显示为错误,我输入了句点,并期望 Eclipse 向我显示资源的快速列表,但它不在那里。

我在另一篇文章中读到对项目进行清理,当我单击“项目 - 清理”时,资源列表将被刷新,资源被识别。

我认为需要的另一件事是文件名必须仅小写。
当它处于混合大小写时,它不会显示。

希望这有帮助。

I have successfully played a video file that I loaded into the res/raw folder directly from that resource.

This was done in

Android 1.5

API Level 3

The file size was below 50M

My code snippet is as follows

        Uri video= Uri.parse("android.resource://MYPACKAGENAME/" + R.raw.presence); 
    videoView.setMediaController(mediaController);
        videoView.setVideoURI(video);
        videoView.start();

The main issue I saw occurring was getting App to recognize the mp4 file in the raw folder

I am new to android development but this is what I did I hope it helps.

In the first line as I typed "R.raw" Eclipse showed it as an error I typed the period and expected Eclipse to show me a quick list of the resources but it was not there.

I read in another post to do a clean on the project and the resource list would be refreshed when I clicked PROJECT - CLEAN the resource was identified.

Another thing that I believe is required is that the file name MUST be lowercase only.
When it was in mixed case it would not show up.

Hope this helps.

2024-12-25 04:01:42

上面的代码:

Uri video= Uri.parse("android.resource://MYPACKAGENAME/" + R.raw.presence); 
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.start();

对我来说非常有用!

MYPACKAGENAME = 要工作的完整包名称。我在这里被困了一分钟。

This code from above:

Uri video= Uri.parse("android.resource://MYPACKAGENAME/" + R.raw.presence); 
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.start();

worked great for me!

MYPACKAGENAME = full package name to work. I got stuck here for minute.

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