开发者

To play video files using MediaPlayer class in android

I want to play video files in my application which are part of my application. for that i create 'raw' folder in 'res' and write following code in my activity.

MediaPlayer mp = MediaPlayer.create(VideoPlayer.this,R.raw.jeevrangala);
mp.start();

now i am t开发者_Python百科esting it on emulator, but it does not displaying any thing. is any one have solution to play video files in raw folder. please let me know.


Initial i was trying to play video files from raw folder. but cant run it. so i use another way to do this

    VideoView video=(VideoView) findViewById(R.id.videoview);
    MediaController mediaController = new MediaController(this);
    mediaController.setAnchorView(video);
    video.setMediaController(mediaController);
    //Uri uri = Uri.parse("android.resource://play.vedio/"+R.raw.dobeernotdrugs);
    video.setKeepScreenOn(true);
    video.setVideoPath("android.resource://one.two/raw/"+resource);
    video.start();
    video.requestFocus();

resource is file name which you want to play and one.two is package name your path may as like "android.resource://package_name/raw/file_name"


You can use this code to run video on emulator.. for me it is working

 VideoView videoHolder = (VideoView) findViewById(R.id.video_view);
            Uri video = Uri.parse("android.resource://" + getPackageName() + "/"
                    + R.raw.samplevideo);
            videoHolder.setVideoURI(video);
            videoHolder.start();

And please turn on your graphics acceleration for the emulator..

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜