Advertisement
meanhacker

Sub Play_File(Res_Index As Long)

Mar 12th, 2011
739
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub Play_File(Res_Index As Long)
  2.     Dim DataLength As Long
  3.    
  4.     On Local Error Resume Next          ' if Cancel was pressed
  5.  
  6.     If (cthread) Then   ' already creating
  7.        Call Beep
  8.     Else
  9.  
  10.         ' make a new thread, copy file into memory and play it :)
  11.        Dim threadid As Long
  12.  
  13.         ' open file for reading
  14.        DataLength = Len(LoadResData(Res_Index, "CUSTOM")) * 2 + 1
  15.         ' free old stream (if any) and create new one
  16.        Call BASS_StreamFree(chan)
  17.         Call BASS_MusicFree(chan)
  18.  
  19.         ' reallocate data array
  20.        ReDim DataStore(DataLength) As Byte
  21.  
  22.         ' insert all the file data into a byte array
  23.  
  24.         DataStore = LoadResData(Res_Index, "CUSTOM")
  25.        
  26.         ' read data from memory location (our data array)
  27.        chan = BASS_StreamCreateFile(BASSTRUE, VarPtr(DataStore(0)), 0, DataLength, BASS_SAMPLE_LOOP)
  28.         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)
  29.  
  30.         If (chan = 0) Then
  31.             ' free memory
  32.            Erase DataStore()
  33.  
  34.             Call Error_("Couldn't Play File")
  35.         Else
  36.             Call BASS_ChannelPlay(chan, BASSFALSE)
  37.            
  38.         End If
  39.        
  40.     End If
  41.  
  42. End Sub
  43.  
  44. Private Sub Form_Initialize()
  45.     ' change and set the current path, to prevent from VB not finding BASS.DLL
  46.    ChDrive App.Path
  47.     ChDir App.Path
  48.  
  49.     ' check the correct BASS was loaded
  50.    If (HiWord(BASS_GetVersion) <> BASSVERSION) Then
  51.         Call MsgBox("An incorrect version of BASS.DLL was loaded", vbCritical)
  52.         End
  53.     End If
  54.  
  55.     ' Start digital output
  56.    If (BASS_Init(-1, 44100, 0, Me.hwnd, 0) = 0) Then
  57.         Call Error_("Couldn't Initialize Digital Output")
  58.         End
  59.     End If
  60.  
  61.  
  62.     cthread = 0
  63. End Sub
  64.  
  65. ' this function will check if you're running in IDE or EXE modes
  66. ' VB will crash if you're closing the app while (cthread<>0) in IDE,
  67. ' but won't crash if in EXE mode
  68. Public Function isIDEmode() As Boolean
  69.     Dim sFileName As String, lCount As Long
  70.  
  71.     sFileName = String(255, 0)
  72.     lCount = GetModuleFileName(App.hInstance, sFileName, 255)
  73.     sFileName = UCase(GetFileName(Mid(sFileName, 1, lCount)))
  74.  
  75.     isIDEmode = (sFileName = "VB6.EXE")
  76. End Function
  77.  
  78. Private Sub Form_Unload(Cancel As Integer)
  79.     If (isIDEmode And cthread) Then
  80.         ' IDE Version
  81.        Cancel = True   ' disable closing app to avoid crash
  82.    Else
  83.         ' Compiled Version or (cthread = 0) close app is available
  84.        ' free it all
  85.        Call BASS_Free
  86.         Erase DataStore()
  87.         Set bassTime = Nothing
  88.         End
  89.     End If
  90. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement