I've created an app which will play from on RTSP:
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try
{
mediaPlayer.setDataSource(
"rtsp://184.72.239.149/vod/mp4:BigBuckBunny_175k.mov");
mediaPlayer.prepare();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
Toast.makeText(MyYouTubeActivity.this,
"Eror Play", Toast.LENGTH_SHORT).show();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mediaPlayer.start();
But it's not working, in Logcat I see this:
09-12 12:57:20.899: ERROR/PlayerDriver(95): Command PLAYER_PREPARE completed with an error or info PVMFFailure
First inset permission ::
android.permission.WRITE_EXTERNAL_STORAGE
android.permission.INTERNET
code ::
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.setDataSource("url");
player.prepare();
player.start();
and also refer :: This
Related
I have a problem with the MediaPlayer. Just when I set the datasource, I get the error:
02-22 21:26:10.050: E/MediaPlayer-JNI(7332): setDataSource: outside path in JNI is �x#
My device is a Samsum Galaxy Advance and my code:
try {
mediaPlayer.reset();
mediaPlayer.setDataSource(audioFile);
mediaPlayer.prepare();
mediaController.show();
mediaPlayer.start();
} catch (IllegalArgumentException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SecurityException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IllegalStateException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Try to set the data source path like this and use mediacontroller in this way:
String audioFile= Environment.getExternalStorageDirectory().getAbsolutePath();
audioFile+="/NaturaLocal/muralla_torreVieja_es.mp3";
MediaPlayer mp = new MediaPlayer();
MediaController mc= new MediaController(mp);
mc.setDataSource(audiofile);
mc.prepare();
mc.start();
Android 2.3 Mediaplayer can't play none of those audiostreams resulting in W/System.err(19610): java.io.IOException: Prepare failed.: status=0xFFFFFFF6. However, the same stream works fine on Android 4.0.
Is there anything I can provide the app with to make it work on Android 2.3 platform ?
Thanks.
Some code that I use:
mPlayer = new MediaPlayer();
mPlayer.setOnErrorListener(mOnErrorListener);
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mPlayer.setOnPreparedListener(mOnPreparedListener);
mPlayer.setOnBufferingUpdateListener(mOnBufferingUpdateListener);
try {
mPlayer.setDataSource(
this,
Uri.parse("http://radio02-cn03.akadostream.ru:8114/detifm192.mp3"));
mPlayer.prepare();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
UPD
I'm able to play "http://radio02-cn03.akadostream.ru:8114/detifm192.mp3" with MoboPlayer - any suggestions how they do it ? It plays after message "trying soft decoding mode"
Check there encoding. It seems that hardware decoding is failing.
i'm trying to use this code which i called from a button but it doesn't work and when i see the LogCat window i found Media Player called in state 0, error (-38,0)
public void audioPlayer(String path, String fileName){
//set up MediaPlayer
MediaPlayer mp = new MediaPlayer();
try {
mp.setDataSource(HeyActivity.this, Uri.parse(path+"/"+fileName));
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
mp.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
System.out.print("hey");
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mp.start();
}
Try setting OnPreparedListener and call the start method within it. Like this:
MediaPlayer mp = new MediaPlayer();
mp.setOnPreparedListener( new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
mp.start();
}
};
);
I finally solved the problem by running on an emulator that supported audio!!
Can't believe it was that simple!
Window > AVD Manager > Edit your AVD (I created a new one to be on the safe side cause I was running from snapshot) > Hardware > New > Audio Playback Support
I am using below code to play wav sound on touch of imageview
MediaPlayer mp = MediaPlayer.create(this, R.raw.ok);
mp.start();
while (mp.isPlaying()) {
// donothing
};
mp.release();
this gives me Force Close error, am i missing anything? or do i need to provide the permission in manifest file?..Please help.
Thanks
after created media player you have to call prepare() before start. Try this code
MediaPlayer mp = MediaPlayer.create(this, R.raw.ok);
mp.prepare();
mp.start();
Try with this and see.
public void audioPlayer(String path, String fileName){
//set up MediaPlayer
MediaPlayer mp = new MediaPlayer();
try {
mp.setDataSource(path+"/"+fileName);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
mp.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mp.start();
}
Change this method according to your code. Also if there is any error, you should post the error log so that others could identify the exact issue.
I use the following code to play audio from sdcard. But it doesn't play, even doesn't throw error. My file is in the following path /sdcard/media/blueeye.mp3. Any suggestions.
public void audioPlayer(){
//set up MediaPlayer
MediaPlayer mp = new MediaPlayer();
try {
mp.setDataSource(mp.setDataSource(getExternalFilesDir() + "/media/blueeye.mp3"); );
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
mp.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mp.start();
}
I think it should be /mnt/sdcard/media/blueeye.mp3 and please use getExternalFilesDir():
mp.setDataSource(getExternalFilesDir() + "/media/blueeye.mp3");
Also, If you'd set your own onErrorListener, you will be able to see easily what the problem is.