2017-06-06 70 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');