简体   繁体   English

Android在原始文件夹中播放视频(从Intent启动画廊)

[英]Android play video in raw folder (launching gallery from intent)

So I know there are a lot of questions on this, but all seem to have the same answer and it's not what I'm looking for. 因此,我知道对此有很多疑问,但是似乎所有人都有相同的答案,这不是我想要的。

I have a video in the raw folder in my project, and I can get it to play in my app with VideoView . 我的项目的raw文件夹中有一个视频,我可以使用VideoView在应用程序中播放它。 However, I would like to take advantage of the gallery video player that all phones come with so the user can pause or scroll through the video. 但是,我想利用所有电话随附的图库视频播放器,以便用户可以暂停或滚动视频。

When I try to open my video with an ACTION_VIEW intent, it appears that there are no apps that can handle the intent. 当我尝试使用ACTION_VIEW意向打开视频时,似乎没有能够处理该意向的应用程序。 I have the same video in a folder in my phone, and the gallery player can play it fine. 手机的文件夹中有相同的视频,图库播放器可以正常播放。 I also downloaded VLC but still no apps show up in the list. 我还下载了VLC,但列表中仍未显示任何应用程序。 Is it just not possible, or am I missing something? 只是不可能,还是我错过了什么?

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("android.resource://" + ActivityMain.PACKAGE_NAME + "/" + R.raw.test));
intent.setDataAndType(Uri.parse("android.resource://" + ActivityMain.PACKAGE_NAME + "/" + R.raw.test), "video/*");
startActivity(Intent.createChooser(intent, "Complete action using"));

Very few apps support the android.resource scheme. 很少有应用程序支持android.resource方案。 Copy the video to a file and play that, or embed your own video player. 将视频复制到文件并播放,或嵌入自己的视频播放器。

I think it should help you,use video/mp4 ... 我认为它应该可以帮助您,使用video/mp4 ...

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM