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();
Related
I'm trying to play live stream mp3 audio by media player.
The problem is that when I am using URL, it blocks UI thread for sometime then it works fine. But I need that it plays the song with the buffering as well.
Thanks in Advance.Please help.
try {
audioPlayer = new MediaPlayer();
audioPlayer.setOnBufferingUpdateListener(this);
audioPlayer.setOnCompletionListener(this);
audioPlayer.setAudioStreamType(useFrontSpeaker ? AudioManager.STREAM_VOICE_CALL : AudioManager.STREAM_MUSIC);
try {
audioPlayer.reset();
audioPlayer.setDataSource(mSongDetail.getPath());
audioPlayer.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();
}
audioDuration = audioPlayer.getDuration();
audioPlayer.start();
startProgressTimer();
} catch (Exception e) {
if (audioPlayer != null) {
audioPlayer.reset();
audioPlayer.release();
audioPlayer = null;
isPaused = false;
MusicPreferance.playingSongDetail = null;
}
return false;
}
Try to use audioPlayer.prepareAsync() + asyncHandler for it, or use a separate Thread.
error :
Couldn't open file on client side, trying server side
Unable to to create media player
protected void onListItemClick(ListView l, View v, int position, long id) {
//get selected items
String selectedValue = (String) getListAdapter().getItem(position);
try {
MediaPlayer objMediaPlayer = new MediaPlayer();
objMediaPlayer = new MediaPlayer();
objMediaPlayer.setDataSource("http://192.168.1.3:3000/songs/WakaWaka.mp3");
objMediaPlayer.prepare();
objMediaPlayer.start();
} 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();
}
}
Check the Android Media Player State Diagram.
You have to call reset() e prepare() before calling start().
Try this:
private MediaPlayer objMediaPlayer = new MediaPlayer();
objMediaPlayer = new MediaPlayer();
try {
objMediaPlayer.setDataSource(path);
objMediaPlayer.prepare();
objMediaPlayer.start();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
This may help some people.. in order to stream a video from online, you must
add to 'AndroidManifest.xml'
<uses-permission android:name="android.permission.INTERNET" />
i went thru your problem. But couldn't get much of it. One thing for sure is, the url what you have specified here doesn't exist. So I made use of my own and did a sample. Check it out,
mediaPlayer mp=new MediaPlayer();
try {
mp.setDataSource("http://182.71.230.252/developers/blind_willie.mp3");
mp.prepare();
} 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();
}
mp.start();
I am trying to play audio like so, but it doesnt play, any ideas why? Whne i check if audio is playing it says false.
Uri myUri = Uri.parse("android.resource://com.Apps.Notifications/raw/dreamy");
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mediaPlayer.setDataSource(appContext, myUri);
} 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 {
mediaPlayer.prepare();
} catch (IllegalStateException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
mediaPlayer.start();
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.