BroAudio
Quick StartScripting APIAsset Store
  • Overview
    • Introduction
    • Getting Started
    • Compatibility
  • Core Features
    • Library Manager
      • Create The Library
      • Design The Sound
        • 🔊Volume
        • 🎚️Fading
        • 🔁Looping
        • 🎲Randomization
        • 💪Velocity
        • 🎛️Spatial & Mix
    • Audio Player
      • Music Player
      • Dominator Player
    • Playback Group
    • Audio Effect
    • No-Code Components
      • Sound Source
      • Sound Volume
      • Spectrum Analyzer
    • Addressables
    • Customization
  • Designs
    • Audio Mixer
  • Tools
    • Audio Clip Editor
    • Audio Effect Editor
    • Useful Attrubutes
  • Reference
    • Scripting API
      • Class
        • BroAudio
        • SoundSource
        • BroAdvice
      • Interface
        • IAudioPlayer
        • IMusicPlayer
        • IPlayerEffect
        • IAutoResetWaitable
        • IAudioSourceProxy
      • Struct
        • SoundID
        • Effect
        • Fading
      • Enums
        • BroAudioType
        • EffectType
        • StopMode
        • Transition
        • Ease
    • Unity API Integration
    • Audio Terminology
    • Technical Details
  • Others
    • Release Notes
    • Known Issues
      • Duplicate SoundID Issue
    • Roadmap
    • Support & Contact
Powered by GitBook
On this page
  • Introduction
  • How To Use?
  • .AsBGM()
  • .SetTransition(Transition transition, float fadeTime)
  1. Core Features
  2. Audio Player

Music Player

Last updated 6 days ago

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 without needing to know which one was playing before.

The key differences between MusicPlayer and standard players are:

  1. Only one Entity(SoundID) is played at a time (except during transitions).

  2. 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 under this option.

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.

BroAudio.Play(_id).AsBGM();

🔔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), the argument: 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.

Entity FadeIn
Entity FadeOut
Transition
FadeTime

0

0

Default

Not set

2

2

CrossFade

0

2

2

Immediate

2

0

2

OnlyFadeIn

Not Set

2

0

OnlyFadeOut

NotSet

Page cover image
SoundID