Playng video file present on Android local file system

How to play video in a local file system (for example: res / a.3gp) using VideoView. I need some 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);
        videoView.requestFocus();
        videoView.start();
        mediaController.show();
    }
}

I get an error because the video cannot be played. Can someone help me in solving this problem? Thanks at Advance.

+3
source share
3 answers

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

In Android, there is no D: drive. Android is not Windows.

+5
source

I used this line and worked for me:

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

then ...

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

where com.myapp is the main application package

hope this helps!

+2

Afaik cannot play videos from the internal storage of applications; see Can video video play videos stored in the internal storage?

I ran into a similar problem and was already looking for 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

The workaround is to temporarily copy the video to the SD card and play it there.

+1
source

Source: https://habr.com/ru/post/1763426/


All Articles