简体   繁体   English

在Android中加载视频(mp4)文件

[英]Loading a video (mp4) file in android

     VideoView v = (VideoView) findViewById(R.id.VideoView01);
     Uri uri = Uri.parse("android.resource://" + getPackageName() + "vid.mp4");
     mc = new MediaController(this);
     v.setMediaController(mc);
     v.setVideoURI(uri);
     v.start();

An alertbox appears saying that the video cannot be played.Do you have a solution to this . 出现一个警告框,提示无法播放视频。您对此有解决方案吗?

thanks in advance 提前致谢

This is a linux filesystem permission issue. 这是linux文件系统权限问题。 The location of the file is solely owned by your application. 该文件的位置仅由您的应用程序拥有。 The MediaPlayer service ViewView relies on runs as a different "user" from a file system perspective. 从文件系统角度来看, MediaPlayer服务ViewView依赖于以不同的“用户”身份运行。

The way I've solved this in the past is to create a custom VideoView extending SurfaceView that takes a FileDiscriptor as it's data source . 我过去解决此问题的方法是创建一个自定义VideoView扩展SurfaceView ,该方法使用FileDiscriptor作为数据源

This side steps the issue by providing a connection to the data the is already open as far as the file system is concerned. 通过提供与已打开的数据的连接(就文件系统而言),这一方面解决了问题。

If your feeling frisky you could pull down the VideoView code from google and add a new setVideoFileDiscriptor method. 如果您觉得不愉快,可以从Google下拉VideoView代码 ,然后添加一个新的setVideoFileDiscriptor方法。

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

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