3

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);
        videoView.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.

DeRagan
  • 22,827
  • 6
  • 41
  • 50
Android_programmer_camera
  • 13,197
  • 21
  • 67
  • 81

3 Answers3

5

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

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

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
2

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!

angarrido
  • 129
  • 2
  • 3
1

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.

Community
  • 1
  • 1
Mathias Conradt
  • 28,420
  • 21
  • 138
  • 192