2017-06-06 30 views
0

嗨我一直在使用cordova-native-plugin在我的应用程序中播放音频。我有音频列表,并添加了按钮播放和停止列表中的每个项目。参考已存在给定的音频ID和参考不存在

当我点击播放我得到这个错误:

Unhandled Promise rejection: A reference does not exist for the specified audio id. ; Zone: ; Task: null ; Value: A reference does not exist for the specified audio id. undefined

,而有时我得到:参考已经存在。虽然我的音频播放正常。

任何人都可以请告诉我如何解决这些错误。我不希望这些警报之间停止我的应用程序本身。

playAudio(id, source) { 
    console.log(id + " " + source); 
    this.nativeAudio.preloadSimple(id.toString(), source);  
    this.nativeAudio.play(id.toString()); 
} 

preloadSimple方法有什么问题。

+0

https://github.com/floatinghotpot/cordova-plugin-nativeaudio/issues/ 121 –

+0

我试过这个,但是这个解决方案不起作用。请注意我正在使用Ionic 2,angular 2和打字稿 – Prajakta

回答

1

我有同样的问题。要解决这个问题,我在应用程序启动时预加载音频。

在你app.component.ts(IM使用离子3)检查,如果该平台已准备就绪,你的预加载与音频后:

this.nativeAudio.preloadSimple('pin3', 'assets/audios/pin3Audio.mp3');