Skip to content

Remove redundant music checks in frontend methods - #3586

Merged
Geokureli merged 2 commits into
HaxeFlixel:devfrom
Geokureli:music-focus
Apr 12, 2026
Merged

Remove redundant music checks in frontend methods#3586
Geokureli merged 2 commits into
HaxeFlixel:devfrom
Geokureli:music-focus

Conversation

@Geokureli

@Geokureli Geokureli commented Apr 6, 2026

Copy link
Copy Markdown
Member

Fixes #3580

Introduced in #3558

Now that music is added to FlxG.sound.list (an unintended change, but not a bad thing) FlxG.sound.onFocusLost calls music.onFocusLost twice. the second would set _resumeOnFocus to false since it was already paused

I'm not sure why music was not added to the list, I'll check for any other unintended side effects of this change before merging. That may have been be a breaking change, as if anyone checked the if the list contains the music, it would have been false, but is now true, but that seems like an odd thing to do.

I don't think I can unit test this, but i'll look and see Added tests

@Geokureli Geokureli added this to the 6.2.0 milestone Apr 6, 2026
@Geokureli
Geokureli marked this pull request as ready for review April 6, 2026 17:40
@Geokureli
Geokureli merged commit da83ac9 into HaxeFlixel:dev Apr 12, 2026
10 checks passed
@Geokureli
Geokureli deleted the music-focus branch April 12, 2026 15:12
@ACrazyTown

Copy link
Copy Markdown
Contributor

@Geokureli This is a breaking change. It breaks any project that manually replaces FlxG.sound.music, most notably Funkin'.

From what I've gathered, FlxG.sound.music used to be updated independently of the sound list. If you wanted to replace it with a custom sound you could simply reassign it (and remove it from the sound list, if created via FlxG.sound). (example)

Since it's no longer updated independently, projects that do the aforementioned now have music that doesn't update, which is especially problematic in FNF's case as the sound time no longer updates, and therefore the gameplay gets stuck

@Geokureli

Copy link
Copy Markdown
Member Author

Setting music directly is actually fairly common, I'm surprised I didn't think of that. I may revert this, but first I'll try a new PR that fixes the original issue without adding music to the list, I suppose

@SimonArs

Copy link
Copy Markdown

@Geokureli This is a breaking change. It breaks any project that manually replaces FlxG.sound.music, most notably Funkin'.

From what I've gathered, FlxG.sound.music used to be updated independently of the sound list. If you wanted to replace it with a custom sound you could simply reassign it (and remove it from the sound list, if created via FlxG.sound). (example)

Since it's no longer updated independently, projects that do the aforementioned now have music that doesn't update, which is especially problematic in FNF's case as the sound time no longer updates, and therefore the gameplay gets stuck

Honestly didn't notice any problems with this. At most, music stopped playing after switching state, but this was solved simply by doing music.persist to true

@Geokureli

Copy link
Copy Markdown
Member Author

Honestly didn't notice any problems with this. At most, music stopped playing after switching state, but this was solved simply by doing music.persist to true

Can you share your code for playing music?

@SimonArs

SimonArs commented Jul 18, 2026

Copy link
Copy Markdown

Honestly didn't notice any problems with this. At most, music stopped playing after switching state, but this was solved simply by doing music.persist to true

Can you share your code for playing music?

Sure. I use wrapper around FlxG.sound.playMusic():

public static function mysic(?options:SoundOptions, ?n:String):Null<FlxSound> {
	if (n != null)
		musico = n;

	final o:SoundOptions = options;

	final lib:String = o?.library ?? 'sodaluv';
	final m:Sound = Paths.sound(lib == 'sodaluv' ? 'music/$musico' : musico, lib);
	if (m == null)
		return null;

	final msc:FlxSound = FlxG.sound.playMusic(m, o?.group, o?.volume ?? Fei.prf.musicVol, o?.loop ?? true, o?.onComplete);
	msc.persist = true; //fixes mentioned issue

	if (o?.time != null)
		msc.time = o.time;

	final prox:ProxData = o?.proximity;
	if (prox != null) {
		msc.proximity(prox.x, prox.y, prox.target, prox.radius, prox.pan ?? true);

		if (prox.pitch != null)
			msc.pitch = prox.pitch;
	}

	return msc;
}

@Geokureli

Geokureli commented Jul 19, 2026

Copy link
Copy Markdown
Member Author

Can you share your code for playing music?

Sure. I use wrapper around FlxG.sound.playMusic():

Thanks! It sounds like you're saying that, before this change, playMusic would always persist across state switches, and now it no longer does unless you specifically make it persist, is that correct?

If so, I don't see why that would have changed, and I should look into it.

Edit: I looked into it, it used to set persist to true, so I added that back. Thanks, again!

@SimonArs

Copy link
Copy Markdown

Can you share your code for playing music?

Sure. I use wrapper around FlxG.sound.playMusic():

Thanks! It sounds like you're saying that, before this change, playMusic would always persist across state switches, and now it no longer does unless you specifically make it persist, is that correct?

If so, I don't see why that would have changed, and I should look into it.

Edit: I looked into it, it used to set persist to true, so I added that back. Thanks, again!

Yes, you got it right. I was glad to help with it!

Geokureli added a commit that referenced this pull request Jul 19, 2026
* Revert "Remove redundant music checks in frontend methods (#3586)"

This reverts commit da83ac9.

* remove music from sound list

* add test back

* persist music

* changelog

* test music persist in PR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Music doesn't resume after onFocus in FlxSoundFrontEnd

3 participants