No sound in open-fl loaded SWF, plays fine in Adobe player?

I’m trying a simple test SWF that has sound (stolen from PiratePig) embedded at the beginning on its own track as a stream rather than an event.

I include it with <library path="assets/cutscenes/test.swf" type="swflite" /> and load it with:

class Main extends Sprite {
    public function new() {
        super();
        Assets.loadLibrary ("test", function (_) {
            var clip = Assets.getMovieClip ("test:");
            addChild (clip);
        });
    }
}

The SWF plays exactly right in the standalone player, but in my openfl code above, there’s no sound. The visuals look fine, though.

I’ve tried various sound encoding options for the source–raw, mp3, high/low bitrates, high/low quality, to no avail.

I can play just fine the same sound file separate from the swf (but then they’re not necessarily in sync, and that’s not how one is supposed to do things, I guess) so I know OpenFL sound in general is working for me:

    var Sound3:Sound = Assets.getSound ("assets/theme.wav");
    Sound3.play();

Is anyone else having this trouble? The code mentions sound streams, so I guess it’s supported, but then there’s the odd un-answered github issue about sound on openfl/swf’s repo.

Flash target, btw, but hope to target windows, android, linux, eventually…

I guess, this feature is just not supported in native.
The solution here is to play this sound manually.

I thought native meant windows/mac/linux via hxcpp? This is occurring even on flash. On native windows I get a crash loading any swf.

Is there a good method to ensure the sound and the visuals stay in sync, if you play the sound manually at the beginning of the swf and then it chokes on some frames? Seems the rendering is a bit less smooth than the standalone player and I have a lot of fast transitions.

Well, then it doesn’t work even on flash. :frowning:
Try legacy mode, it’s more stable for me. At least swf is not crashing on native.

I think, if swf chokes, then sound desync anyway, whether you play it manually or inside swf.

1 Like

So, you have sound working OK in legacy? In that case I’ll definitely give it a shot…otherwise, I might as well abandon SWF and just animate manually, because at least then I’d by default break the sounds up into chunks, so they would be sync’d every few seconds. (It doesn’t make sense to bother breaking them up if you are composing an SWF with a timeline editor, but it sure makes getting timing right easier in code…I had just assumed that a timeline editor would make the development process smoother with its instant iteration, and thus more enjoyable. Not necessarily so :))

Flash Player has a built-in feature to prevent desyncing, but I doubt OpenFL does. (So even if you could play the sound from the SWF file, the “stream” setting wouldn’t work.)

Does it really? The only mention I see in the Sound class is the option to “stream” the sound (i.e., play it as it loads). This is different from the option to synchronize the sound with the animation.

If you want to implement this yourself, I would suggest timing the animation based on the value of sound.position. Each frame, get the value of sound.position, calculate the video frame that should appear at that point in time, and display it. This will cause you to skip frames if the audio gets too far ahead, but at least it’ll keep things in sync.

Oh, thanks for the explanation. (You’re right, I hadn’t looked closely enough for context.) I’m not quite ambitious enough to implement it myself, but whether it’s me or someone else your advice will be useful, so thanks.