I use bass.dll to play music files from http://www.un4seen.com/
I try to use function called BASS_ChannelSetPosition. I use ctypes to access the Library. Below is the part of documentation (comes with bass as help file)

I need somebody to tell me whether the mode (BASS_POS_BYTE, BASS_MUSIC_POSRESET...etc) is a function or constant, and how do I set it as a flag in function. Below is the actual erroronous code

def onSetPosition(self, handle, position, mode):        
        #QWORD BASS_ChannelSetPosition(DWORD handle, QWORD pos DWORD mode, ); - older version
        bass.BASS_ChannelSetPosition.argtypes = [ct.c_uint, ct.c_int64, ct.c_char_p]  
        bass.BASS_ChannelSetPosition.restype = BOOL
        successful2 = bass.BASS_ChannelSetPosition(handle, position, mode)
        error = bass.BASS_ErrorGetCode()# don't worry, this is for debugging purposes only
        successful = (successful2, error)# don't worry, this is for debugging purposes only
        return successful # don't worry, this is for debugging purposes only

Sets the playback position of a sample, MOD music, or stream.

BOOL BASS_ChannelSetPosition(
DWORD handle,
QWORD pos,
DWORD mode
);


Parameters
handle The channel handle... a HCHANNEL, HSTREAM or HMUSIC.
pos The position, in units determined by the mode.
mode How to set the position. One of the following, with optional flags.
BASS_POS_BYTE The position is in bytes, which will be rounded down to the nearest sample boundary.
BASS_POS_MUSIC_ORDER The position is in orders and rows... use MAKELONG(order,row). (HMUSIC only)
BASS_MUSIC_POSRESET Flag: Stop all notes. This flag is applied automatically if it has been set on the channel, eg. via BASS_ChannelFlags. (HMUSIC)
BASS_MUSIC_POSRESETEX Flag: Stop all notes and reset bpm/etc. This flag is applied automatically if it has been set on the channel, eg. via BASS_ChannelFlags. (HMUSIC)
other modes & flags may be supported by add-ons, see the documentation.

Return value
If successful, then TRUE is returned, else FALSE is returned. Use BASS_ErrorGetCode to get the error code.

Error codes
BASS_ERROR_HANDLE handle is not a valid channel.
BASS_ERROR_NOTFILE The stream is not a file stream.
BASS_ERROR_POSITION The requested position is invalid, eg. it is beyond the end or the download has not yet reached it.
BASS_ERROR_NOTAVAIL The requested mode is not available. Invalid flags are ignored and do not result in this error.
BASS_ERROR_UNKNOWN Some other mystery problem!

Here are some helpful function (All are working)

#Create Stream
    def onStream(self, path): 
        #Initialize device by calling init methods
        self.onInitLib()   
        #arg definitions
        #HSTREAM BASS_StreamCreateFile(BOOL mem, void *file, QWORD offset, QWORD length, DWORD flags);
        bass.BASS_StreamCreateFile.argtypes = [BOOL, ct.c_char_p, ct.c_int64 , ct.c_int64, ct.c_uint]
        #defining restypes
        bass.BASS_StreamCreateFile.restype = ct.c_uint        
        print path
        stream = bass.BASS_StreamCreateFile(False, path, 0, 0, 0)
        self.stream = stream
        #check if the loop option is checked       
        return self.stream
    
    #Play File
    def onPlayStream(self, stream):
        #define args
        #BASS_ChannelPlay(stream, FALSE); // play the stream
        bass.BASS_ChannelPlay.argtypes = [ct.c_uint, BOOL]
        #call function
        bass.BASS_ChannelPlay(stream, False)
    
    #free the stream    
    def onFreeStream(self, stream):
        bass.BASS_StreamFree(stream) 

    def onInitLib(self):        
        #define arg types
        #BOOL BASS_Init(int device, DWORD freq, DWORD flags, HWND win, GUID *clsid );
        bass.BASS_Init.argtypes = [ct.c_int, ct.c_uint, ct.c_uint, ct.c_uint, ct.c_uint]
        #define result types
        bass.BASS_Init.restype = ct.c_int
        #call function with args
        c= bass.BASS_Init(-1, 44100, 0,0, 0)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.