Bass Lib right way to play music and sound

Started by ron77_db, Apr 01, 2022, 08:20 AM

Previous topic - Next topic

ron77_db

hello here is a small example of how to use correctly Bass library to play sound and music files (Wav mp3 Ogg files)

#include Once "bass.bi"

'' this mod file should be available in the fbc package:
dim as string SOUND_FILE = "goodbye.ogg"

If (BASS_GetVersion() < MAKELONG(2,2)) Then
    Print "BASS version 2.2 or above required!"
    End 1
End If

If (BASS_Init(-1, 44100, 0, 0, 0) = 0) Then
    Print "Could not initialize BASS"
    End 1
End If

Dim As HMUSIC test = BASS_StreamCreateFile(0, strptr(SOUND_FILE), 0, 0, BASS_MUSIC_LOOP)
If (test = 0) Then
    Print "BASS could not load '" & SOUND_FILE & "'"
    BASS_Free()
    End 1
End If

BASS_ChannelPlay(test, 0)

Print "Sound playing; waiting to keypress to stop and exit..."
Sleep

BASS_ChannelStop(test)
BASS_MusicFree(test)
BASS_Stop()
BASS_Free()