Tao.Sdl SDK Documentation

SdlMixer.Mix_HookMusic Method 

Hook for a custom music player

[Visual Basic]
Public Shared Sub Mix_HookMusic( _
   ByVal mix_func As MixFunctionDelegate, _
   ByVal arg As IntPtr _
)
[C#]
public static void Mix_HookMusic(
   MixFunctionDelegate mix_func,
   IntPtr arg
);

Parameters

mix_func
Function pointer to a music player mixer function. NULL will stop the use of the music player, returning the mixer to using the internal music players like usual.
arg
This is passed to the mix_func's udata parameter when it is called.

Remarks

This sets up a custom music player function. The function will be called with arg passed into the udata parameter when the mix_func is called. The stream parameter passes in the audio stream buffer to be filled with len bytes of music. The music player will then be called automatically when the mixer needs it. Music playing will start as soon as this is called. All the music playing and stopping functions have no effect on music after this. Pause and resume will work. Using a custom music player and the internal music player is not possible, the custom music player takes priority. To stop the custom music player call Mix_HookMusic(NULL, NULL).

NOTE: NEVER call SDL_Mixer functions, nor SDL_LockAudio, from a callback function.

void Mix_HookMusic(void (*mix_func)(void *udata, Uint8 *stream, int len), void *arg)
            

Example

            // make a music play function
                    // it expects udata to be a pointer to an int
                    void myMusicPlayer(void *udata, Uint8 *stream, int len)
                    {
                        int i, pos=*(int*)udata;
                        // fill buffer with...uh...music...
                        for(i=0; i<len; i++)
                            stream[i]=(i+pos)&ff;
                        // set udata for next time
                        pos+=len;
                        *(int*)udata=pos;
                    }
                    ...
                    // use myMusicPlayer for playing...uh...music
                    int music_pos=0;
                    Mix_HookMusic(myMusicPlayer, &music_pos);
            

See Also

SdlMixer Class | Tao.Sdl Namespace | Mix_SetMusicCMD | Mix_GetMusicHookData