Jump to content

Any idea what this error means?


Ninjadoodle
 Share

Recommended Posts

Hi @enpu

I'm just testing on iOS through Panda remote, and I'm getting this error ...

C:\Users\tom\AppData\Local\Programs\Panda2\resources\app.asar\device\device.js:329 iOS iPhone8,4: audio.js:586 InvalidStateError: The object is in an invalid state.

I'm not sure what it means, but it stops the level from working. The same level / game works fine on Desktop.

Thank you in advance!

*** EDIT - just tried again for like the 5th time and this time it worked - should I worry about this? ***

Link to comment
Share on other sites

The error means that you are trying to stop sound that is not playing or that is already stopped.

Though it should only try to stop sound that is playing, so it feels like a bug. What iOS version are you using? Do you have any code in your game where you are calling stop method of Sound or Music?

Link to comment
Share on other sites

Hi @enpu

I'm on iOS 11.4 (iPhone SE)

I'm trying to stop a 'music' called intro, before playing new 'music' called theme.

The intro music is still definitely playing when I call intro.stop();

If I don't stop the intro music, and just play the theme music - it stops the intro, and plays theme without any issues.

game.module(
    'game.menu'
)
.body(function() {

game.createScene('Menu', {
    
    init: function() {
        
        intro = new game.Music('musicIntroHighTide.wav');
        intro.loop = false;
        if (!played) {
            intro.play();
            played = true;
        }
        
        outro = new game.Music('musicStingerHighTide.wav');
        outro.loop = false;
        
        theme = new game.Music('musicFullMixAltHighTide.wav');
        
        stage = game.storage.get('stage', 0);
        
        this.stageSetup = new game.StageSetup();
        this.stageSetup.setupStage();
        this.stageSetup.containers();
        
        this.menuPlay = new game.Sprite('menuPlay.png');
        this.menuPlay.position.set(640, 960);
        this.menuPlay.anchorCenter();
        this.menuPlay.interactive = true;
        this.menuPlay.addTo(game.scene.gm);
        
        this.menuPlay.mousedown = function() {
            
            game.audio.playSound('click.wav');
            
            this.scale.set(0.8);
            game.Tween.add(this.scale, {
                x: 1,
                y: 1
            }, 100, {
                delay: 100,
                easing: 'Back.Out'
            }).start();
            
            game.scene.fader.fadeOut(game.scene.rockOn);
        };
    },
    
    rockOn: function() {
        
        intro.stop();
        theme.play();
        
        if (stage !== 0) {
            game.system.setScene(stage);
        } else {
            game.system.setScene(game.config.start);
        }
    },
    
    update: function() {
        this.stageSetup.updateStage();
    }
});

});

 

Link to comment
Share on other sites

There are few things in your code that i would suggest to change.

1) In JavaScript if you create new variable without "var" keyword, that variable is created into global window object. While that might work, it's not good idea since you might accidentally overwrite something important in the window object, which can cause issues.

game.createScene('Main', {
    init: function() {
        test = 'hello';
        console.log(window.test); // hello
        
        var test = 'hello';
        console.log(window.test); // undefined
    }
});

2) When playing new music, you don't need to stop the current music, the engine will handle that.

3) It might not be a good idea to use wav format for music files. Wav is uncompressed audio format, so file size can get pretty big on longer audios. Use m4a or ogg instead.

Here is how i would change your code:

game.module(
    'game.menu'
)
.body(function() {

game.createScene('Menu', {
    init: function() {
        if (!game.Menu.played) {
            game.audio.playMusic('musicIntroHighTide.wav');
            game.audio.music.loop = false;
            game.Menu.played = true;
        }
        
        this.stage = game.storage.get('stage', 0);
        
        this.stageSetup = new game.StageSetup();
        this.stageSetup.setupStage();
        this.stageSetup.containers();
        
        this.menuPlay = new game.Sprite('menuPlay.png');
        this.menuPlay.position.set(640, 960);
        this.menuPlay.anchorCenter();
        this.menuPlay.interactive = true;
        this.menuPlay.addTo(game.scene.gm);
        
        this.menuPlay.mousedown = function() {
            game.audio.playSound('click.wav');
            
            this.scale.set(0.8);
            game.Tween.add(this.scale, {
                x: 1,
                y: 1
            }, 100, {
                delay: 100,
                easing: 'Back.Out'
            }).start();
            
            game.scene.fader.fadeOut(game.scene.rockOn);
        };
    },
    
    rockOn: function() {
        game.audio.playMusic('musicFullMixAltHighTide.wav');
        
        if (this.stage !== 0) {
            game.system.setScene(this.stage);
        } else {
            game.system.setScene(game.config.start);
        }
    },
    
    update: function() {
        this.stageSetup.updateStage();
    }
});

});

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...