HTTPS网址的Android Media Player设置数据源失败

时间:2016-07-22 17:22:15

标签: android android-mediaplayer android-audiomanager

我正在研究媒体播放器应用程序,当它说出Https mp3链接的IOException时遇到了这个问题,我写的媒体播放器在除4.4.2之外的所有平台上都运行得很好。在Kitkat上,每当我设置数据源时,它都会给我设置数据源IO异常。

V/MediaPlayer-JNI: native_setup
V/MediaPlayer: constructor
V/MediaPlayer: setListener
I/MediaPlayer: path is null
D/MediaPlayer: setDataSource IOException happend : 
    java.io.FileNotFoundException: No content provider: https://s3.amazonaws.com/acm-audio-samples/Audio_Player/DEB-108L/DEB-108L%20THe%20Days%20of%20Noah%20and%20Lot.mp3
        at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1053)
        at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:907)
        at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:834)
        at android.media.MediaPlayer.setDataSource(MediaPlayer.java:979)
        at android.media.MediaPlayer.setDataSource(MediaPlayer.java:933)
        at com.interactive3amd.acm.audioplayer.MediaPlayerService.constructPlayer(MediaPlayerService.java:110)
        at com.interactive3amd.acm.audioplayer.MediaPlayerService.play(MediaPlayerService.java:232)
        at com.interactive3amd.acm.audioplayer.PlayerIncomingHandler.handleMessage(PlayerIncomingHandler.java:32)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:146)
        at android.app.ActivityThread.main(ActivityThread.java:5602)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
        at dalvik.system.NativeStart.main(Native Method)
D/MediaPlayer: Couldn't open file on client side, trying server side
V/MediaPlayer: message received msg=8, ext1=0, ext2=0
V/MediaPlayer: notify(8, 0, 0) callback on disconnected mediaplayer
V/MediaPlayer-JNI: setAudioStreamType: 3
V/MediaPlayer: MediaPlayer::setAudioStreamType
V/MediaPlayer: setVideoSurfaceTexture
V/MediaPlayer: prepareAsync
D/ProgressBar: updateDrawableBounds: left = 0
D/ProgressBar: updateDrawableBounds: top = 0
D/ProgressBar: updateDrawableBounds: right = 64
D/ProgressBar: updateDrawableBounds: bottom = 64
V/MediaPlayer: message received msg=100, ext1=1, ext2=-1004
E/MediaPlayer: error (1, -1004)
V/MediaPlayer: callback application
V/MediaPlayer: back from callback
E/MediaPlayer: Error (1,-1004)
V/MediaPlayer-JNI: stop
V/MediaPlayer: stop
E/MediaPlayer: stop called in state 0
V/MediaPlayer: message received msg=100, ext1=-38, ext2=0
E/MediaPlayer: error (-38, 0)
V/MediaPlayer: callback application
V/MediaPlayer: back from callback
V/MediaPlayer-JNI: reset
V/MediaPlayer: reset
V/MediaPlayer: message received msg=8, ext1=0, ext2=0
V/MediaPlayer: notify(8, 0, 0) callback on disconnected mediaplayer
V/MediaPlayer-JNI: release
V/MediaPlayer: setListener
V/MediaPlayer: disconnect
V/MediaPlayer: destructor
V/MediaPlayer: disconnect

这是我用来调用构造播放器并初始化其所有组件的方法。

private void constructPlayer(SermonDtoNew sermonDto) throws IOException {
    mPlayer = new MediaPlayer();
    if (sermonDto == null) {
        return;
    }
    int pos = this.sermonDto.url.lastIndexOf('/') + 1;
    String str = sermonDto.url.substring(0, pos) + Uri.encode(sermonDto.url.substring(pos));
    mPlayer.setDataSource(this, Uri.parse(str));

    mPlayer.prepareAsync();

    mPlayer.setOnInfoListener(this);
    mPlayer.setOnPreparedListener(this);
    mPlayer.setOnErrorListener(this);
    mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);
    mPlayer.setOnCompletionListener(this);

    if (currentVersionSupportLockScreenControls) {
//            RegisterRemoteClient();
    }

    aquireWifiLock();
    requestFocus();
}

任何帮助将不胜感激。这个相同的代码适用于marshmallow,棒棒糖和除android 4.4.2之外的其他平台。

0 个答案:

没有答案