Media Player called in state 0, error (-38,0) error - android

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

Related

Stream and download audio from URL

I am developing app that search for song and able play and download music/song.I used this url http://tinysong.com/Phdj , this is redirecting to music web page and there its playing song. i used below code to play song.
//play music
MediaPlayer mMediaPlayer = new MediaPlayer();
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try{
mMediaPlayer.setDataSource("http://tinysong.com/Phdj");
mMediaPlayer.prepareAsync();
}catch(IOException e){
e.printStackTrace();
}
catch (IllegalArgumentException e){
e.printStackTrace();
}catch (IllegalStateException e){
e.printStackTrace();
mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener()
{
#Override
public void onPrepared(MediaPlayer mp)
{
mp.start();
}
});
ERROR:
09-21 11:26:49.674: I/MediaPlayer(6735): setLPAflag() in
09-21 11:26:49.674: I/MediaPlayer(6735): mContext is null, can't getMirrorDisplayStatus!!!
09-21 11:26:49.674: I/MediaPlayer(6735): setLPAflag() out
09-21 11:26:58.693: E/MediaPlayer(6735): error (1, -2147483648)
09-21 11:26:58.693: E/MediaPlayer(6735): Error (1,-2147483648)
Is AndroidMedia Library play only .mp3 format? Can i play music from above Url?How can i do that?
You have not passed the context in setDataSource()
Try this
String path="http://tinysong.com/Phdj";
Uri myUri = Uri.parse(path);
MediaPlayer mp = new MediaPlayer();
try {
mp.setDataSource(this, myUri);
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
mp.setOnPreparedListener(new OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
mp.start();
// TODO Auto-generated method stub
}
});
mp.prepareAsync();
} 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();
}

android give an error in create mediaplayer?

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();

Android play sound - forceclose error

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.

RTSP streaming doesn't work

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

Known streaming mp3 link, Correct Android Version. What is wrong with streaming?

I'm using Android 2.3, so according to this post: Streaming Audio from A URL in Android using MediaPlayer? streaming should work. I'm using a proven mp3 stream from kexp.org.
05-19 13:29:17.141: INFO/StagefrightPlayer(68): setDataSource('http://kexp-mp3-1.cac.washington.edu:8000')
05-19 13:29:17.141: INFO/AwesomePlayer(68): prepare was cancelled before doing anything
try {
mp = new MediaPlayer();
mp.reset();
mp.setOnPreparedListener(new OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
mp.start();
}
});
mp.setDataSource("http://kexp-mp3-1.cac.washington.edu:8000");
mp.prepareAsync();
} 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();
} finally {
if(mp!=null) {
mp.release();
mp =null;
}
}
Try this:
MediaPlayer.setDataSource() and prepare() not working - android

Categories

Resources