# Music Streaming file-backed loops that crossfade and duck under dialogue. ```{raw} html 📄 Docs only ``` **Tags:** `audio` `music` `streaming` `crossfade` `fades` ## What it demonstrates - Two short music loops synthesised at startup and written as WAV files into a temp directory with the stdlib `wave` module. Only file-backed clips can stream (synthetic `AudioClip.tone`/`from_pcm` cannot), so this is the recipe for streaming music without shipping an asset. - `AudioPlayer(stream_mode="streaming", loop=True)`: the file is decoded in chunks each frame instead of being loaded whole, which is the mode for music. - `a.crossfade(b, 2.0)`: one call hands playback over on an equal-power curve, so the pair holds a steady loudness through the middle of the fade. - Ducking under a fake dialogue line with `fade_to(0.25, 0.3)`, then restoring with `fade_to(1.0, 0.5)` once the line ends. - Fades and the streaming feed both tick in `on_update`, so the players must be in the tree; a detached player's fade never advances. ## Controls - `SPACE`: crossfade to the other track (2 s, equal power). - `D`: play a dialogue line: duck the music to a quarter amplitude, restore after. - `ESC`: quit. Run: uv run python examples/features/audio/music.py Headless self-check: uv run python examples/features/audio/music.py --test ## Source ```{literalinclude} ../../examples/features/audio/music.py :language: python :linenos: ```