'Play m3u8 audio file using android media player
I am developing an android application for android OS > 4.0 (including and post OS). I have a sample m3u8 file as follows :
#EXTM3U
#EXT-X-TARGETDURATION:56
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:28, no desc
ulr/audio/file.mp3
#EXTINF:28, no desc
ulr/audio/file.mp3
#EXT-X-ENDLIST
and I am trying to play that file, using the following code
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setOnErrorListener(this);
mMediaPlayer.setOnPreparedListener(this);
mMediaPlayer.setOnCompletionListener(this);
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try
{
mMediaPlayer.setDataSource(uri);
} catch (IllegalArgumentException e)
{
e.printStackTrace();
} catch (SecurityException e)
{
e.printStackTrace();
} catch (IllegalStateException e)
{
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
}
mMediaPlayer.prepareAsync();
and my onPrepared() method is as follows :
public void onPrepared(MediaPlayer player)
{
player.start();
}
But the code first comes to onPrepared() and then immediately goes to onError(), with the what=1 and the extra=-1010.
I know this question has been asked various times (here, here and here for instance) and I also know about Vitamio, but i want to find out what is wrong with my implementation. Is there something wrong with the m3u8 file that I created? I went through its documentation and everything seems correct.
Would be really glad if someone could throw some light in this matter.
Solution 1:[1]
Error code -1010 matches up with MEDIA_ERROR_UNSUPPORTED which would imply that the device does not have the hardware or software codecs it needs to decode the MP3 files in your playlist.
Vitamio would work in this situation because it adds software decoding for the media. This is slower than hardware decoding and uses more battery. It can also increase your app size significantly.
This seems odd, though, since MP3 has been a supported media format for decoding in Android for a very long time.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Buns of Aluminum |
