Reputation: 1101
I am starting playback of an online audio stream in a service. This is the method which starts the playback:
void start1(String a){
try{
mp.setDataSource(a);//mp is a global MediaPlayer variable
mp.setOnPreparedListener(this);
mp.prepareAsync();
mp.start();
}catch(Exception e){
noerror=false;
}
}
The onPrepared()
function:
@Override
public void onPrepared(MediaPlayer mp1){
mp.start();
}
This code gives me the error
Start called in state 4: error(-38,0)
What is wrong with this code?
Upvotes: 3
Views: 5110
Reputation: 21
State 4 means Mediaplayer
is in preparing state
and we call other actions like
Mediaplayer.start()
Mediaplayer.stop()
Mediaplayer.pause()
or any other.
As per your code, it is Mediaplayer.start();
Once Onprepared() method is called you can do the further processing.
Just remove
mp.start()
after
mp.prepareAsync();
And you will be good to go!
Upvotes: 1
Reputation: 17850
Remove this line
mp.start();
from your start1
method since you're already starting playing in the onPrepared
method.
Upvotes: 5