I use ctypes to play AUDIO using bass.dll found here:
http://www.un4seen.com/
I have gone so far and tried as they advised me at their forum entry here:
http://www.un4seen.com/forum/?topic=9257.0
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

#import ctypes module
import ctypes as ct
#import OS
import os
#get BOOL C++ value from ctypes
from ctypes.wintypes import BOOL
from ctypes.wintypes import HANDLE
#Loading the DLL see: http://www.daniweb.com/forums/thread160430.html
bass_dll = ct.windll.bass
#initialize the DLL 
# 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). 
#function to intialize the DLL

def onInit_Lib():
    #define arg types
    bass_dll.BASS_Init.argtypes = [ct.c_int, ct.c_int, ct.c_int, ct.c_int, ct.c_int]
    #define result types
    bass_dll.BASS_Init.restype = ct.c_int
    #call function with args
    c= bass_dll.BASS_Init(-1, 44100, 0,0, 0)
    print c

def onStream():
    #arg definitions
    #HSTREAM BASS_StreamCreateFile(BOOL mem, void *file, QWORD offset, QWORD length, DWORD flags);
    bass_dll.BASS_StreamCreateFile.argtypes = [BOOL, ct.c_char_p, ct.c_int , ct.c_int, ct.c_int]
    #defining restypes
    bass_dll.BASS_StreamCreateFile.restype = HANDLE
    path = os.getcwd()
    full = os.path.join(path, "test.mp3")
    print full
    stream = bass_dll.BASS_StreamCreateFile(False, full, 0, 0, 0)
    print stream
    return stream
    
def onPlay(stream):
    #define args
    #BASS_ChannelPlay(stream, FALSE); // play the stream
    bass_dll.BASS_ChannelPlay.argtypes = [HANDLE, BOOL]
    #call function
    bass_dll.BASS_ChannelPlay(stream, False)
    
onInit_Lib()
stream = onStream()
onPlay(stream)

With thanks,

here is modified code that fix the error but no sound

#import ctypes module
import ctypes as ct
#import OS
import os
#get BOOL C++ value from ctypes
from ctypes.wintypes import BOOL
from ctypes.wintypes import HANDLE
#Loading the DLL see: http://www.daniweb.com/forums/thread160430.html
bass_dll = ct.windll.bass
#initialize the DLL 
# 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). 
#function to intialize the DLL

def onInit_Lib():
    #define arg types
    bass_dll.BASS_Init.argtypes = [ct.c_int, ct.c_int, ct.c_int, ct.c_int, ct.c_int]
    #define result types
    bass_dll.BASS_Init.restype = ct.c_int
    #call function with args
    c= bass_dll.BASS_Init(-1, 44100, 0,0, 0)
    print c

def onStream():
    #arg definitions
    #HSTREAM BASS_StreamCreateFile(BOOL mem, void *file, QWORD offset, QWORD length, DWORD flags);
    bass_dll.BASS_StreamCreateFile.argtypes = [BOOL, ct.c_char_p, ct.c_longlong , ct.c_longlong, ct.c_int]
    #defining restypes
    bass_dll.BASS_StreamCreateFile.restype = HANDLE
    path = os.getcwd()
    full = os.path.join(path, "test.mp3")
    print full
    stream = bass_dll.BASS_StreamCreateFile(False, full, 0, 0, 0)
    print stream
    return stream
    
def onPlay(stream):
    #define args
    #BASS_ChannelPlay(stream, FALSE); // play the stream
    bass_dll.BASS_ChannelPlay.argtypes = [HANDLE, BOOL]
    #call function
    bass_dll.BASS_ChannelPlay(stream, False)
    
onInit_Lib()
stream = onStream()
onPlay(stream)

Finally solved. Codes are roughly arranged and are not in order because I was learning the bass.dll & ctypes basics

#Play audio with bass.dll and python ctypes
#Code By Steve
#import ctypes module
import ctypes as ct
#import OS
import os
#get BOOL C++ value from ctypes
from ctypes.wintypes import BOOL
from ctypes.wintypes import HANDLE
#Loading the DLL see: http://www.daniweb.com/forums/thread160430.html
bass_dll = ct.windll.bass
#initialize the DLL 
# 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). 
#function to intialize the DLL

def onInit_Lib():
    #define arg types
    bass_dll.BASS_Init.argtypes = [ct.c_int, ct.c_uint, ct.c_uint, ct.c_uint, ct.c_uint]
    #define result types
    bass_dll.BASS_Init.restype = ct.c_int
    #call function with args
    c= bass_dll.BASS_Init(-1, 44100, 0,0, 0)
    print c

def onStream():
    #arg definitions
    #HSTREAM BASS_StreamCreateFile(BOOL mem, void *file, QWORD offset, QWORD length, DWORD flags);
    bass_dll.BASS_StreamCreateFile.argtypes = [BOOL, ct.c_char_p, ct.c_int64 , ct.c_int64, ct.c_uint]
    #defining restypes
    bass_dll.BASS_StreamCreateFile.restype = ct.c_uint
    path = os.getcwd()
    full = os.path.join(path, "test.mp3")
    print full
    stream = bass_dll.BASS_StreamCreateFile(False, full, 0, 0, 0)
    print stream
    return stream
    
def onPlay(stream):
    #define args
    #BASS_ChannelPlay(stream, FALSE); // play the stream
    bass_dll.BASS_ChannelPlay.argtypes = [ct.c_uint, BOOL]
    #call function
    bass_dll.BASS_ChannelPlay(stream, False)
    
onInit_Lib()
print bass_dll.BASS_ErrorGetCode()
stream = onStream()
print bass_dll.BASS_ErrorGetCode()
onPlay(stream)
print bass_dll.BASS_ErrorGetCode()
while True:
    print "Playing"
This article has been dead for over six months. Start a new discussion instead.