By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,551 Members | 1,142 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,551 IT Pros & Developers. It's quick & easy.

Help with this code

P: 28
I use ctypes to play AUDIO using bass.dll found here:
Un4seen Developments - 2MIDI / BASS / MID2XM / MO3 / XM-EXE / XMPlay
I have gone so far and tried as they advised me at their forum entry here:
New Python Developer with Bass
But I still get errors. Can anyone take code and analyze to point out source of error?
Here is the code, pse ignore any useless comment, I was using the editor as scratch pad too :D
Expand|Select|Wrap|Line Numbers
  1. #import ctypes module
  2. import ctypes as ct
  3. #import OS
  4. import os
  5. #get BOOL C++ value from ctypes
  6. from ctypes.wintypes import BOOL
  7. from ctypes.wintypes import HANDLE
  8. #Loading the DLL see: http://www.daniweb.com/forums/thread160430.html
  9. bass_dll = ct.windll.bass
  10. #initialize the DLL 
  11. # sample I got somehwere: BASS_Init(-1,44100,0,win,NULL) win The application's main window... 0 = the current foreground window (use this for console applications). 
  12. #function to intialize the DLL
  13.  
  14. def onInit_Lib():
  15.     #define arg types
  16.     bass_dll.BASS_Init.argtypes = [ct.c_int, ct.c_int, ct.c_int, ct.c_int, ct.c_int]
  17.     #define result types
  18.     bass_dll.BASS_Init.restype = ct.c_int
  19.     #call function with args
  20.     c= bass_dll.BASS_Init(-1, 44100, 0,0, 0)
  21.     print c
  22.  
  23. def onStream():
  24.     #arg definitions
  25.     #HSTREAM BASS_StreamCreateFile(BOOL mem, void *file, QWORD offset, QWORD length, DWORD flags);
  26.     bass_dll.BASS_StreamCreateFile.argtypes = [BOOL, ct.c_char_p, ct.c_int , ct.c_int, ct.c_int]
  27.     #defining restypes
  28.     bass_dll.BASS_StreamCreateFile.restype = HANDLE
  29.     path = os.getcwd()
  30.     full = os.path.join(path, "test.mp3")
  31.     print full
  32.     stream = bass_dll.BASS_StreamCreateFile(False, full, 0, 0, 0)
  33.     print stream
  34.     return stream
  35.  
  36. def onPlay(stream):
  37.     #define args
  38.     #BASS_ChannelPlay(stream, FALSE); // play the stream
  39.     bass_dll.BASS_ChannelPlay.argtypes = [HANDLE, BOOL]
  40.     #call function
  41.     bass_dll.BASS_ChannelPlay(stream, False)
  42.  
  43. onInit_Lib()
  44. stream = onStream()
  45. onPlay(stream)
  46.  
With thanks,
Dec 18 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.