[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.5.8 Mix_HookMusic

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

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.

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.

 
// 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:
4.5.14 Mix_SetMusicCMD, 4.5.22 Mix_GetMusicHookData



This document was generated on November, 13 2009 using texi2html