Music Player
Introduction
MusicPlayer allows you to seamlessly switch between different BGMs effortlessly. Whenever players enter a new scene or trigger a specific plot point, you can instantly play new music using a new SoundID without needing to know which one was playing before.
The key differences between MusicPlayer and standard players are:
Only one Entity(SoundID) is played at a time (except during transitions).
It automatically transitions from the previous one to the new one, and the previous one will stop after the transition is complete.
How To Use?
For the no-code approach, there is an option in Tools/BroAudio/Preferences named "Always Play Music As BGM". if it's enabled, all entities with audio type: Music will apply this feature with the transition setting specified below.
However, the recommended way is to implement this feature via code for better flexibility and maintainability.
.AsBGM()
Play the music using the basic API, and add .AsBGM() after it, the sound will be played as MusicPlayer.
🔔The sound doesn't have to be a BroAudioType.Music, there is no restriction on this API.
.SetTransition(Transition transition, float fadeTime)
You can specify the transition type and the duration of the transition. If you don't set the fadeTime, the system will use the FadeIn and FadeOut settings of the entity that is defined in LibraryManager; otherwise, these settings will be ignored (or overridden). The types of transitions include:
Default: FadeOut the current one, and then FadeIn the new one.
Immediate: Immediately stop the current one and play the new one without any transition.
OnlyFadeIn: Immediately stop the current one, then FadeIn the new one.
OnlyFadeOut: FadeOut the current one, then immediately play the new one.
CrossFade: Start playing the next one with FadeIn while the previous one begins to FadeOut.
The settings for fadeTime, Transition, and settings of the Entity interact with each other. The rule is:
Unless using Transition.Immediate (ignoring all fadeTime), fadeTime has the highest priority. If it's not set, the system defaults to the Entity's FadeIn/Out settings, followed by the transition mode.
The configurations in the following table all result in the equivalent of Transition.Immediate, meaning there is no transition involved. Hope this can help you understand the relationships.
Last updated