Error code 1,-4 in media player android
-
27-10-2019 - |
سؤال
I got error code with 1,-4 number in android media player
I use this code for playing music in my service
public void playNextSong(/* String manualUrl */) {
mState = State.Stopped;
relaxResources(true); // release everything except MediaPlayer
AudioFile file = playList.nextFile();
if (file == null) {
say("Tidak ada lagu di playlist");
return;
}
try {
// set the source of the media player a a content URI
createMediaPlayerIfNeeded();
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mPlayer.setDataSource(getApplicationContext(), file.getUri());
mState = State.Preparing;
// MUST call this!
setUpAsForeground(file.getTitle() + " (loading)");
// starts preparing the media player in the background. When it's
// done, it will call
// our OnPreparedListener (that is, the onPrepared() method on this
// class, since we set
// the listener to 'this').
//
// Until the media player is prepared, we *cannot* call start() on
// it!
mPlayer.prepareAsync();
} catch (IOException ex) {
Log.e("MusicService",
"IOException playing next song: " + ex.getMessage());
ex.printStackTrace();
}
}
And I use this in the shake listener of my code
mSensorListener
.setOnShakeListener(new ShakeEventListener.OnShakeListener() {
public void onShake() {
musicService.playNextSong();
updateInformation(musicService.playList.getCurrent());
}
});
Anyone can help to handle player not in invalid states exceptions
المحلول
Check this link. It has a description of error codes.
لا تنتمي إلى StackOverflow