Android — streaming a shoutcast audio file

为君一笑 提交于 2019-12-24 09:45:52

问题


i am trying to stream an shoutcast audio file in my device android 2.2...i heard that this shoutcast will not work in android 2.2. so, i tried with android emulator 2.3 then also song not playing why could you tell me where i am going wrong...and the code is below...

  public class AudioDemo extends Activity {

  final String song_uris="http://stream.radiosai.net:8004/";
  private MediaPlayer mediaplayer;
  @Override
  public void onCreate(Bundle icicle) {
  super.onCreate(icicle);
  setContentView(R.layout.main);

  Button play = (Button) findViewById(R.id.play);
  Button pause = (Button) findViewById(R.id.pause);
  Button Previous = (Button) findViewById(R.id.Previous);
  Button Next = (Button) findViewById(R.id.Next);


  mediaplayer = new MediaPlayer();
  mediaplayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

  play.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {

    try {
        mediaplayer.setDataSource(song_uris);
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
      try {
        mediaplayer.prepare();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } // might take long! (for buffering, etc)
      mediaplayer.start();
}
   });
   }
   }

来源:https://stackoverflow.com/questions/8252513/android-streaming-a-shoutcast-audio-file

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