简体   繁体   中英

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. 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.

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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