0
0

Hey everyone,

I currently have some MP3s playing, but they start so quick and when I switch to a new song, they just blast out the new song and quit the other one. Could you please share the code to make a song fade out and then fade in to a new one? Following is the current code I have. I was thinking along the lines of adding a FadeSongs sub, which would end the old one and fade into the new one. Also, any way to make this code better would be great!

Thanks!
Dave

[code:5j4el9yx]Option Explicit

Public FModInit As Boolean

Dim songHandle As Long
Dim StreamChannel As Long
Dim streamHandle As Long
Public CurrentSong As Byte

Public Sub PlaySong(Song As String)
If MUSIC_EXT = ".mid" Or MUSIC_EXT = ".midi" Then
Call PlayMidi(Song)
ElseIf MUSIC_EXT = ".mp3" Then
Call PlayMP3(Song)
End If
End Sub

Public Sub PlayMidi(Song As String)

‘Dim i As Long
Dim FilePath As String

If FModInit = False Then Exit Sub

FilePath = App.Path & "\music\" & Song

If Not FileExist(FilePath, True) Then
    MsgBox "Music file " & Song & " doesn't exist"
    Exit Sub
End If

songHandle = FMUSIC_LoadSong(FilePath)
If songHandle <> 0 Then
    'Loading was successful
    If FMUSIC_PlaySong(songHandle) = 0 Then
        'Something went wrong
        MsgBox "An error occured playing the song!" & vbCrLf & _
            FSOUND_GetErrorString(FSOUND_GetError), vbOKOnly
    End If
Else
    'Something went wrong
    MsgBox "An error occured opening the song!" & vbCrLf & _
        FSOUND_GetErrorString(FSOUND_GetError), vbOKOnly
End If

End Sub

Public Sub StopMidi()

If FModInit = False Then Exit Sub

FMUSIC_FreeSong songHandle
songHandle = 0
CurrentSong = 0

End Sub

Public Sub PlayMP3(Song As String)
Dim FilePath As String

If FModInit = False Then Exit Sub

FilePath = App.Path & "\music\" & Song

If Not FileExist(FilePath, True) Then
    MsgBox "Music file " & Song & " doesn't exist"
    Exit Sub
End If

streamHandle = FSOUND_Stream_Open(FilePath, FSOUND_LOOP_NORMAL, 0, 0)
If streamHandle <> 0 Then
    StreamChannel = FSOUND_Stream_Play(FSOUND_FREE, streamHandle)
    If StreamChannel = 0 Then
        'Error occured
        MsgBox "An error occured playing the stream!" & vbCrLf & _
        FSOUND_GetErrorString(FSOUND_GetError), vbOKOnly
    End If
Else
    MsgBox "An error occured opening the stream!" & vbCrLf & _
    FSOUND_GetErrorString(FSOUND_GetError), vbOKOnly
    Exit Sub
End If

End Sub

Public Sub StopMP3()
If FModInit = False Then Exit Sub

FSOUND_Stream_Close streamHandle
streamHandle = 0
CurrentSong = 0
End Sub[/code:5j4el9yx]

  • You must to post comments
0
0

Think a fast fadeout should be enough.

If you need a good crossfade ‘example’, there is a open source VB6 player at http://www.ctuser.net/qplayer . Should be some work to strip it down for your issues, but the overall crossfade time is very accurate (<8ms total delay an my computer if not busy), and if you have questions about it I can help.

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.