【问题标题】:Playing Sequentially audio files (Ionic 3 Native Audio)连续播放音频文件(Ionic 3 Native Audio)
【发布时间】: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


    【解决方案1】:

    这个级别的插件似乎是一个错误

    // can optionally pass a callback to be called when the file is done playing
    this.nativeAudio.play('uniqueId1', () => console.log('uniqueId1 is done playing'));
    

    这个bug似乎在播放完成后的回调方法上。回调与插件的 this.nativeAudio.play 方法同时执行

    查看Post

    【讨论】:

    • 是的,它似乎认为“完成播放”已加载并开始播放。我有同样的问题,除了在第二个文件上运行第一个文件的播放长度的 setTimeout 之外,我不知道如何解决它;这种方法不是一个好习惯。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多