Android: setDataSource IOException happend: java.io.FileNotFoundException: No content provider: http://

标签 android android-mediaplayer

当我尝试通过 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 的新项目并再次测试 - 同样的问题,但在其他应用程序(在线广播、在线音乐)上都运行完美,测试了不同的应用程序。

附注早期所有工作都很好,我认为这是 Android 5 的错误,因为在 Android 4.* 上工作很好(播放在 10-20 秒后开始)也在模拟器上播放在 onPreparedListener 之后立即开始

新的日志:

    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

最佳答案

你以错误的方式编写代码,你确实播放你流式传输的音乐

    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"/>

关于Android: setDataSource IOException happend: java.io.FileNotFoundException: No content provider: http://,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30306192/

相关文章:

android - NavGraphBuilder 中的可组合项重复 3 次或更多次

android - 使用DataBinding库设置背景色资源或为null

java - 在 Android 中隐藏 keystore 密码的最佳方法是什么?

android - 使用 ExoPlayer 再现加密视频

android - 如何增加媒体播放器的音量

java - Java Android 应用 MediaPlayer 中的 NullPointerException

android - MediaPlayer滞后于手机锁

android - 播放结束时做点事

android - Kotlin 协程单元测试错误 : Exception in thread "main @coroutine#1 @coroutine#2" java. lang.NullPointerException

Android 应用程序中的 java.lang.NullPointerException