4
My shorthand code is this:
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDataSource("http://stm43.srvstm.com:8474/;");
mediaPlayer.prepareAsync();
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
mp.start();
}
});
mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
public boolean onError(MediaPlayer mp, int what, int extra) {
mp.reset();
Log.i("informacao", "erro "+ what + " -- " + extra);
return false;
}
});
The logcat is returning me the following message:
? I/information: error 1 -- -2147483648
According to the Mediaplayer documentation the numbering error 1 is MEDIA_ERROR_UNKNOWN which is described as "Unspecified media player error." , the test that presented this error was done on an emulator with android 8.1 (Oreo), in versions 4.4.2 and 6.0 works normally, I would like to understand why it does not work in version 8.1 and what are the alternatives to make this stream work in the latest versions of android.
If the link is accessed this way http://stm43.srvstm.com:8474/Listen.pls in a browser, a file is downloaded and when opening the file . pls the stream works on the computer normally.
Information about the stream: (HE-AAC@ 64 kbps, 44.1 kHz)
I tested on android 8.1 and it works. The only thing that changed the code is to pass
mediaPlayer.prepareAsync();
for aftersetOnPreparedListener()
.– ramaral
What do you mean? I just tested again and the error message is the same, you used other resources? or only an Activity with this code?
– LSA
Only one Activity with this code
– ramaral
Ok, I still do not understand, but I will do new tests in other emulators and other versions, later update here the results.
– LSA
@ramaral I created a new project from scratch as you did and tested, worked normally. Then I found it strange since I was trying and looking for a solution for some time, after a few days trying to understand, I realized that the error was not in this code but in another part of the project, How can I proceed in this scenario? I edit the question stating the problem and how I solved, create an answer or answer here right here in the comments ?
– LSA
If the reason for the problem is related to Mediaplayer and is something that can happen to others, you must respond. However, there is no harm in putting an answer, even if the circumstances are different.
– ramaral