RoboAlex
RoboAlex

Reputation: 5015

Add and Access a video file in android project

I just wanted to run a predefined video file when a button is clicked. I have added this video file into res/raw folder in myVideApp project. Now I need to pass this path to videoView.setVideoPath() in order to play the video.

How can I access the stored video file's actual path in android. Note: I don't want to open the file. just want the actual location of the file to pass to video view.

I tried "path = this.getResources().getString(R.raw.bbc);" but its not working since it gives the path relative to the current project. but videoview needs absolute path.

Thank you, Regards, Robo.

Upvotes: 1

Views: 1794

Answers (2)

lincolnerson
lincolnerson

Reputation: 168

  • Following are steps to access video file and to play video
    1. Get Video Control
    2. create media controller
    3. Get Video path from local resorce
    4. Set media controller to video
    5. set path of video in video control
    6. Set Focus
    7. Start Video

.

VideoView videoView = (VideoView)findViewById(R.id.videoViewGuide);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
Uri uri = Uri.parse("android.resource:// " + getPackageName() + "/" +         R.raw.Guide_Video_01);
videoView.setMediaController(mediaController);
videoView.setVideoURI(uri);
videoView.requestFocus();
videoView.start();

Upvotes: 0

Vipul
Vipul

Reputation: 28103

Following Snippet will help you.

            getWindow().setFormat(PixelFormat.TRANSLUCENT);
            videoView = new VideoView(this);
            videoView.setMediaController(new MediaController(this));
            videoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() +"/" + R.raw.bbc);  //Don't put extension
            videoView.requestFocus();
            setContentView(videoView);
            videoView.start();

Upvotes: 1

Related Questions