No sound in HTML5

I’m trying to make a simple program to run a psychology study. The following code plays a sequence of tones at different intervals when compiled to neko. When trying to run the same code in HTML5 there is no audio. I’ve tried running this in chrome, firefox and ie with no luck. Is there some HTML5 specific audio initialization I’m missing?

package;

import haxe.Timer;

import openfl.Assets;
import openfl.display.Bitmap;
import openfl.display.Sprite;
import openfl.events.KeyboardEvent;
import openfl.events.TimerEvent;
import openfl.Lib;
import openfl.Lib.getTimer;
import openfl.media.Sound;

/**
 * ...
 * @author Bobby
 */
class Main extends Sprite 
{
//delare vars
	public var beepInterval = 500;
	public var betweenTrialBreak = 1500;
	
	public var startTime = 0.0;
	
	public var stim = new Bitmap(Assets.getBitmapData("img/1.png"));
	public var beep:Sound = Assets.getSound("audio/beep.wav");
	public var stimList = new Array();
	
	//Initialization
	public function new() 
	{
		super();
		
		//populate stim list
		stimList[1] = new Bitmap(Assets.getBitmapData("img/1.png"));
		stimList[2] = new Bitmap(Assets.getBitmapData("img/2.png"));
		stimList[3] = new Bitmap(Assets.getBitmapData("img/3.png"));
		stimList[4] = new Bitmap(Assets.getBitmapData("img/4.png"));
		
		startTime = Timer.stamp();
		Timer.delay(playBeep, 500);
		Timer.delay(playBeep, beepInterval * 2);
		Timer.delay(playBeep, beepInterval * 3);
		Timer.delay(playBeep, beepInterval * 4);
		
		Timer.delay(presentStim, 1000);
	}
	
	public function playBeep() { //Plays a beep!
		beep.play();
	}
	
	private function presentStim() { //Presents a stimulus
		addChild (stim);
	}	
}

You probably need to use other sound file formats. In your case .ogg.
Have a look at the openfl example PlayingSound

        #if flash
	sound = Assets.getSound ("assets/stars.mp3");
	#else
	sound = Assets.getSound ("assets/stars.ogg");
	#end

Thanks so much, I tried reading previous forum posts but didn’t find the PlayingSound openfl example. Switching to playing the files as .ogg format fixed this issue nicely!

Check out this thread:


You might need more than one sound file format.

1 Like