Плагин smartAudio не работает на реальном устройстве Android - PullRequest
0 голосов
/ 05 ноября 2018

Привет, может кто-нибудь помочь мне выяснить, почему плагин smartAudio не работает на реальном устройстве Android, но он отлично работает в веб-браузере при тестировании приложения?

Я выполнил следующие команды:

$ ionic cordova plugin add cordova-plugin-nativeaudio
$ npm install --save @ionic-native/native-audio

Ниже приведен мой код для воспроизведения звука:

смарт-audio.ts

import { Injectable } from '@angular/core';
import { Platform } from 'ionic-angular';
import { NativeAudio } from '@ionic-native/native-audio';

@Injectable()
export class SmartAudio {

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

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

    if(platform.is('cordova')){
        this.audioType = 'native';
    }

}

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);
        });

    }

}

}

app.module.ts

    import { BrowserModule } from '@angular/platform-browser';
    import { ErrorHandler, NgModule } from '@angular/core';
    import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
    import { SplashScreen } from '@ionic-native/splash-screen';
    import { StatusBar } from '@ionic-native/status-bar';
    import { NativeAudio } from '@ionic-native/native-audio';
    import { SmartAudio } from '../providers/smart-audio/smart-audio';

    import { MyApp } from './app.component';
    import { HomePage } from '../pages/home/home';
    import { KevinPage } from '../pages/kevin/kevin';

    @NgModule({
  declarations: [
    MyApp,
    HomePage,
    KevinPage
  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp)
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    HomePage,
    KevinPage
  ],
  providers: [
    StatusBar,
    SplashScreen,
    NativeAudio,
    {provide: ErrorHandler, useClass: IonicErrorHandler},
    SmartAudio
  ]
    })
    export class AppModule {}

app.component.ts

import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';

import { HomePage } from '../pages/home/home';
import { SmartAudio } from '../providers/smart-audio/smart-audio';
import { NativeAudio } from '@ionic-native/native-audio';
@Component({
  templateUrl: 'app.html'
})
export class MyApp {
  rootPage:any = HomePage;

  constructor(platform: Platform, statusBar: StatusBar, splashScreen: 
SplashScreen, smartAudio: SmartAudio, nativeAudio: NativeAudio) {
platform.ready().then(() => {
  // Okay, so the platform is ready and our plugins are available.
  // Here you can do any higher level native things you might need.
  statusBar.styleDefault();
  splashScreen.hide();
  smartAudio.preload('policeSound', './assets/sounds/basic.mp3');
    });
  }
}

Метод:

 playSound(){
this.smartAudio.play('policeSound');

}

Пожалуйста, помогите мне решить эту проблему, я видел другие сообщения об этой же ошибке, но все еще не повезло, я использую Ionic Framework и использую свое устройство Android для тестирования

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...