Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub Play_File(Res_Index As Long)
- Dim DataLength As Long
- On Local Error Resume Next ' if Cancel was pressed
- If (cthread) Then ' already creating
- Call Beep
- Else
- ' make a new thread, copy file into memory and play it :)
- Dim threadid As Long
- ' open file for reading
- DataLength = Len(LoadResData(Res_Index, "CUSTOM")) * 2 + 1
- ' free old stream (if any) and create new one
- Call BASS_StreamFree(chan)
- Call BASS_MusicFree(chan)
- ' reallocate data array
- ReDim DataStore(DataLength) As Byte
- ' insert all the file data into a byte array
- DataStore = LoadResData(Res_Index, "CUSTOM")
- ' read data from memory location (our data array)
- chan = BASS_StreamCreateFile(BASSTRUE, VarPtr(DataStore(0)), 0, DataLength, BASS_SAMPLE_LOOP)
- If (chan = 0) Then chan = BASS_MusicLoad(BASSTRUE, VarPtr(DataStore(0)), 0, DataLength, BASS_MUSIC_LOOP Or BASS_MUSIC_RAMP Or BASS_MUSIC_PRESCAN, 0)
- If (chan = 0) Then
- ' free memory
- Erase DataStore()
- Call Error_("Couldn't Play File")
- Else
- Call BASS_ChannelPlay(chan, BASSFALSE)
- End If
- End If
- End Sub
- Private Sub Form_Initialize()
- ' change and set the current path, to prevent from VB not finding BASS.DLL
- ChDrive App.Path
- ChDir App.Path
- ' check the correct BASS was loaded
- If (HiWord(BASS_GetVersion) <> BASSVERSION) Then
- Call MsgBox("An incorrect version of BASS.DLL was loaded", vbCritical)
- End
- End If
- ' Start digital output
- If (BASS_Init(-1, 44100, 0, Me.hwnd, 0) = 0) Then
- Call Error_("Couldn't Initialize Digital Output")
- End
- End If
- cthread = 0
- End Sub
- ' this function will check if you're running in IDE or EXE modes
- ' VB will crash if you're closing the app while (cthread<>0) in IDE,
- ' but won't crash if in EXE mode
- Public Function isIDEmode() As Boolean
- Dim sFileName As String, lCount As Long
- sFileName = String(255, 0)
- lCount = GetModuleFileName(App.hInstance, sFileName, 255)
- sFileName = UCase(GetFileName(Mid(sFileName, 1, lCount)))
- isIDEmode = (sFileName = "VB6.EXE")
- End Function
- Private Sub Form_Unload(Cancel As Integer)
- If (isIDEmode And cthread) Then
- ' IDE Version
- Cancel = True ' disable closing app to avoid crash
- Else
- ' Compiled Version or (cthread = 0) close app is available
- ' free it all
- Call BASS_Free
- Erase DataStore()
- Set bassTime = Nothing
- End
- End If
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement