android live radio player setDataSource

时间:2017-03-15 16:55:01

标签: java android

我在youtube上关注教程,但我遇到了https://www.youtube.com/watch?v=pPpVZ8YZXHk&t=62s

输入

后的教程中的

      package com.example.oneilbogle.radiov1;

  import android.media.AudioManager;
 import android.media.MediaPlayer;
 import android.os.AsyncTask;
 import android.support.v7.app.AppCompatActivity;
 import android.os.Bundle;
 import android.view.View;
 import android.widget.Button;

 public class MainActivity extends AppCompatActivity {

Button b_play;

MediaPlayer mediaPlayer;

boolean prepared = false;
boolean started = false;

String stream = "http://142.4.217.133:8647/stream";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    b_play = (Button) findViewById(R.id.b_play);

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

    new PlayerTask().execute(stream);


b_play.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {

    }
});
}
class PlayerTask extends AsyncTask<String, Void, Boolean>{
    @Override
    protected Boolean doInBackground(String... params) {

        mediaPlayer.setDataSource(strings[0]);

        return prepared;
    }
  }
}

mediaPlayer.setDataSource(串[0]);

作者使用了try / catch选项,但我得到了另一个选项option1

enter image description here

我该怎么办?

2 个答案:

答案 0 :(得分:0)

你正在弄乱参数名称。 尝试使用:

protected Boolean doInBackground(String... params) {
        mediaPlayer.setDataSource(params[0]);
        return prepared;
    }

    protected Boolean doInBackground(String... strings) {
        mediaPlayer.setDataSource(strings[0]);
        return prepared;
    }

答案 1 :(得分:0)

所以我所做的就是把它改成了流

   mediaPlayer.setDataSource(stream);