Reputation: 765
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.
Upvotes: 1
Views: 6017
Reputation: 6940
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:
NullPointerException
)....sometimes simpler is better
Upvotes: 2
Reputation: 765
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);
}
Upvotes: 2
Reputation: 411
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.
Upvotes: 0
Reputation: 4425
videoView.setVideoPath("http://www.ebookfrenzy.com/android_book/movie.mp4"); MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
videoView.start();
Upvotes: 0
Reputation: 10174
/external/video/media/24363
is not correct, please check. local path must be visit..e.g. /sdcard/video/media/..
Upvotes: 0