【发布时间】:2018-02-26 15:20:50
【问题描述】:
我需要在 Ionic 3 中一个接一个地播放音频文件列表
我正在使用ionic native audio plugin
这里的信息是他们告诉如何使用插件(官方文档)
import { NativeAudio } from '@ionic-native/native-audio';
constructor(private nativeAudio: NativeAudio) { }
...
this.nativeAudio.preloadSimple('uniqueId1', 'path/to/file.mp3').then(onSuccess, onError);
this.nativeAudio.preloadComplex('uniqueId2', 'path/to/file2.mp3', 1, 1, 0).then(onSuccess, onError);
this.nativeAudio.play('uniqueId1').then(onSuccess, onError);
// can optionally pass a callback to be called when the file is done playing
this.nativeAudio.play('uniqueId1', () => console.log('uniqueId1 is done playing'));
this.nativeAudio.loop('uniqueId2').then(onSuccess, onError);
this.nativeAudio.setVolumeForComplexAsset('uniqueId2', 0.6).then(onSuccess,onError);
this.nativeAudio.unload('uniqueId1').then(onSuccess,onError);...
我在下面的应用程序中使用它
....
playAll() {
for (let i = 1; i <= 77; i++) {
this.playAvecIonNative(i)
}
}
async playAvecIonNative(i) {
// this.currentBeyit = this.cpt;
this.idAudio = 'w' + i;
this.nativeAudio.preloadComplex(this.idAudio, 'assets/audio/' + i + '.ogg', 1, 1, 0)
.then(await this.onSuccessPreloading, this.onErrorPreload);
}
onSuccessPreloading = (data) => {
this.nativeAudio.play(this.idAudio).then(await this.onSuccessPlaying, this.onErrorPlay);
}
onSuccessPlaying = (a) => {
this.nativeAudio.unload(this.idAudio);
}
onErrorPreload() {
alert('ERREUR PRELOAD')
}
onErrorPlay() {
alert('ERREUR PLAY')
}
当我使用 playAvecIonNative() 测试一个音频文件时,它工作得很好,但对于多个文件,它不能按预期工作 欢迎您的专业知识!
【问题讨论】:
标签: typescript audio ionic-framework