I can’t get Sound to load a small mp3 file. I’ve done this plenty in AS3 Air projects. I’ve looked really hard for stupid mistakes but I must be missing something. I am using HaxeDevelop and targeting “windows” currently using “Debug”.
Can anyone help?
Here is the program.
package;
import openfl.display.Sprite;
import openfl.Lib;
import openfl.media.Sound;
import openfl.media.SoundTransform;
import openfl.media.SoundChannel;
import openfl.net.URLRequest;
import openfl.utils.Timer;
import openfl.events.Event;
import openfl.events.TimerEvent;
import openfl.events.IOErrorEvent;
import sys.FileSystem;
/**
* ...
* @author Bruce
*/
class Main extends Sprite
{
private var _treePlantManySound :Sound;
private var _treePlantManySoundTrans:SoundTransform;
private var _treePlanManytSoundChan :SoundChannel;
private var _repeatTimer :Timer;
private var _theSoundURLRequest :URLRequest;
public function new()
{
super();
_repeatTimer = new Timer(5000, 0);
_repeatTimer.addEventListener(TimerEvent.TIMER, playItAgain, false);
_repeatTimer.start();
trace("FileSystem.exists() = " + FileSystem.exists("../../Audio/A/SoundDogs_Audio/testsound.mp3"));
_theSoundURLRequest = new URLRequest("../../Audio/A/SoundDogs_Audio/testsound.mp3");
trace("_theSoundURLRequest.url = " + _theSoundURLRequest.url);
//_treePlantManySound = new Sound(_theSoundURLRequest);
_treePlantManySound = new Sound();
_treePlantManySound.addEventListener(IOErrorEvent.IO_ERROR, handleIOErrors, false);
_treePlantManySound.load(_theSoundURLRequest);
_treePlantManySoundTrans = new SoundTransform(1);
}
private function playItAgain(event :TimerEvent):Void
{
trace("bytes loaded = " + _treePlantManySound.bytesLoaded);
_treePlanManytSoundChan = _treePlantManySound.play(0, 2, _treePlantManySoundTrans);
}
private function handleIOErrors(event :IOErrorEvent):Void
{
trace("handleIOErrors() event target = " + event.target);
trace("handleIOErrors() event current target = " + event.currentTarget);
trace("handleIOErrors() event text = " + event.text);
trace("handleIOErrors() event toString() = " + event.toString());
trace("handleIOErrors() event = " + event);
}
}
Here is the output:
Running process: C:\HaxeToolkit\haxe\haxelib.exe run lime run “project.xml” windows -debug -notrace
src/Main.hx:36: FileSystem.exists() = true
src/Main.hx:38: _theSoundURLRequest.url = …/…/Audio/A/SoundDogs_Audio/testsound.mp3
src/Main.hx:54: handleIOErrors() event target = [object Sound]
src/Main.hx:55: handleIOErrors() event current target = [object Sound]
src/Main.hx:56: handleIOErrors() event text =
src/Main.hx:57: handleIOErrors() event toString() = [IOErrorEvent type=“ioError” bubbles=true cancelable=false text="" errorID=0]
src/Main.hx:58: handleIOErrors() event = [IOErrorEvent type=“ioError” bubbles=true cancelable=false text="" errorID=0]
src/Main.hx:48: bytes loaded = 0
src/Main.hx:48: bytes loaded = 0
src/Main.hx:48: bytes loaded = 0
Haxe Develop says my SDK is “Haxe 4.1.1”
Here is what haxelib says:
C:\Users\BBartonSr>haxelib list
actuate: [1.8.9]
box2d: [1.2.3]
hxcpp: [4.2.1]
layout: [1.2.1]
lime-samples: [7.0.0]
lime: [7.8.0]
nme: [6.1.1]
openfl-samples: [8.7.0]
openfl: [9.0.2]
polygonal-printf: [1.0.2-beta]
Any suggestions?
Thank you.