【问题标题】:Android http live Streaming URL using mediaplayer使用媒体播放器的 Android http live Streaming URL
【发布时间】:2011-11-17 11:06:40
【问题描述】:

我正在尝试播放一个 url,但它没有播放,我使用的代码如下..logcat 显示 Mediaplayer 错误(1,-1002),启动状态为 0,错误(-38,0)为什么。 ..?我哪里出错了......你能帮我看看怎么玩............

       import java.io.IOException;

       import android.app.Activity;
       import android.media.AudioManager;
       import android.media.MediaPlayer;
         import android.os.Bundle;
      import android.view.View;
      import android.widget.ImageButton;
       import android.widget.TextView;

        public class BacaFatihahActivity extends Activity {



        final String songs_urIs= "http://stream.radiosai.net:8002/";
           // private TextView txt_song_title;
        private MediaPlayer mediaplayer;
        @Override
         public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  ImageButton btn_play = (ImageButton) findViewById(R.id.button_play);
  ImageButton btn_pause = (ImageButton) findViewById(R.id.button_pause);
  ImageButton btn_next = (ImageButton) findViewById(R.id.button_next);
  ImageButton btn_previous = (ImageButton) findViewById(R.id.button_Previous);
  //txt_song_title = (TextView) findViewById(R.id.txt_song_title);

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


  btn_play.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) {
        try {
            mediaplayer.setDataSource(songs_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();
        }
         mediaplayer.start();   
    }
       });


        }
       }

【问题讨论】:

  • 哪个 api 级别?你需要知道 android 在 3.0 (aka apilevel 11) 之前不支持“http live Streaming”

标签: android http-live-streaming android-mediaplayer


【解决方案1】:

代码正确但api级别错误~

不是每个api级别都支持这种方式播放媒体,http直播,可能你需要api级别10或更高

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多