Native Audio Problem

I’m using emulator and first open the app audio not play.
But back to main window and run,audio is play
why first not play?

No idea.

Add your ionic info output and packages.json content please.
Share the relevant code that plays the audio please.



    "scripts": {
        "clean": "ionic-app-scripts clean",
        "build": "ionic-app-scripts build",
        "ionic:build": "ionic-app-scripts build",
        "ionic:serve": "ionic-app-scripts serve"
    "dependencies": {
        "@angular/common": "4.1.3",
        "@angular/compiler": "4.1.3",
        "@angular/compiler-cli": "4.1.3",
        "@angular/core": "4.1.3",
        "@angular/forms": "4.1.3",
        "@angular/http": "4.1.3",
        "@angular/platform-browser": "4.1.3",
        "@angular/platform-browser-dynamic": "4.1.3",
        "@ionic-native/core": "3.12.1",
        "@ionic-native/media": "^3.14.0",
        "@ionic-native/native-audio": "^3.14.0",
        "@ionic-native/screen-orientation": "^3.12.1",
        "@ionic-native/splash-screen": "^3.12.1",
        "@ionic-native/status-bar": "^3.12.1",
        "@ionic-native/streaming-media": "^3.14.0",
        "@ionic/storage": "^2.0.1",
        "com.hutchind.cordova.plugins.streamingmedia": "~0.1.4",
        "cordova-android": "^6.2.3",
        "cordova-ios": "^4.4.0",
        "cordova-plugin-compat": "^1.0.0",
        "cordova-plugin-console": "^1.0.5",
        "cordova-plugin-crosswalk-webview": "^2.3.0",
        "cordova-plugin-device": "^1.1.4",
        "cordova-plugin-file": "^4.0.0",
        "cordova-plugin-media": "^3.0.1",
        "cordova-plugin-nativeaudio": "^3.0.9",
        "cordova-plugin-screen-orientation": "^2.0.1",
        "cordova-plugin-splashscreen": "^4.0.3",
        "cordova-plugin-statusbar": "^2.2.2",
        "cordova-plugin-streaming-media": "^1.0.2",
        "cordova-plugin-whitelist": "^1.3.1",
        "cordova-sqlite-storage": "^2.0.4",
        "ionic-angular": "3.5.0",
        "ionic-audio": "^3.1.0",
        "ionic-plugin-keyboard": "^2.2.1",
        "ionicons": "3.0.0",
        "rxjs": "5.4.0",
        "sw-toolbox": "3.6.0",
        "zone.js": "0.8.12"
    "devDependencies": {
        "@ionic/app-scripts": "^1.3.12",
        "@ionic/cli-plugin-cordova": "1.4.0",
        "@ionic/cli-plugin-ionic-angular": "1.3.1",
        "typescript": "2.3.4"
    "description": "An Ionic project",
    "cordova": {
        "plugins": {
            "cordova-plugin-screen-orientation": {},
            "cordova-plugin-console": {},
            "cordova-plugin-device": {},
            "cordova-plugin-statusbar": {},
            "cordova-plugin-whitelist": {},
            "ionic-plugin-keyboard": {},
            "cordova-sqlite-storage": {},
            "com.hutchind.cordova.plugins.streamingmedia": {},
            "cordova-plugin-media": {},
            "cordova-plugin-nativeaudio": {},
            "cordova-plugin-splashscreen": {},
            "cordova-plugin-crosswalk-webview": {
                "XWALK_VERSION": "23+",
                "XWALK_LITEVERSION": "xwalk_core_library_canary:17+",
                "XWALK_COMMANDLINE": "--disable-pull-to-refresh-effect",
                "XWALK_MODE": "embedded",
                "XWALK_MULTIPLEAPK": "true"
        "platforms": []

ionic info


	ionViewDidLoad() {

You should probably check if platform is ready() here before doing that.

app.component.ts OR myFile.ts

No idea as you only labeled it “my code”. The one in “ionViewDidLoad()”.


export class MyApp {
  rootPage:any = HomePage;

  constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
    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.


myFile.ts, in ionViewDidLoad() you are doing stuff that doesn’t work if the platform is not ready. Wrap the code in there in platform.ready() to make sure the platform is ready before you play the sound.

would you like that

		this.platform.ready().then(() => {

Yes, something like that. Note that you also have to DI the platform in the constructor for this to work, as in app.module.

Yes I did but dont run.
Same thing firstly install app my emulator dont run , but after run

I now looked into the actual code you are writing: You are using the functions of nativeAudio wrong. Look at the examples at The methods return promises, so you have to work in .then() and just not the next line. The code is async, so when you call .play id didn’t finish .preloadSimple yet.

I cant use

  			function(msg){}, function(msg){});
		this.nativeAudio.preloadComplex('uniqueKey1', '..................', 1, 1, 0).then(
			function(msg){}, function(msg){});'uniqueKey1');

What do you mean by “I cant use”. Is this a question? Or are you telling me?

.play should be called inside the success handler of the preloadSimple probably.

Dont run

  constructor(public platform:Platform,public navCtrl: NavController,private nativeAudio: NativeAudio) {


		this.platform.ready().then(() => {	
			this.nativeAudio.preloadComplex('uniqueKey1', '..................', 1, 1, 0).then(

Why not?
Do you get an error?
Does it never work now or still as before?

Try this:

ionViewDidLoad() {
  this.platform.ready().then(() => {	
    this.nativeAudio.preloadComplex('uniqueKey1', 'assets/audio/merhaba.mp3', 1, 1, 0).then(() => {  'uniqueKey1');

Yes it is.Thank you.
And I want my app button starting disable but it’s first install app its enable.
Is it same reason?

< h1>{{al}}----{{b}}< /h1 >

class Page {

Sorry, your last two messages make no sense to me at all. If it is a different problem (not Native Audio) please create a new topic.

Thanks for providing this explanation. If we want to then unload the audio after it plays can we safely do that upon ionViewDidLeave firing? Or does it also need to be inside of a handler like the play function?