smartAudio plugin not working on an Android real device











up vote
0
down vote

favorite












Hi can anyone help me to figure out why the smartAudio plugin is not working on a real android device but it works perfectly on the web browser when testing the application?



I ran the following commands:



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


Below is my code to play the sound:



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


Method:



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


}



Please help me out to get this issue resolved, I have seen other posts regarding the same error but still no luck, I'm using Ionic framework and using my Android device to test










share|improve this question


























    up vote
    0
    down vote

    favorite












    Hi can anyone help me to figure out why the smartAudio plugin is not working on a real android device but it works perfectly on the web browser when testing the application?



    I ran the following commands:



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


    Below is my code to play the sound:



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


    Method:



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


    }



    Please help me out to get this issue resolved, I have seen other posts regarding the same error but still no luck, I'm using Ionic framework and using my Android device to test










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      Hi can anyone help me to figure out why the smartAudio plugin is not working on a real android device but it works perfectly on the web browser when testing the application?



      I ran the following commands:



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


      Below is my code to play the sound:



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


      Method:



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


      }



      Please help me out to get this issue resolved, I have seen other posts regarding the same error but still no luck, I'm using Ionic framework and using my Android device to test










      share|improve this question













      Hi can anyone help me to figure out why the smartAudio plugin is not working on a real android device but it works perfectly on the web browser when testing the application?



      I ran the following commands:



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


      Below is my code to play the sound:



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


      Method:



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


      }



      Please help me out to get this issue resolved, I have seen other posts regarding the same error but still no luck, I'm using Ionic framework and using my Android device to test







      android angular cordova ionic-framework






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 5 at 2:05









      Germinator Mendez

      82




      82





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53147403%2fsmartaudio-plugin-not-working-on-an-android-real-device%23new-answer', 'question_page');
          }
          );

          Post as a guest





































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53147403%2fsmartaudio-plugin-not-working-on-an-android-real-device%23new-answer', 'question_page');
          }
          );

          Post as a guest




















































































          這個網誌中的熱門文章

          Xamarin.form Move up view when keyboard appear

          Post-Redirect-Get with Spring WebFlux and Thymeleaf

          Anylogic : not able to use stopDelay()