爲什麼我得到這個錯誤?請幫忙!android studio:無法創建媒體播放器
9月10日至十七日:34:13.217 17220-20262/com.example.e19adm.onlineradioplayer E/MediaPlayer的:無法創建媒體播放器
公共類MainActivity擴展AppCompatActivity {
Button b_play;
MediaPlayer mediaPlayer;
String stream="https://www.internet-radio.com/station/danceradioukchatbox/";
boolean prepared = false;
boolean started = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b_play =(Button) findViewById(R.id.b_play);
b_play.setEnabled(false);
b_play.setText("LOADING");
mediaPlayer=new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
new PlayerTask().execute(stream);
b_play.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (started){
started = false;
mediaPlayer.pause();
b_play.setText("PLAY");
} else {
started = true;
mediaPlayer.start();
b_play.setText("PAUSE");
}
}
});
}
class PlayerTask extends AsyncTask<String, Void, Boolean>{
@Override
protected Boolean doInBackground(String... strings) {
try {
mediaPlayer.setDataSource(strings[0]);
mediaPlayer.prepare();
prepared = true;
} catch (IOException e) {
e.printStackTrace();
}
return prepared;
}
@Override
protected void onPostExecute(Boolean aBoolean) {
super.onPostExecute(aBoolean);
b_play.setEnabled(true);
b_play.setText("PLAY");
}
}
@Override
protected void onPause() {
super.onPause();
if (started){
mediaPlayer.pause();
}
}
@Override
protected void onResume() {
super.onResume();
if (started){
mediaPlayer.start();
}
}
@Override
protected void onDestroy() {
super.onDestroy();
if (prepared){
mediaPlayer.release();
}
} }
> 0-17 10:17:35.383 32413-32413/com.example.e19adm.onlineradioplayer
> E/MediaPlayer: pause called in state 0
> 10-17 10:17:135.413 32413-19389/com.example.e19adm.onlineradioplayer I/MediaPlayer: This
> is not a sprint project
> 10-17 10:17:35.423 32413-19389/com.example.e19adm.onlineradioplayer E/MediaPlayer: Unable
> to create media player
> 10-17 10:17:35.423 32413-19389/com.example.e19adm.onlineradioplayer W/System.err:
> java.io.IOException: setDataSource failed.: status=0x80000000
> 10-17 10:17:35.423 32413-19389/com.example.e19adm.onlineradioplayer W/System.err: at
> android.media.MediaPlayer._setDataSource(Native Method)
> 10-17 10:17:35.423 32413-19389/com.example.e19adm.onlineradioplayer W/System.err: at
> android.media.MediaPlayer.setDataSource(MediaPlayer.java:1248)
> 10-17 10:17:35.433 32413-19389/com.example.e19adm.onlineradioplayer W/System.err: at
> android.media.MediaPlayer.setDataSource(MediaPlayer.java:1180)
> 10-17 10:17:35.433 32413-19389/com.example.e19adm.onlineradioplayer W/System.err: at
> com.example.e19adm.onlineradioplayer.MainActivity$PlayerTask$override.doInBackground(MainActivity.java:64)
> 10-17 10:17:35.433 32413-19389/com.example.e19adm.onlineradioplayer W/System.err: at
> com.example.e19adm.onlineradioplayer.MainActivity$PlayerTask$override.access$dispatch(MainActivity.java)
> 10-17 10:17:35.433 32413-19389/com.example.e19adm.onlineradioplayer W/System.err: at
> com.example.e19adm.onlineradioplayer.MainActivity$PlayerTask.doInBackground(MainActivity.java:0)
> 10-17 10:17:35.433 32413-19389/com.example.e19adm.onlineradioplayer W/System.err: at
> com.example.e19adm.onlineradioplayer.MainActivity$PlayerTask.doInBackground(MainActivity.java:57)
> 10-17 10:17:35.433 32413-19389/com.example.e19adm.onlineradioplayer W/System.err: at
> android.os.AsyncTask$2.call(AsyncTask.java:288)
> 10-17 10:17:35.433 32413-19389/com.example.e19adm.onlineradioplayer W/System.err: at
> java.util.concurrent.FutureTask.run(FutureTask.java:237)
> 10-17 10:17:35.433 32413-19389/com.example.e19adm.onlineradioplayer W/System.err: at
> android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
> 10-17 10:17:35.433 32413-19389/com.example.e19adm.onlineradioplayer W/System.err: at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
> 10-17 10:17:35.433 32413-19389/com.example.e19adm.onlineradioplayer W/System.err: at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
> 10-17 10:17:35.433 32413-19389/com.example.e19adm.onlineradioplayer W/System.err: at
> java.lang.Thread.run(Thread.java:864)
> 10-17 10:17:38.643 32413-32413/com.example.e19adm.onlineradioplayer D/[MediaPluginDLNA]:
> [getIsRegionSupported] sRegionCode: 6
> 10-17 10:17:38.643 32413-32413/com.example.e19adm.onlineradioplayer D/[MediaPluginDLNA]:
> not in Mirror mode
> 10-17 10:17:38.643 32413-32413/com.example.e19adm.onlineradioplayer D/MediaPlayer:
> doStart() in
> 10-17 10:17:38.643 32413-32413/com.example.e19adm.onlineradioplayer D/MediaPlayer:
> Htc_getIntParameter get error: -38
> 10-17 10:17:38.643 32413-32413/com.example.e19adm.onlineradioplayer E/MediaPlayer: start
> called in state 1
> 10-17 10:17:38.643 32413-32413/com.example.e19adm.onlineradioplayer E/MediaPlayer: error
> (-38, 0)
> 10-17 10:17:38.643 32413-32413/com.example.e19adm.onlineradioplayer D/MediaPlayer:
> Mediaplayer receives message, message type: 100
> 10-17 10:17:38.643 32413-32413/com.example.e19adm.onlineradioplayer E/MediaPlayer: Error
> (-38,0)
> 10-17 10:17:40.133 32413-32413/com.example.e19adm.onlineradioplayer E/MediaPlayer: pause
> called in state 0
可能重複的[無法創建媒體播放器(使用url)](http://stackoverflow.com/questions/27832921/unable-to-create-media-player-using-url) – Raghavendra
你真的應該添加更多的logcat而不是隻有最上面一行 –
它似乎是你的鏈接是錯誤的,不包括一個音頻文件,如:https://..../fileName.mp3 – Saeid