Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to catch all errors for ExoPlayer?

I implemented ExoPlayer as player for my application. But I can´t find out how to catch all ExoPlayer errors to avoid app crash. I added following listener, but it doesn´t catch all errors.

I have to use DRM and it sometimes crash on some problem with it, but I can´t set listener before, because player is 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() {

    }
});

Error example:

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)
like image 737
Michalsx Avatar asked Mar 22 '17 09:03

Michalsx


People also ask

Who uses ExoPlayer?

ExoPlayerView is one of the most used UI components in many apps such as YouTube, Netflix, and many video streaming platforms.

Does ExoPlayer support m3u8?

mpd or . m3u8 video file from server using FFMPEG. Exoplayer does not support mp4 file format for adaptive streaming but you can choose mp4 like format for auto streaming. Auto streaming is something which is completely depends on speed and connectivity of the internet.

What is ExoPlayer v2?

ExoPlayer is an application level media player for Android. It provides an alternative to Android's MediaPlayer API for playing audio and video both locally and over the Internet. ExoPlayer supports features not currently supported by Android's MediaPlayer API, including DASH and SmoothStreaming adaptive playbacks.

How do I hide Seekbar in ExoPlayer?

You can do it simply by creating a layout named: exo_playback_control_view. xml and override the regular XML. On this one below is the standard XML, You can add android:visiblite="invisible" for DefaultTimeBar which is what I think you're trying to hide, if not feel free change it as you want.


1 Answers

As Event Listener is @deprecated now you can call Listener

Kotlin

var exoPlayer = SimpleExoPlayer.Builder(context).build()

exoPlayer?.addListener(object : Player.Listener {
        override fun onPlayerError(error: ExoPlaybackException) {
            when(error.type){
                ExoPlaybackException.TYPE_REMOTE -> {
                    Utils.appToast(
                        requireActivity(),
                        error.localizedMessage
                    )
                }
                ExoPlaybackException.TYPE_RENDERER -> {
                    Utils.appToast(
                        requireActivity(),
                        error.rendererException.message
                    )
                }
                ExoPlaybackException.TYPE_SOURCE -> {
                    Utils.appToast(
                        requireActivity(),
                        error.sourceException.message
                    )
                }
                ExoPlaybackException.TYPE_UNEXPECTED -> {
                    Utils.appToast(
                        requireActivity(),
                        error.unexpectedException.message
                    )
                }
            }
        }
    })

And in initialize player function

private fun initializePlayer() {

    bi.exoVideoPlayer.player = exoPlayer
            .......
}
like image 189
Ali Azaz Alam Avatar answered Oct 03 '22 00:10

Ali Azaz Alam