Music_Play
Play background music with looping and volume control.
Synopsis
HCHANNEL HGE::Stream_Play(HSTREAM stream, bool loop, int volume = 100);
Parameters
- stream — Handle to a loaded music stream
- loop — true to loop continuously, false to play once
- volume — Volume level (0-100)
Returns
A channel handle (HCHANNEL) for controlling playback, or 0 if playback failed.
Description
Starts playing a music stream that was loaded with Stream_Load. Returns a channel handle that can be used to control volume, pause, or stop the music.
Example
HSTREAM music;
HCHANNEL musicChannel;
void LoadMusic()
{
music = hge->Stream_Load("music/level1.ogg");
}
void StartMusic()
{
// Play looped at 80% volume
musicChannel = hge->Stream_Play(music, true, 80);
}
void StopMusic()
{
hge->Channel_Stop(musicChannel);
}
void SetMusicVolume(int vol)
{
hge->Channel_SetVolume(musicChannel, vol);
}
void FreeMusic()
{
hge->Stream_Free(music);
}
Supported Formats
HGE supports streaming playback of:
- OGG Vorbis (.ogg)
- MP3 (.mp3)
- WAV (.wav)
- Other formats supported by BASS
Channel Control
After starting playback, use channel functions:
// Pause/resume
hge->Channel_Pause(musicChannel);
hge->Channel_Resume(musicChannel);
// Adjust volume (0-100)
hge->Channel_SetVolume(musicChannel, 50);
// Stop playback
hge->Channel_Stop(musicChannel);
// Check if still playing
bool isPlaying = hge->Channel_IsPlaying(musicChannel);
Music vs Sound Effects
- Music (Stream_*) — For long audio files; data is streamed from disk
- Sound Effects (Effect_*) — For short sounds; loaded entirely into memory