android MediaPlayer java.io.IOException: Prepare failed.: status=0x1 解决



我试的是网络音乐,本地音乐不存在该问题,一直报这个错( java.io.IOException: Prepare failed.: status=0x1),后来发现主要原因是你一直找到的网络资源有问题,后来我在百度音乐里面找了个音乐,然后查看源码找到它的链接,试了下ok了,首先我要说明你一定要规范,一定要注册音频策略,然后再设置mediaPlayer的音频类型


        mAudioPolicy = new DLSAudioPolicyManager(OnlineMp3Activity.this);
		mAudioPolicy.register(mPackageName, AudioManager.STREAM_IVOKA, mNotifier);
		mAudioPolicy.play(AudioManager.STREAM_MUSIC);
		
        mediaPlayer=new MediaPlayer();
			mediaPlayer.setDataSource(videoUrl);
    		mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
			mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
				
				@Override
				public boolean onError(MediaPlayer mp, int what, int extra) {
					mp.stop();
					mp.release();
					
//					mAudioPolicy.stop();
//					mAudioPolicy.unregister();
					Log.i(TAG,"Error on Listener,what:"+what+"extra:"+extra);
					return false;
				}
			});
			
			mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener(){

				@Override
				public void onCompletion(MediaPlayer arg0) {
					
//					mAudioPolicy.stop();
//					mAudioPolicy.unregister();
					
					arg0.stop();
					arg0.release();
					Log.i(TAG,"mediaPlayer Listener completed");
				}
				
			});
			
	   		mediaPlayer.prepare();
    		mediaPlayer.start();


strVideoURL="http://zhangmenshiting.baidu.com/data2/music/87894333/87894333.mp3?xcode=20bacaac2d7fe763ca7aaed2810f0415023c754d8afb3d4d";



找资源,就是在google浏览器上面查看源码

android MediaPlayer java.io.IOException: Prepare failed.: status=0x1 解决_第1张图片

android MediaPlayer java.io.IOException: Prepare failed.: status=0x1 解决_第2张图片

你可能感兴趣的:(android)