准备好后,Android MediaPlayer动作OnCompleteListener

时间:2015-05-15 12:57:34

标签: android android-mediaplayer

打开我的应用程序并选择要播放的第一首歌后,我的MediaPlayer动作OnCompleteListener并跳到下一首歌。这个小故障在打开应用程序后只出现一次并且非常烦人。任何想法如何我能解决这个问题吗? 我想我正在使用prepareListener。

    mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
        @Override
        public void onPrepared(MediaPlayer mp) {
            mp.start();
        }
    });

    mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mp) {
            if (currentPosition < musicUrl.size() - 1) {
                currentPosition = currentPosition + 1;
                URL = musicUrl.get(currentPosition);
                Uri uri = Uri.parse(URL);
                try {
                    mediaPlayer.stop();
                    mediaPlayer.reset();
                    mediaPlayer.setDataSource(URL);
                    mediaPlayer.prepareAsync();
                    musicController.setCurrentSong(myDataList.get(currentPosition));
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    });

我的LogCAT:

    05-15 15:51:23.438  22818-22818/ D/DrawerView? onInsetsChanged()
    05-15 15:51:24.917  22818-22834/ V/AudioSystem? ioConfigChanged() event 0, ioHandle 4
    05-15 15:51:24.917  22818-22834/ V/AudioSystem? ioConfigChanged() opening already existing output! 4
    05-15 15:51:24.917  22818-22834/ V/AudioSystem? ioConfigChanged() event 0, ioHandle 2
    05-15 15:51:24.917  22818-22834/ V/AudioSystem? ioConfigChanged() opening already existing output! 2
    05-15 15:51:26.287  22818-22818/ I/ViewRootImpl? ViewRoot's Touch Event : ACTION_DOWN
    05-15 15:51:26.366  22818-22818/ I/ViewRootImpl? ViewRoot's Touch Event : ACTION_UP
    05-15 15:51:26.373  22818-22818/ V/MediaPlayer[Native]? stop
    05-15 15:51:26.373  22818-22818/ E/MediaPlayer[Native]? stop called in state 1
    05-15 15:51:26.373  22818-22818/ V/MediaPlayer[Native]? message received msg=100, ext1=-38, ext2=0
    05-15 15:51:26.373  22818-22818/ E/MediaPlayer[Native]? error (-38, 0)
    05-15 15:51:26.373  22818-22818/ V/MediaPlayer[Native]? callback application
    05-15 15:51:26.373  22818-22818/ V/MediaPlayer[Native]? back from callback
    05-15 15:51:26.374  22818-22818/ V/MediaPlayer[Native]? reset
    05-15 15:51:26.374  22818-22818/ V/MediaPlayer[Native]? before disconnect p = 0x0
    05-15 15:51:26.389  22818-22818/ I/BrunchXmlParserImpl? [BrunchXmlParserImpl::findIndexByKey] typeIndex < 0
    05-15 15:51:26.400  22818-22818/ I/BrunchFeatureSwitchEx? [removeFeatureSwitchExLastItem] size = 14
    05-15 15:51:26.400  22818-22818/ I/BrunchFeatureSwitchEx? [removeFeatureSwitchExLastItem] size = 13
    05-15 15:51:26.400  22818-22818/ I/BrunchFeatureSwitchEx? [removeFeatureSwitchExLastItem] size = 12
    05-15 15:51:26.400  22818-22818/ I/BrunchXmlParserImpl? [BrunchXmlParserImpl::findIndexByKey] typeIndex < 0
    05-15 15:51:26.400  22818-22818/ I/BrunchFeatureSwitchEx? [removeFeatureSwitchExLastItem] size = 11
    05-15 15:51:26.400  22818-22818/ I/BrunchXmlParserImpl? [BrunchXmlParserImpl::findIndexByKey] typeIndex < 0
    05-15 15:51:26.400  22818-22818/ I/BrunchFeatureSwitchEx? [removeFeatureSwitchExLastItem] size = 10
    05-15 15:51:26.400  22818-22818/ I/BrunchXmlParserImpl? [BrunchXmlParserImpl::findIndexByKey] typeIndex < 0
    05-15 15:51:26.400  22818-22818/ I/BrunchFeatureSwitchEx? [removeFeatureSwitchExLastItem] size = 9
    05-15 15:51:26.400  22818-22818/ I/BrunchXmlParserImpl? [BrunchXmlParserImpl::findIndexByKey] typeIndex < 0
    05-15 15:51:26.400  22818-22818/ I/BrunchFeatureSwitchEx? [removeFeatureSwitchExLastItem] size = 8
    05-15 15:51:26.400  22818-22818/ I/BrunchFeatureSwitchEx? [removeFeatureSwitchExLastItem] size = 7
    05-15 15:51:26.400  22818-22818/ I/BrunchFeatureSwitchEx? [removeFeatureSwitchExLastItem] size = 6
    05-15 15:51:26.400  22818-22818/ I/BrunchFeatureSwitchEx? [removeFeatureSwitchExLastItem] size = 5
    05-15 15:51:26.401  22818-22818/ I/BrunchFeatureSwitchEx? [removeFeatureSwitchExLastItem] size = 4
    05-15 15:51:26.401  22818-22818/ I/BrunchFeatureSwitchEx? [removeFeatureSwitchExLastItem] size = 3
    05-15 15:51:26.401  22818-22818/ I/BrunchFeatureSwitchEx? [removeFeatureSwitchExLastItem] size = 2
    05-15 15:51:26.401  22818-22818/ I/BrunchFeatureSwitchEx? [removeFeatureSwitchExLastItem] size = 1
    05-15 15:51:26.402  22818-22818/ V/PropertyFromBrunch? Insert BrunchFeatureInfo strm.comm.video_max_h, Defaults, Video:MaxWidth
    05-15 15:51:26.402  22818-22818/ V/PropertyFromBrunch? Insert BrunchFeatureInfo strm.comm.video_max_w, Defaults, Video:MaxHeight
    05-15 15:51:26.402  22818-22818/ V/PropertyFromBrunch? Insert BrunchFeatureInfo strm.rtsp.rtp_port_min, Rtsps, Port:Min
    05-15 15:51:26.402  22818-22818/ V/PropertyFromBrunch? Insert BrunchFeatureInfo strm.rtsp.rtp_port_max, Rtsps, Port:Max
    05-15 15:51:26.402  22818-22818/ V/PropertyFromBrunch? Insert BrunchFeatureSwitch strm.feature.use_proxy, NewFeatures, Streaming:useProxy
    05-15 15:51:26.402  22818-22818/ D/BrunchUtilityImpl? [MakeUserAgentInfo] Representative features_ex xml
    05-15 15:51:26.402  22818-22818/ D/BrunchUtilityImpl? [MakeUserAgentInfo] get UserAgent
    05-15 15:51:26.402  22818-22818/ D/BrunchUtilityImpl? [MakeUserAgentInfo] csUserAgentType[11100]
    05-15 15:51:26.402  22818-22818/ W/BrunchUtilityImpl? [MakeUserAgentInfo] Model Name, Version, Default User-Agent
    05-15 15:51:26.402  22818-22818/ W/BrunchUtilityImpl? [MakeUserAgent] ro.lge.swversion_short [V20h]
    05-15 15:51:26.402  22818-22818/ W/BrunchUtilityImpl? [MakeUserAgent] NETWORKPLAY_DEFAULT_USER_AGENT
    05-15 15:51:26.402  22818-22818/ V/PropertyFromBrunch? [getPropertyInt32] found key : strm.feature.use_proxy, value : 0
    05-15 15:51:26.402  22818-22818/ V/MediaPlayer[Native]? setDataSource
    05-15 15:51:26.406  22818-22818/ V/MediaPlayer[Native]? setVideoSurfaceTexture
    05-15 15:51:26.406  22818-22818/ V/MediaPlayer[Native]? prepareAsync
    05-15 15:51:26.408  22818-22834/ V/MediaPlayer[Native]? message received msg=8, ext1=0, ext2=0
    05-15 15:51:26.411  22818-22834/ V/MediaPlayer[Native]? unrecognized message: (8, 0, 0)
    05-15 15:51:26.411  22818-22834/ V/MediaPlayer[Native]? callback application
    05-15 15:51:26.411  22818-22834/ V/MediaPlayer[Native]? back from callback
    05-15 15:51:26.414  22818-22818/ V/MediaPlayer[Native]? start
    05-15 15:51:26.414  22818-22818/ E/MediaPlayer[Native]? start called in state 4
    05-15 15:51:26.414  22818-22818/ V/MediaPlayer[Native]? message received msg=100, ext1=-38, ext2=0
    05-15 15:51:26.414  22818-22818/ E/MediaPlayer[Native]? error (-38, 0)
    05-15 15:51:26.414  22818-22818/ V/MediaPlayer[Native]? callback application
    05-15 15:51:26.414  22818-22818/ V/MediaPlayer[Native]? back from callback
    05-15 15:51:26.426  22818-22818/ D/DrawerView? onInsetsChanged()
    05-15 15:51:26.434  22818-22981/ E/MediaHTTPConnectionEx? MediaHTTPConnectionEx contructor
    05-15 15:51:26.434  22818-22836/ E/MediaHTTPConnectionEx? connect
    05-15 15:51:26.435  22818-22836/ E/MediaHTTPConnectionEx? disconnecting
    05-15 15:51:26.436  22818-22836/ E/MediaHTTPConnectionEx? disconnected
    05-15 15:51:26.438  22818-22834/ E/MediaHTTPConnectionEx? [getMIMEType] mContentType:application/octet-stream
    05-15 15:51:26.438  22818-22834/ E/MediaHTTPConnectionEx? [seekToEx] offset:0/mCurrentOffset:-1
    05-15 15:51:26.440  22818-22834/ D/MediaHTTPConnectionEx? [seekToEx] HTTP header =>User-Agent: LG-D855/V20h Player/LG Player 1.0 for Android 5.0 (stagefright alternative)
    05-15 15:51:26.440  22818-22834/ D/MediaHTTPConnectionEx? [seekToEx] include Range: bytes= 0-
    05-15 15:51:26.440  22818-22834/ D/MediaHTTPConnectionEx? [seekToEx] HTTP header =>Range: bytes=0-
    05-15 15:51:26.451  22818-22818/ E/MediaPlayer? Error (-38,0)
    05-15 15:51:26.451  22818-22818/ V/MediaPlayer[Native]? stop
    05-15 15:51:26.452  22818-22818/ E/MediaPlayer[Native]? stop called in state 0
    05-15 15:51:26.452  22818-22818/ V/MediaPlayer[Native]? message received msg=100, ext1=-38, ext2=0
    05-15 15:51:26.452  22818-22818/ E/MediaPlayer[Native]? error (-38, 0)
    05-15 15:51:26.452  22818-22818/ V/MediaPlayer[Native]? callback application
    05-15 15:51:26.452  22818-22818/ V/MediaPlayer[Native]? back from callback
    05-15 15:51:26.452  22818-22818/ V/MediaPlayer[Native]? reset
    05-15 15:51:26.452  22818-22981/ V/MediaPlayer[Native]? message received msg=8, ext1=0, ext2=0
    05-15 15:51:26.452  22818-22818/ E/MediaHTTPConnectionEx? disconnecting
    05-15 15:51:26.452  22818-22818/ E/MediaHTTPConnectionEx? this.mConnection.disconnect();
    05-15 15:51:26.453  22818-22818/ E/MediaHTTPConnectionEx? this.mConnection.disconnected;
    05-15 15:51:26.453  22818-22818/ E/MediaHTTPConnectionEx? disconnected
    05-15 15:51:26.484  22818-23458/ E/MediaHTTPConnectionEx? [seekToEx] offset:0/mCurrentOffset:-1
    05-15 15:51:26.487  22818-22981/ V/MediaPlayer[Native]? notify(8, 0, 0) callback on disconnected mediaplayer
    05-15 15:51:26.487  22818-22981/ V/MediaPlayer[Native]? message received msg=100, ext1=1, ext2=-2147483648
    05-15 15:51:26.487  22818-22981/ E/MediaPlayer[Native]? error (1, -2147483648)
    05-15 15:51:26.487  22818-22981/ V/MediaPlayer[Native]? callback application
    05-15 15:51:26.487  22818-22818/ V/MediaPlayer[Native]? before disconnect p = 0x9d44cf80
    05-15 15:51:26.487  22818-22818/ V/MediaPlayer[Native]? reset disconnect
    05-15 15:51:26.488  22818-22981/ V/MediaPlayer[Native]? back from callback
    05-15 15:51:26.488  22818-22834/ E/MediaHTTPConnectionEx? [seekToEx] offset:0/mCurrentOffset:-1
    05-15 15:51:26.488  22818-22834/ D/MediaHTTPConnection? unknown exception java.lang.NullPointerException: Attempt to invoke virtual method 'java.net.URLConnection java.net.URL.openConnection()' on a null object reference
    05-15 15:51:26.488  22818-22818/ V/PropertyFromBrunch? [getPropertyInt32] found key : strm.feature.use_proxy, value : 0
    05-15 15:51:26.488  22818-22834/ D/MediaHTTPConnection? readAt 0 / 32768 => -1
    05-15 15:51:26.488  22818-22818/ V/MediaPlayer[Native]? setDataSource
    05-15 15:51:26.491  22818-22981/ V/MediaPlayer[Native]? message received msg=8, ext1=0, ext2=0
    05-15 15:51:26.491  22818-22981/ V/MediaPlayer[Native]? notify(8, 0, 0) callback on disconnected mediaplayer
    05-15 15:51:26.491  22818-22818/ V/MediaPlayer[Native]? setVideoSurfaceTexture
    05-15 15:51:26.491  22818-22818/ V/MediaPlayer[Native]? prepareAsync

1 个答案:

答案 0 :(得分:0)

我的问题的解决方案是调用mediaPlayer onErrorListener,当发生错误时,我正在使用相同的URL重试媒体播放器。