开发者

Playng video file present in Local File System in Android

开发者 https://www.devze.com 2023-01-14 19:29 出处:网络
How to play video present in local file system (ex:in res/a.3gp) using VideoView . I need Sample code.

How to play video present in local file system (ex:in res/a.3gp) using VideoView . I need Sample code. I am trying to play as below:

import android.app.Activity;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;


public class videoSample extends Activity {  
    /** Called when the activity is first created. */ 
     String path="D:/mApp2/videoSample/res/drawable-hdpi/adf.mp4"; 
    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        VideoView videoView = (VideoView) findViewById(R.id.VideoView01);
        MediaController mediaController = new MediaController(this);
        mediaController.setMediaPlayer(videoView);
        videoView.setVideoPath(path);   
        videoView.setMediaController(mediaController);
        vid开发者_JAVA技巧eoView.requestFocus();
        videoView.start();
        mediaController.show();
    }
}

I am getting error as Video cant be played. Can any one help me in sorting out this issue? Thanks in Advance.


String path="D:/mApp2/videoSample/res/drawable-hdpi/adf.mp4";

There is no D: drive in Android. Android is not Windows.


i used this string and worked for me:

private String srcPath = "android.resource://com.myapp/raw/videofile";

then...

myVideoView.setVideoURI(Uri.parse(srcPath));

where com.myapp is the app main package

hope it helps!


Afaik it's not possible to play videos from the internal app storage, see Can a videoview play a video stored on internal storage?

I faced similar issue and already searched about it.

http://www.anddev.org/multimedia-problems-f28/videoview-cannot-play-video-from-internal-storage-t16636.html

http://groups.google.com/group/android-developers/browse_thread/thread/a01d415c8e48e0d3

Workaround is to copy the video to sdcard temporarily and play it from there.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号