问题
As the title, how can I stream an m3u8 audio on Android without vitamio? (on Android 2.3+). I've seen that some app can stream my my link http://4metest1-view.4me.it/api/xpublisher/resources/weebopublisher/getContentDescriptor.m3u8?clientId=4metest1&contentId=b55f7d74-cd81-48ce-9390-d9ffd5c49281&channelType=STREAMHTTPIOS&v=4 like VLC or aqua Player, but i cannot setup mMediaPlayer to reproduce it.
回答1:
Use a VideoView to play your audio with relaxing music :)
myVideoView = (VideoView)this.findViewById(R.id.myVideoView);
MediaController mc = new MediaController(this);
myVideoView.setMediaController(mc);
urlStream = "http://4metest1-view.4me.it/api/xpublisher/resources/weebopublisher/getContentDescriptor.m3u8?clientId=4metest1&contentId=b55f7d74-cd81-48ce-9390-d9ffd5c49281&channelType=STREAMHTTPIOS&v=4";
runOnUiThread(new Runnable() {
@Override
public void run() {
myVideoView.setVideoURI(Uri.parse(urlStream));
}
});
回答2:
Your m3u8 is not a true HLS file. It is just a playlist pointer to a single MP3
http://4metest1-4me.weebo.it/ios/Dance_of_the_Yao_People_3_JIDMQ7.mp3
You can either use media player to stream from the source directly or parse the file m3u8 file in your code to pull out the idividual URL's
url url = new URL(" http://4metest1-view.4me.it/api/xpublisher/resources/weebopublisher/getContentDescriptor.m3u8?clientId=4metest1&contentId=b55f7d74-cd81-48ce-9390-d9ffd5c49281&channelType=STREAMHTTPIOS&v=4");
InputStream m3u8 = (InputStream) url.getContent();
BufferedReader br = new BufferedReader(new InputStreamReader(M3U8));
for(int i = 0; i < 2; ++i)
{
br.readLine();
}|
readLine(); //this parses the third line of the playlist
br.close();
url = new URL(baseURL.concat(target));
来源:https://stackoverflow.com/questions/20220208/android-audio-m3u8-streaming-how-to