当我尝试通过 Medialayer 播放流音乐时,我会收到此消息:
05-18 18:24:30.371 23988-23988/my.package.name D/MediaPlayer﹕ setDataSource IOException happend :
java.io.FileNotFoundException: No content provider: http://stream6.radiostyle.ru:8006/priboyfm
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1074)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:927)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:854)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1085)
at my.package.name.radio05.radio.PlayService.prepareRadioAt(PlayService.java:149)
at my.package.name.radio05.radio.PlayService.onStartCommand(PlayService.java:108)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3307)
at android.app.ActivityThread.access$2200(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1546)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5942)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
但是在onPreparedListener播放开始后的2-5分钟内。
对于测试我创建了一个只有MediaPlayer的新项目并再次测试 - 同样的问题,但在其他应用程序(在线广播,在线音乐)上所有工作完美,测试不同的应用程序。
P.S。早期所有工作都很好,我认为它是Android 5的错误,因为在Android 4. *工作得很好(10-20秒后开始播放)也在模拟器播放后开始onPreparedListener
新logcat:
05-18 19:31:57.461 22893-22893/? V/MediaPlayer-JNI﹕ native_setup
05-18 19:31:57.461 22893-22893/? V/MediaPlayer﹕ constructor
05-18 19:31:57.466 22893-22893/? V/MediaPlayer﹕ setListener
05-18 19:31:57.466 22893-22893/? V/MediaPlayer-JNI﹕ setAudioStreamType: 3
05-18 19:31:57.466 22893-22893/? V/MediaPlayer﹕ MediaPlayer::setAudioStreamType
05-18 19:31:57.481 22893-22893/? V/MediaPlayer﹕ setVideoSurfaceTexture
05-18 19:31:57.481 22893-22893/? V/MediaPlayer﹕ prepare
05-18 19:31:57.541 22893-22902/my.package.test I/System.out﹕ (HTTPLog)-Static: isSBSettingEnabled false
05-18 19:31:57.541 22893-22902/my.package.test I/System.out﹕ (HTTPLog)-Static: isShipBuild true
05-18 19:31:57.541 22893-22902/my.package.test I/System.out﹕ (HTTPLog)-Thread-101145-825770595: SmartBonding Enabling is false, SHIP_BUILD is true, log to file is false, DBG is false
05-18 19:31:57.541 22893-22902/my.package.test I/System.out﹕ (HTTPLog)-Static: isSBSettingEnabled false
05-18 19:31:58.491 22893-22902/my.package.test I/System.out﹕ KnoxVpnUidStorageknoxVpnSupported API value returned is false
05-18 19:31:59.046 22893-22902/my.package.test V/MediaHTTPConnection﹕ mTotalSize is -1
05-18 19:31:59.051 22893-22902/my.package.test D/MediaHTTPConnection﹕ setReadTimeOut = 30000ms
05-18 19:32:26.646 22893-22955/my.package.test V/MediaPlayer﹕ message received msg=200, ext1=973, ext2=0
05-18 19:32:26.646 22893-22955/my.package.test W/MediaPlayer﹕ info/warning (973, 0)
05-18 19:32:26.646 22893-22955/my.package.test V/MediaPlayer﹕ callback application
05-18 19:32:26.646 22893-22955/my.package.test V/MediaPlayer﹕ back from callback
05-18 19:32:26.646 22893-22955/my.package.test V/MediaPlayer﹕ message received msg=1, ext1=0, ext2=0
05-18 19:32:26.651 22893-22955/my.package.test V/MediaPlayer﹕ prepared
05-18 19:32:26.651 22893-22955/my.package.test V/MediaPlayer﹕ signal application thread
05-18 19:32:26.651 22893-22955/my.package.test V/MediaPlayer﹕ callback application
05-18 19:32:26.651 22893-22955/my.package.test V/MediaPlayer﹕ back from callback
05-18 19:32:26.651 22893-22893/my.package.test V/MediaPlayer﹕ prepare complete - status=0
05-18 19:32:26.651 22893-22893/my.package.test E/MediaPlayer﹕ Should have subtitle controller already set
05-18 19:32:26.651 22893-22893/my.package.test V/MediaPlayer-JNI﹕ start
05-18 19:32:26.651 22893-22893/my.package.test V/MediaPlayer﹕ start
05-18 19:32:26.656 22893-22893/my.package.test D/Activity﹕ performCreate Call secproduct feature valuefalse
05-18 19:32:26.656 22893-22893/my.package.test D/Activity﹕ performCreate Call debug elastic valuetrue
05-18 19:32:26.816 22893-22893/my.package.test V/ActivityThread﹕ updateVisibility : ActivityRecord{21cbc7ea token=android.os.BinderProxy@3c01408c {my.package.test/my.package.test.MainActivity}} show : true
05-18 19:32:26.766 22893-23646/my.package.test D/OpenGLRenderer﹕ Render dirty regions requested: true
05-18 19:32:26.806 22893-22893/my.package.test D/Atlas﹕ Validating map...
05-18 19:32:26.821 22893-22893/my.package.test E/MediaPlayer﹕ Should have subtitle controller already set
05-18 19:32:26.861 22893-23646/my.package.test I/OpenGLRenderer﹕ Initialized EGL, version 1.4
05-18 19:32:26.861 22893-23646/my.package.test W/OpenGLRenderer﹕ Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
05-18 19:32:26.876 22893-23646/my.package.test D/OpenGLRenderer﹕ Get maximum texture size. GL_MAX_TEXTURE_SIZE is 4096
05-18 19:32:26.876 22893-23646/my.package.test D/OpenGLRenderer﹕ Enabling debug mode 0
05-18 19:32:26.876 22893-23646/my.package.test E/﹕ [android_ws] Format: 5, Width: 1080, Height: 1920
05-18 19:32:26.881 22893-23646/my.package.test E/﹕ [android_ws] Format: 5, Width: 1080, Height: 1920
05-18 19:32:26.881 22893-23646/my.package.test E/﹕ [android_ws] Format: 5, Width: 1080, Height: 1920
05-18 19:32:26.881 22893-23646/my.package.test E/﹕ [android_ws] Format: 5, Width: 1080, Height: 1920
05-18 19:32:27.166 22893-22893/my.package.test I/Timeline﹕ Timeline: Activity_idle id: android.os.BinderProxy@3c01408c time:136675283
05-18 19:32:27.166 22893-22893/my.package.test I/Timeline﹕ Timeline: Activity_idle id: android.os.BinderProxy@3c01408c time:136675283
05-18 19:32:53.916 22893-22893/my.package.test D/ViewRootImpl﹕ ViewPostImeInputStage ACTION_DOWN
答案 0 :(得分:1)
你以错误的方式编写代码,你会播放你流式传输的音乐
String url = "http://stream6.radiostyle.ru:8006/priboyfm";
MediaPlayer mPlayer
Buuton buttonPlay = (Button) findViewById(R.id.play);
buttonPlay.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// editing
if(mPlayer == null){
mPlayer = new MediaPlayer();
}
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mPlayer.setDataSource(url);
} catch (IllegalArgumentException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (SecurityException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (IllegalStateException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
}
try {
mPlayer.prepare();
} catch (IllegalStateException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
} catch (IOException e) {
Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();
}
mPlayer.start();
}
});
//更新答案
private void play_music_onReady(){
// pass your url here
MediaPlayer mp = MediaPlayer.create(getApplicationContext(), Uri.parse(url));
mp.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.start();
}
});
}
确保您拥有iternet权限
<uses-permission android:name="android.permission.INTERNET"/>