# Sandbox.MusicComponent

Plays background music through [Sandbox.Game.Music](/api/Sandbox.Game.Music). Drop it in, pick a track. Only one track plays
at a time, so enabling another music component crossfades to it. Music isn't tied to the scene - to keep
a track going across scene loads either put this on a DontDestroyOnLoad object or turn off StopOnDisable.

- Kind: class
- Namespace: `Sandbox`
- Assembly: `Sandbox.Engine`
- Inherits: [Sandbox.Component](/api/Sandbox.Component)
- Modifiers: sealed

## Constructors

- [`MusicComponent`](/api/Sandbox.MusicComponent/.ctor)

## Properties

- [`FadeIn`](/api/Sandbox.MusicComponent/FadeIn): Seconds to fade in when starting, and to crossfade from whatever was playing.
- [`FadeOut`](/api/Sandbox.MusicComponent/FadeOut): Seconds to fade out when stopping.
- [`Loop`](/api/Sandbox.MusicComponent/Loop): Start again when the track ends.
- [`PlayOnStart`](/api/Sandbox.MusicComponent/PlayOnStart): Start playing as soon as this component is enabled.
- [`StopOnDisable`](/api/Sandbox.MusicComponent/StopOnDisable): Stop the music when this component is disabled or destroyed, if it's still the track playing. Turn off to let it carry on, e.g. across a scene load.
- [`Track`](/api/Sandbox.MusicComponent/Track): The music to play. Tick Loop in the sound editor for a gapless loop.
- [`Volume`](/api/Sandbox.MusicComponent/Volume): Volume of this track, on top of the game's music volume.

## Methods

- [`Play`](/api/Sandbox.MusicComponent/Play): Play this track, crossfading from whatever is playing.
- [`Stop`](/api/Sandbox.MusicComponent/Stop): Fade out and stop, if this track is the one playing.
