离子原生音频不适用于Android

Gon*_*ols 15 android cordova ionic2 angular

我有问题使用本机音频cordova插件与离子.我使用npm安装了native

sudo npm install --save @ionic-native/native-audio
Run Code Online (Sandbox Code Playgroud)

并添加了一个名为smartAudio的新提供程序(下面附带代码).它在离子网络视图和iOS模拟器/真实设备上都像魅力一样......但由于某些原因,Android模拟器/真实设备上根本没有声音.

我有一个离子幻灯片元素,使用*ngFor生成图像幻灯片,像这样 -

<ion-slides (ionSlideDidChange)="muteAnimalSound()" pager dir="rtl" [loop]="true" >
  <ion-slide *ngFor="let slide of animals_slides; let i = index" style="background-color: white">
    <img src="{{slide.img_url}}" (click)="playAnimalSound($event)">
    </ion-slide>
  </ion-slides>
Run Code Online (Sandbox Code Playgroud)

playAnimalSound()函数看起来像这样 -

playAnimalSound(ev) {
    let animalSound = this.getAnimalBySource(ev.target.src);
    let currentIndex = this.slides.getActiveIndex();

    this.smartAudio.preload(currentIndex, animalSound[0].sound_url);
    this.smartAudio.play(currentIndex);
  }
Run Code Online (Sandbox Code Playgroud)

我的smartAudio提供程序是这样定义的 -

export class SmartAudio {

    audioType: string = 'html5';
    sounds: any = [];

    constructor(public nativeAudio: NativeAudio, platform: Platform) {

        if(platform.is('cordova')){
            this.audioType = 'native';
        }
        //testing atlassian sourcetree

    }

    preload(key, asset) {

        if(this.audioType === 'html5'){

            let audio = {
                key: key,
                asset: asset,
                type: 'html5'
            };

            this.sounds.push(audio);

        } else {

            this.nativeAudio.preloadSimple(key, asset);

            let audio = {
                key: key,
                asset: key,
                type: 'native'
            };

            this.sounds.push(audio);
        }       

    }

    play(key){

        let audio = this.sounds.find((sound) => {
            return sound.key === key;
        });

        if(audio.type === 'html5'){

            let audioAsset = new Audio(audio.asset);
            audioAsset.play();

        } else {

            this.nativeAudio.play(audio.asset).then((res) => {
                console.log(res);
            }, (err) => {
                console.log(err);
            });

        }

    }
    stop(key)
    {
        let audio = this.sounds.find((sound) => {
            return sound.key === key;
        });

         if(audio.type === 'html5'){

            let audioAsset = new Audio(audio.asset);
            audioAsset.play();

        } else {

            this.nativeAudio.stop(audio.asset).then((res) => {
                console.log(res);
            }, (err) => {
                console.log(err);
            });

        }

    }

}
Run Code Online (Sandbox Code Playgroud)

小智 1

我发现您的 smartAudio 提供商存在问题。请将“资产:密钥”更改为“资产:资产”,然后重试。

在此输入图像描述