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
android angular cordova ionic-framework
add a comment |
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
android angular cordova ionic-framework
add a comment |
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
android angular cordova ionic-framework
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
android angular cordova ionic-framework
asked Nov 5 at 2:05
Germinator Mendez
82
82
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password