web-dev-qa-db-ja.com

ExoPlayerのすべてのエラーをキャッチする方法は?

アプリケーションのプレーヤーとしてExoPlayerを実装しました。しかし、アプリのクラッシュを回避するためにすべてのExoPlayerエラーをキャッチする方法を見つけることができません。次のリスナーを追加しましたが、すべてのエラーをキャッチできるわけではありません。

DRMを使用する必要があり、問題が発生するとクラッシュすることがありますが、プレーヤーがNULLであるため、以前はリスナーを設定できません。

    player = ExoPlayerFactory.newSimpleInstance(context, trackSelector, loadControl, drmSessionManager);

    player.addListener(new ExoPlayer.EventListener() {
        @Override
        public void onTimelineChanged(Timeline timeline, Object manifest) {

        }

        @Override
        public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {

        }

        @Override
        public void onLoadingChanged(boolean isLoading) {

        }

        @Override
        public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {

        }

        @Override
        public void onPlayerError(ExoPlaybackException error) {
            //Catch here, but app still crash on some errors!
        }

        @Override
        public void onPositionDiscontinuity() {

        }
    });

エラーの例:

03-22 16:38:31.401 17960-25624/com.mypackage.name E/ExoPlayerImplInternal: Renderer error.  
                                                                     com.google.Android.exoplayer2.ExoPlaybackException 
                                                                         at com.google.Android.exoplayer2.mediacodec.MediaCodecRenderer.shouldWaitForKeys(MediaCodecRenderer.Java:709)  
                                                                         at com.google.Android.exoplayer2.mediacodec.MediaCodecRenderer.feedInputBuffer(MediaCodecRenderer.Java:650)    
                                                                         at com.google.Android.exoplayer2.mediacodec.MediaCodecRenderer.render(MediaCodecRenderer.Java:490) 
                                                                         at com.google.Android.exoplayer2.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.Java:464)  
                                                                         at com.google.Android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.Java:300)   
                                                                         at Android.os.Handler.dispatchMessage(Handler.Java:98) 
                                                                         at Android.os.Looper.loop(Looper.Java:154) 
                                                                         at Android.os.HandlerThread.run(HandlerThread.Java:61) 
                                                                         at com.google.Android.exoplayer2.util.PriorityHandlerThread.run(PriorityHandlerThread.Java:40) 
                                                                      Caused by: com.google.Android.exoplayer2.drm.DrmSession$DrmSessionException: com.google.Android.exoplayer2.upstream.HttpDataSource$HttpDataSourceException: Unable to connect to https://widevine-dash.ezdrm.com/proxy?pX=blablablabla    
                                                                         at com.google.Android.exoplayer2.drm.DefaultDrmSessionManager.onError(DefaultDrmSessionManager.Java:594)   
                                                                         at com.google.Android.exoplayer2.drm.DefaultDrmSessionManager.onKeysError(DefaultDrmSessionManager.Java:589)   
                                                                         at com.google.Android.exoplayer2.drm.DefaultDrmSessionManager.onKeyResponse(DefaultDrmSessionManager.Java:549) 
                                                                         at com.google.Android.exoplayer2.drm.DefaultDrmSessionManager.access$900(DefaultDrmSessionManager.Java:49) 
                                                                         at com.google.Android.exoplayer2.drm.DefaultDrmSessionManager$PostResponseHandler.handleMessage(DefaultDrmSessionManager.Java:669) 
                                                                         at Android.os.Handler.dispatchMessage(Handler.Java:102)    
                                                                         at Android.os.Looper.loop(Looper.Java:154)     
                                                                         at Android.os.HandlerThread.run(HandlerThread.Java:61)     
                                                                         at com.google.Android.exoplayer2.util.PriorityHandlerThread.run(PriorityHandlerThread.Java:40)     
                                                                      Caused by: com.google.Android.exoplayer2.upstream.HttpDataSource$HttpDataSourceException: Unable to connect to https://widevine-dash.ezdrm.com/proxy?pX=blablablabla  
                                                                         at com.google.Android.exoplayer2.upstream.DefaultHttpDataSource.open(DefaultHttpDataSource.Java:204)   
                                                                         at com.google.Android.exoplayer2.upstream.DataSourceInputStream.checkOpened(DataSourceInputStream.Java:101)    
                                                                         at com.google.Android.exoplayer2.upstream.DataSourceInputStream.read(DataSourceInputStream.Java:81)    
                                                                         at com.google.Android.exoplayer2.upstream.DataSourceInputStream.read(DataSourceInputStream.Java:75)    
                                                                         at com.google.Android.exoplayer2.util.Util.toByteArray(Util.Java:118)  
                                                                         at com.google.Android.exoplayer2.drm.HttpMediaDrmCallback.executePost(HttpMediaDrmCallback.Java:106)   
                                                                         at com.google.Android.exoplayer2.drm.HttpMediaDrmCallback.executeKeyRequest(HttpMediaDrmCallback.Java:91)  
                                                                         at com.google.Android.exoplayer2.drm.DefaultDrmSessionManager$PostRequestHandler.handleMessage(DefaultDrmSessionManager.Java:692)  
                                                                         at Android.os.Handler.dispatchMessage(Handler.Java:102)    
                                                                         at Android.os.Looper.loop(Looper.Java:154) 
                                                                         at Android.os.HandlerThread.run(HandlerThread.Java:61) 
                                                                      Caused by: Java.net.SocketTimeoutException: timeout   
                                                                         at com.Android.okhttp.okio.Okio$3.newTimeoutException(Okio.Java:212)   
                                                                         at com.Android.okhttp.okio.AsyncTimeout.exit(AsyncTimeout.Java:250)    
                                                                         at com.Android.okhttp.okio.AsyncTimeout$2.read(AsyncTimeout.Java:217)  
                                                                         at com.Android.okhttp.okio.RealBufferedSource.indexOf(RealBufferedSource.Java:306) 
                                                                         at com.Android.okhttp.okio.RealBufferedSource.indexOf(RealBufferedSource.Java:300) 
                                                                         at com.Android.okhttp.okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.Java:196)  
                                                                         at com.Android.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.Java:191)   
                                                                         at com.Android.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.Java:80)   
                                                                         at com.Android.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.Java:906)    
                                                                         at com.Android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.Java:782)   
                                                                         at com.Android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.Java:463)   
03-22 16:38:31.401 17960-25624/com.mypackage.name E/ExoPlayerImplInternal:     at com.Android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.Java:405) 
                                                                         at com.Android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.Java:521)   
                                                                         at com.Android.okhttp.internal.huc.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.Java:105) 
                                                                         at com.Android.okhttp.internal.huc.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.Java) 
                                                                         at com.google.Android.exoplayer2.upstream.DefaultHttpDataSource.open(DefaultHttpDataSource.Java:201)   
                                                                            ... 10 more
03-22 16:38:31.402 17960-17960/com.mypackage.name E/PlayerActivity: onPlayerError: com.google.Android.exoplayer2.drm.DrmSession$DrmSessionException: com.google.Android.exoplayer2.upstream.HttpDataSource$HttpDataSourceException: Unable to connect to https://widevine-dash.ezdrm.com/proxy?pX=blablablabla  
03-22 16:38:31.404 17960-17960/com.mypackage.name D/AndroidRuntime: Shutting down VM    
03-22 16:38:31.407 17960-17960/com.mypackage.name E/UncaughtException: Java.lang.IllegalStateException  
                                                                     at com.google.Android.exoplayer2.util.Assertions.checkState(Assertions.Java:79)    
                                                                     at com.google.Android.exoplayer2.ExoPlaybackException.getSourceException(ExoPlaybackException.Java:111)    
                                                                     at com.mypackage.name.ui.activities.PlayerActivity$1.onPlayerError(PlayerActivity.Java:260)    
                                                                     at com.google.Android.exoplayer2.ExoPlayerImpl.handleEvent(ExoPlayerImpl.Java:382) 
                                                                     at com.google.Android.exoplayer2.ExoPlayerImpl$1.handleMessage(ExoPlayerImpl.Java:93)  
                                                                     at Android.os.Handler.dispatchMessage(Handler.Java:102)    
                                                                     at Android.os.Looper.loop(Looper.Java:154) 
                                                                     at Android.app.ActivityThread.main(ActivityThread.Java:6121)   
                                                                     at Java.lang.reflect.Method.invoke(Native Method)  
                                                                     at com.Android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.Java:889) 
                                                                     at com.Android.internal.os.ZygoteInit.main(ZygoteInit.Java:779)    
03-22 16:38:31.417 17960-25623/com.mypackage.name D/FA: Logging event (FE): _ae, Bundle[{_o=crash, _sc=PlayerActivity_, _si=-5050973009208192093, timestamp=1490197111407, fatal=1}]    
03-22 16:38:31.437 17960-25684/com.mypackage.name D/SurfaceUtils: set up nativeWindow 0x791072a810 for 1x1, color 0x2, rotation 0, usage 0x930  
03-22 16:38:31.454 17960-25623/com.mypackage.name V/FA: Using measurement service   
03-22 16:38:31.455 17960-25623/com.mypackage.name V/FA: Connecting to remote service    
03-22 16:38:31.707 17960-17960/com.mypackage.name E/AndroidRuntime: FATAL EXCEPTION: main   
                                                              Process: com.mypackage.name, PID: 17960   
                                                              Java.lang.IllegalStateException   
                                                                  at com.google.Android.exoplayer2.util.Assertions.checkState(Assertions.Java:79)   
                                                                  at com.google.Android.exoplayer2.ExoPlaybackException.getSourceException(ExoPlaybackException.Java:111)   
                                                                  at com.mypackage.name.ui.activities.PlayerActivity$1.onPlayerError(PlayerActivity.Java:260)   
                                                                  at com.google.Android.exoplayer2.ExoPlayerImpl.handleEvent(ExoPlayerImpl.Java:382)    
                                                                  at com.google.Android.exoplayer2.ExoPlayerImpl$1.handleMessage(ExoPlayerImpl.Java:93) 
                                                                  at Android.os.Handler.dispatchMessage(Handler.Java:102)   
                                                                  at Android.os.Looper.loop(Looper.Java:154)    
                                                                  at Android.app.ActivityThread.main(ActivityThread.Java:6121)  
                                                                  at Java.lang.reflect.Method.invoke(Native Method) 
                                                                  at com.Android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.Java:889)    
                                                                  at com.Android.internal.os.ZygoteInit.main(ZygoteInit.Java:779)   
10
Michalsx

ExoPlayerサポートからのフィードバックのおかげで、これはすべての問題をカバーするはずです。

    @Override
    public void onPlayerError(ExoPlaybackException error) {
        switch (error.type) {
            case ExoPlaybackException.TYPE_SOURCE:
                Log.e(TAG, "TYPE_SOURCE: " + error.getSourceException().getMessage());
                break;

            case ExoPlaybackException.TYPE_RENDERER:
                Log.e(TAG, "TYPE_RENDERER: " + error.getRendererException().getMessage());
                break;

            case ExoPlaybackException.TYPE_UNEXPECTED:
                Log.e(TAG, "TYPE_UNEXPECTED: " + error.getUnexpectedException().getMessage());
                break;
        }
    }
21
Michalsx