首页 > 解决方案 > 如何在 nativescript-exoplayer 中捕获 PlayerError 并显示适当的警报

问题描述

当用户有连接问题时,我在控制台中得到这个:

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

我想知道是否有可能捕捉到这个错误并告诉用户他们有连接问题并且视频无法加载。我在 nativescript-vue 中使用这个很棒的插件

这是我在 nativescript-vue 应用程序中使用该组件的方式:

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

标签: nativescriptnativescript-vue

解决方案


我在 node_modules 插件的 videoplayer.android.js 文件中找到了这个:

onPlayerError: function (error) {

},

所以我给组件中的全局对象分配了一个回调函数,并在 onPlayerError 函数中调用了全局对象上的函数。
现在适用于安卓。


推荐阅读