Android Audio m3u8 Streaming - HOW TO

拥有回忆 提交于 2020-01-13 05:12:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!