Streaming Audio from A URL in Android using MediaPlayer?

后端 未结 7 1832
逝去的感伤
逝去的感伤 2020-11-28 00:29

I\'ve been trying to stream mp3\'s over http using Android\'s built in MediaPlayer class. The documentation would suggest to me that this should be as easy as :



        
7条回答
  •  北海茫月
    2020-11-28 01:06

    I guess that you are trying to play an .pls directly or something similar.

    try this out:

    1: the code

    mediaPlayer = MediaPlayer.create(this, Uri.parse("http://vprbbc.streamguys.net:80/vprbbc24.mp3"));
    mediaPlayer.start();
    

    2: the .pls file

    This URL is from BBC just as an example. It was an .pls file that on linux i downloaded with

    wget http://foo.bar/file.pls
    

    and then i opened with vim (use your favorite editor ;) and i've seen the real URLs inside this file. Unfortunately not all of the .pls are plain text like that.

    I've read that 1.6 would not support streaming mp3 over http, but, i've just tested the obove code with android 1.6 and 2.2 and didn't have any issue.

    good luck!

提交回复
热议问题