Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by Legedric

Hey guys!

I am currently using impactjs to build a new browsergame and I began to struggle with playing sounds with the built in soundmanager.

The code I use is quite simple:
var laserLaunchSound = new ig.Sound( 'media/sounds/laser_shot.*' );
laserLaunchSound.play();

I created an .ogg and mp3 version of the sound file and in IE9 it works just fine (nearly without delay) but in Firefox and Chrome (most recent versions) it does just nothing (no exceptions are thrown)...

I also tried to implement sounds by using the soundmanager2 library but the delay between animation and hearing a sound was quite huge so I went back to the built in soundmanager.

I appreciate any on this and I am also open for any other JS sound/audio lib to use cross browser!

Best regards,

Legedric

1 decade ago by dominic

Check the resources panel in your browser's debug tools and see if the sound file is really requested and loaded. Maybe it's just a typo!?

Also, make sure to create the Sound instance as a class variable instead of directly in a function. This will attach the sound file to the pre-loader, so it's readily available when it's needed. More info here:
http://impactjs.com/documentation/working-with-assets#using-the-preloader

1 decade ago by Legedric

Thanks for the quick response!

I double checked the file names and they are all right...

I now changed the sound loading to this:

ig.module(
  'game.manager.customsoundmanager'
)
.requires(
  'game.helper.loghelper',
  'game.helper.constants'
)
.defines(function(){

CustomSoundManager = ig.Class.extend({
  laserLaunchSound: null,
  alienExplosionSound: null,
  grenadeExplosionSound: null,
  missileExplosionSound: null,
  stoneHitSound: null,

  initialize: function() {
    this.laserLaunchSound = new ig.Sound( 'media/sounds/laser_shot.*' );
    this.alienExplosionSound = new ig.Sound( 'media/sounds/alien_hit.*' );
    this.grenadeExplosionSound = new ig.Sound( 'media/sounds/grenade_explosion.*' );
    this.missileExplosionSound = new ig.Sound( 'media/sounds/missile_explosion.*' );
    this.stoneHitSound = new ig.Sound( 'media/sounds/stone_hit.*' );
  }
});

});

The sound firing then happens with this line:
ig.game.customSoundManager.laserLaunchSound.play();

Again: IE9 works like a charm, FF & Chrome do not...
I guess that there might be something wrong with my .ogg files as the IE uses the .mp3 files (afaik). Although the .ogg equivalents play just fine when I open them in Windows Media Player.

Perhaps I will try it with the .ogg files from z-type just to test it, as z.type works for me in any browser (including sounds).

1 decade ago by dahl

Yeah i'm not having trouble with sound, but my animation will not play. it just shows the first '0' frame of my anim and it just sits there.

ig.module(
	'game.entities.skull'
)
.requires(
	'impact.entity'
)
.defines(function(){

EntitySkull = ig.Entity.extend({
	
	size: {x:56, y:56},
	collides: ig.Entity.COLLIDES.FIXED,
	type: ig.Entity.TYPE.A,
	checkAgainst: ig.Entity.TYPE.A,
	
	animSheet: new ig.AnimationSheet( 'media/skull.png', 56, 56 ),
	
	init: function( x, y, settings ) {
		this.parent( x, y, settings );
		
		this.addAnim( 'idle', 0.1, [0,1,2,3,4,5,6,7] );
		
		this.vel.x =0;
		this.vel.y = 25;
		
		
	},
	
	update: function() {
		
	},
	
});

	

});

it looks ok to me, i didn't change anything from yesterday.

1 decade ago by Jerczu

@dahl add
this.parent();

in your update function and mark your code block with just two # rather than a long line ############## like that.

1 decade ago by dahl

Ok. #x2. Also, i just removed the empty 'update: function' and that fixed it. in firefox anyway. chrome just locks up. so it's prolly just a chrome thing.

thanks.

1 decade ago by rootbeerking

Yeah I too am having trouble with sounds/music playing in firefox. They play just fine in everything else. Not sure what the issue with firefox is.

EDIT: Actually the sounds are all playing fine in firefox and chrome while the game is on my private server. But when I upload the game to my hosted server the audio doesn't play. Everything is where it should be, so why they aren't working, I do not know.

1 decade ago by Legedric

Problem solved!

So after I tried using the sound files from z-type (including music) it is still the same... so IE=yes, everything else = no...

I also tried to analyze the loading of the sound files using the development tools of each browser. For IE it loads the .mp3 versions of the files and all goes well. For Firefox, Firebug lists a 404 for the .ogg versions of the files... for Chrome it does the same.

So I checked the paths listed in there and they were all right which nearly drove me mad... But then I tried to access the files directly with the specific browser and I got this:

HTTP Error 404.3 - Not Found

The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.


This is an IIS specific error which says that the file type (ogg in this case) is not being handled by it so it got blocked.
All I got to do then was to add the MIME type to the IIS file type list (.oog -> audio/ogg) and now it works in all my browsers!

So in any case someone else uses impactjs on a windows machine you may run into this issue and the above mentioned is the solution...

The reason why it worked in IE is that the .mp3 files are mapped correctly by default and so the .mp3 sound files could be loaded but not the .ogg ones.

Best regards,

Legedric

1 decade ago by Figures

Thanks a ton for this solution! Fixed my problem JUST before I pulled all my hair out.
Page 1 of 1
« first « previous next › last »