Reputation: 229
I want to play .mpg file from MediaPlayer in android. But I am not able to play. This is my code.
File file = new File("abc.mpg");
MediaPlayer mp = MediaPlayer.create(MainActivity.this, Uri.fromFile(file.getAbsoluteFile()));
mp.seekTo(0);
mp.start();
I get null pointer error on mp.seekTo(0)
function.
Upvotes: 1
Views: 1671
Reputation: 365
I don't think android supports mpg format. You can always build a decoder yourself or look at some libs for it. See if exo player has formats you need. Also checkout Vitamio SDK
Upvotes: 1
Reputation: 364
mpeg can be compressing the video over a range of different formats/algorithms/codecs and some are supported some are not. 3gp is just one and it is supported (although a very poor format).
Try encoding a video yourself that you'll see all different options. Usually mp4 on H264 works flawlessly on mobiles.
Upvotes: 1
Reputation: 337
Are you sure that you have the correct path specified. Try debugging it by making an if statement:
File file = new File("abc.mpg");
MediaPlayer mp = MediaPlayer.create(MainActivity.this, Uri.fromFile(file.getAbsoluteFile()));
if(file != null && mp != null) {
mp.seekTo(0);
mp.start();
}
Let me know what happens, if the problem goes away it means either mp or file are equal to null.
Upvotes: 1