我在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]);
我该怎么办?
答案 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);