Android 意图让视频播放器在 res/raw 文件中播放视频 [英] Android intent to video player to play video in res/raw file

查看:35
本文介绍了Android 意图让视频播放器在 res/raw 文件中播放视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Android 新手,在使用堆栈 android 视频播放器播放视频时遇到问题.我到处搜索答案,但没有找到.

I am new in Android and I have problem with playing video using stack android video player. I search answer everywhere but don't find it.

我的代码是:

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

它不起作用并且应用程序崩溃.怎么了.这取决于智能手机型号吗?我的智能手机型号是 THL 5000,Android 4.4.2.

It doesn't work and application crash. What is wrong. Is it depend to smartphone model? My smartphone model is THL 5000, Android 4.4.2.

谢谢!

推荐答案

很遗憾,其他应用(Android 意图)无法访问您的资源.

Unfortunately other apps (Android intents) can't access your resources.

  1. 您需要创建一个 ContentProvider,或者将数据存储在任何人都可以访问的位置(SD 卡或本地存储的公共文件夹中)1.
  2. 另一种解决方案可能是使用 Android MediaPlayer.MediaPlayer 可以从 URL 或资源运行音频和视频文件,其中源文件位于您的设备上.要播放视频文件,您需要将其与 SuffaceView 结合使用.这里是一个完整的例子.
  3. 一种快速且最简单的解决方案是在 WebView 中播放视频.该视频位于资产文件夹中,只需打开file:///android_asset/video.mp4"网址即可.
  1. You'll need to create a ContentProvider, or store the data in a place accessible to anyone (either SD card, or in a public folder in your local storage) 1.
  2. An other solution could be, to use the Android MediaPlayer. The MediaPlayer can run audio and video files, where the source file is located on your device, from a URL or from your resources. To play a video file you need to combine it with SuffaceView. Here is a full example.
  3. A quick and the easiest solution would be to play the video in a WebView. The video is located in the assets folder and by simply open the "file:///android_asset/video.mp4" URL works for me.

这篇关于Android 意图让视频播放器在 res/raw 文件中播放视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆