android - Android:无法使用 videoview 播放视频
问题描述
请在下面找到xml
<VideoView
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
Java代码:
String url = "android.resource://com.example.androidtutorial/" + R.raw.instructions;
videoView.setVideoURI(Uri.parse(url));
videoView.start();
Logcat 中显示错误:
2019-10-20 10:51:16.708 5063-5063/? E/androidtutoria: Unknown bits set in runtime_flags: 0x8000
2019-10-20 10:51:22.825 5063-5080/com.example.androidtutorial E/MediaPlayerNative: error (1, -2147483648)
2019-10-20 10:51:23.178 5063-5063/com.example.androidtutorial E/MediaPlayer: Error (1,-2147483648)
我在互联网上看到了许多使用相同代码的示例,但就我而言,它不起作用。
解决方案
我建议您使用 WebView 而不是视频视图。
这会更好。
但是为了你的答案
1.检查你的连接
2.检查您的权限
3.检查您使用 Debug 构建的 Url
4.将start方法放入try catch
现在它在这一行似乎有问题:
videoView.setVideoURI(Uri.parse(url));
uri 表示您设备中的文件路径而不是 url,请检查并重试。
你可以在评论中更新我
编辑:使用此方法:
public Uri getRawUri(String filename) {
return Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE +
File.pathSeparator + File.separator + getPackageName() + "/raw/" +
filename);
}
下一个解决方案:使用Uri.fromFile
代替Uri.parse
和
使用这两种方法:
video.setVideoURI(URI);
video.setMediaController(new MediaController(this));
video.requestFocus();
video.start();
onCreate()
在你的方法中试试这个:
Uri URI = getRawUri(instructions);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(video)
video.setVideoURI(URI);
video.setMediaController(mediaController);
video.requestFocus();
video.start();
推荐阅读
- javascript - javascript中antlr4访问者中的自定义上下文变量
- c++11 - 试图 push_back 一个向量
进入私有向量 没有返回函数的同一个类 - php - Laravel Eloquent - 最受欢迎的查询
- javascript - 在 JQuery 中使用 switch 语句替换多个字符
- php - PHP没有来自HTML表单的响应
- git - 无版本目录树的重复 repo 导入
- mysql - 无法在嵌套游标存储过程中获得预期输出
- django - 在 Djnago 中配置 postgresql
- python - 如何将 python getter 方法转换为 elasticsearch 查询?
- reactjs - 从服务器获取数据后将数据传递给其他组件并使用该数据加载其他组件