Search code examples
nativescriptnativescript-vue

How to catch PlayerError in nativescript-exoplayer and show a propper alert


When the user has connection problems I get this in the console:

PlayerError com.google.android.exoplayer2.ExoPlaybackException: com.google.android.exoplayer2.upstream.HttpDataSource$HttpDataSourceException: Unable to connect to ...

I was wondering if it was possible to catch this error and tell the user that they have connection problems and the video can't load. I'm using this great plugin in nativescript-vue

Here is how I'm using the component in my nativescript-vue app:

  <exoplayer
    :src="video.src"
    autoplay="true"
    controls="false"
    height="300"
    @finished="done"
  />

Solution

  • I found this in the videoplayer.android.js file of the plugin in node_modules:

    onPlayerError: function (error) {
    
    },
    

    So I assigned a callback function to the global object in my component and called the function on the global object in the onPlayerError function.
    Works for android now.