1

I am developing video player app. I want this app to be appear as option on selecting video from sdcard, album or any folder of the phone . When i select my video player to play video, it takes to app but video is not playing. I have given permission to read and write external storage in manifest.Below is my code :

 Intent in =getIntent();
 file_path = in.getData().getPath();
 System.out.println("file path from sdcard:"+file_path);
  videoView =(VideoView)findViewById(R.id.video);

   MediaController mediaController= new MediaController(this);
    mediaController.setAnchorView(videoView);        
     Uri uri=Uri.parse(file_path);        
     videoView.setVideoURI(uri);        
     videoView.requestFocus();
         videoView.start();

ERROR :

 10-19 10:39:40.917: I/System.out(20430): file path from sdcard:/external/video/media/24363
 10-19 10:39:40.987: E/MediaPlayer(20430): Uri is  <URL suppressed>
 10-19 10:39:40.997: E/MediaPlayer(20430): error (1, -2147483648)
 10-19 10:39:41.017: E/MediaPlayer(20430): Error (1,-2147483648)
 10-19 10:39:41.017: D/VideoView(20430): Error: 1,-2147483648

EDIT: testing phone : Android 4.1 with 32Gb inbuilt memory and does not have Sdcard.

Brinda K
  • 745
  • 3
  • 16
  • 34

5 Answers5

2

Answer for this is here

 public String getRealPathFromURI(Uri contentUri) {
    String[] proj = { MediaStore.Video.Media.DATA };
    Cursor cursor = managedQuery(contentUri, proj, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
}
Community
  • 1
  • 1
Brinda K
  • 745
  • 3
  • 16
  • 34
2

I had this same problem, went down many different paths to fix it, and what finally ended up working was the following code block:

/* inside onCreate */
VideoView videoView = (VideoView)findViewById(R.id.loginVideoBackground);
videoView.setVideoURI(Uri.parse("android.resource://" + this.getPackageName() + "/raw/lights"));
videoView.start();

I had previously tried:

  • Extending SurfaceView
  • using the answer given by @brinda above (which was resulting in a NullPointerException)
  • and various other permutations of StackOverflow answers

....sometimes simpler is better

sschrass
  • 7,014
  • 6
  • 43
  • 62
Bobby
  • 6,840
  • 1
  • 22
  • 25
0

/external/video/media/24363 is not correct, please check. local path must be visit..e.g. /sdcard/video/media/..

Crossle Song
  • 10,104
  • 2
  • 29
  • 38
0
videoView.setVideoPath("http://www.ebookfrenzy.com/android_book/movie.mp4");        MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
videoView.start();
QuokMoon
  • 4,387
  • 4
  • 26
  • 50
  • i am asking how to play video from sdcard, not from http. – Brinda K Oct 19 '13 at 06:21
  • The videoView.setVideoURI(vidFile); is depracated method needs to be replaced by the videoView.setVideoPath(path);setVideoPath("/mnt/sdcard/infinnitti.mp4"); using file – QuokMoon Oct 19 '13 at 06:39
  • @altaf I am using Sony Xperia with android 4.1.2 which is having 32Gb inbuilt memory and does not have sdcard.So how to get the file name from intent? – Brinda K Oct 21 '13 at 08:36
0

To be honest, I've experienced similar problems in the past and for each account, what I've ultimately found to be the best solution was to extend SurfaceView, directly. There is a surprisingly small amount of code to write and can easily (relatively speaking) be tailored efficiently to your requirements.

Brandon
  • 401
  • 3
  • 8
  • I am using Sony Xperia with android 4.1.2 which is having 32Gb inbuilt memory and does not have sdcard.So how to get the file name from intent? – Brinda K Oct 21 '13 at 08:02