Beispiel #1
0
def rewind():
    '''Restart music.

    Resets playback of the current music to the beginning.
    '''
    mixer._mixer_init_check()
    Mix_RewindMusic()
Beispiel #2
0
def rewind():
    '''Restart music.

    Resets playback of the current music to the beginning.
    '''    
    mixer._mixer_init_check()
    Mix_RewindMusic()
Beispiel #3
0
def unpause():
    '''Resume paused music.

    This will resume the playback of a music stream after it has been paused.
    '''    
    mixer._mixer_init_check()
    Mix_UnpauseMusic()
Beispiel #4
0
def unpause():
    '''Resume paused music.

    This will resume the playback of a music stream after it has been paused.
    '''
    mixer._mixer_init_check()
    Mix_ResumeMusic()
Beispiel #5
0
def queue(filename):
    '''Queue a music file to follow the current one.

    This will load a music file and queue it. A queued music file will begin
    as soon as the current music naturally ends. If the current music is ever
    stopped or changed, the queued song will be lost.

    The following example will play music by Bach six times, then play
    music by Mozart once::

        pygame.mixer.music.load('bach.ogg')
        pygame.mixer.music.play(5)        # Plays six times, not five
        pygame.mixer.music.queue('mozart.ogg')

    :Parameters:
        `filename` : str
            Filename of music file to queue.

    '''
    global _queue_music

    mixer._mixer_init_check()

    music = Mix_LoadMUS(filename)
    _free_loaded(False, True)

    _queue_music = music
Beispiel #6
0
def queue(filename):
    '''Queue a music file to follow the current one.

    This will load a music file and queue it. A queued music file will begin
    as soon as the current music naturally ends. If the current music is ever
    stopped or changed, the queued song will be lost.

    The following example will play music by Bach six times, then play
    music by Mozart once::

        pygame.mixer.music.load('bach.ogg')
        pygame.mixer.music.play(5)        # Plays six times, not five
        pygame.mixer.music.queue('mozart.ogg')
    
    :Parameters:
        `filename` : str
            Filename of music file to queue.

    '''
    global _queue_music

    mixer._mixer_init_check()

    music = Mix_LoadMUS(filename)
    _free_loaded(False, True)

    _queue_music = music
Beispiel #7
0
def pause():
    '''Temporarily stop music playback.

    Temporarily stop playback of the music stream. It can be resumed
    with the `unpause` function.
    '''
    mixer._mixer_init_check()
    Mix_PauseMusic()
Beispiel #8
0
def pause():
    '''Temporarily stop music playback.

    Temporarily stop playback of the music stream. It can be resumed
    with the `unpause` function.
    '''
    mixer._mixer_init_check()
    Mix_PauseMusic()
Beispiel #9
0
def stop():
    '''Stop the music playback.

    Stops the current music if it is playing.  Any queued music will be
    unqueued.
    '''
    mixer._mixer_init_check()
    Mix_HaltMusic()
    _free_loaded(False, True)
Beispiel #10
0
def stop():
    '''Stop the music playback.

    Stops the current music if it is playing.  Any queued music will be
    unqueued.
    '''    
    mixer._mixer_init_check()
    Mix_HaltMusic()
    _free_loaded(False, True)
Beispiel #11
0
def get_busy():
    '''Check if the music stream is playing.

    Returns True when the music stream is actively playing. When the music
    is idle this returns False.

    :rtype: bool
    '''
    mixer._mixer_init_check()
    return Mix_PlayingMusic()
Beispiel #12
0
def get_volume():
    '''Get the music volume.

    Returns the current volume for the mixer. The value will be between 0.0
    and 1.0.

    :rtype: float
    '''
    mixer._mixer_init_check()
    return Mix_VolumeMusic(-1) / 128.0
Beispiel #13
0
def get_volume():
    '''Get the music volume.

    Returns the current volume for the mixer. The value will be between 0.0
    and 1.0.
    
    :rtype: float
    '''
    mixer._mixer_init_check()
    return Mix_VolumeMusic(-1) / 128.0
Beispiel #14
0
def get_busy():
    '''Check if the music stream is playing.

    Returns True when the music stream is actively playing. When the music
    is idle this returns False.
    
    :rtype: bool
    '''
    mixer._mixer_init_check()
    return Mix_PlayingMusic()
Beispiel #15
0
def set_volume(volume):
    '''Set the music volume.

    Set the volume of the music playback. The value argument is between
    0.0 and 1.0. When new music is loaded the volume is reset.

    :Parameters:
        `volume` : float
            Volume of music playback, in range [0.0, 1.0].

    '''
    mixer._mixer_init_check()
    Mix_VolumeMusic(int(volume * 128))
Beispiel #16
0
def set_volume(volume):
    '''Set the music volume.

    Set the volume of the music playback. The value argument is between
    0.0 and 1.0. When new music is loaded the volume is reset.
    
    :Parameters:
        `volume` : float
            Volume of music playback, in range [0.0, 1.0].

    '''
    mixer._mixer_init_check()
    Mix_VolumeMusic(int(volume * 128))
Beispiel #17
0
def fadeout(time):
    '''Stop music playback after fading out.

    This will stop the music playback after it has been faded out over the
    specified time (measured in milliseconds).  Any queued music will be
    unqueued.

    Note, that this function blocks until the music has faded out.
    
    :Parameters:
        `time` : int
            Time to fade out over, in milliseconds.

    '''
    mixer._mixer_init_check()

    Mix_FadeOutMusic(time)
    _free_loaded(False, True)
Beispiel #18
0
def fadeout(time):
    '''Stop music playback after fading out.

    This will stop the music playback after it has been faded out over the
    specified time (measured in milliseconds).  Any queued music will be
    unqueued.

    Note, that this function blocks until the music has faded out.

    :Parameters:
        `time` : int
            Time to fade out over, in milliseconds.

    '''
    mixer._mixer_init_check()

    Mix_FadeOutMusic(time)
    _free_loaded(False, True)
Beispiel #19
0
def play(loops=0, start=0.0):
    '''Start the playback of the music stream.

    This will play the loaded music stream. If the music is already playing it
    will be restarted.

    The `loops` argument controls the number of repeats a music will play.
    play(5) will cause the music to played once, then repeated five times, for
    a total of six. If `loops` is -1 then the music will repeat until stopped.

    The `start` argument controls where in the music the song starts playing.
    The starting position is dependent on the format of music playing.
    MP3 and OGG use the position as time (in seconds). MOD music it is the
    pattern order number. Passing a value to `start` will raise a
    NotImplementedError if it cannot set the start position

    :Parameters:
        `loops` : int
            Number of times to repeat music after initial play through.
        `start` : float
            Starting time within music track to play from, in seconds.

    '''
    global _frequency, _format, _channels

    mixer._mixer_init_check()

    if not _current_music:
        raise base.error, 'music not loaded'

    Mix_HookMusicFinished(_endmusic_callback)
    Mix_SetPostMix(_mixmusic_callback, None)
    ready, _frequency, _format, _channels = Mix_QuerySpec()

    if Mix_Linked_Version().is_since((1, 2, 3)):
        volume = Mix_VolumeMusic(-1)
        Mix_FadeInMusicPos(_current_music, loops, 0, start)
        Mix_VolumeMusic(volume)
    else:
        if start:
            raise NotImplementedError, \
                'music start position requires SDL_Mixer 1.2.3 or later'
        Mix_PlayMusic(_current_music, loops)
Beispiel #20
0
def get_pos():
    '''Get the amount of time music has been playing.

    This gets the number of milliseconds that the music has been playing for.
    The returned time only represents how long the music has been playing; it
    does not take into account any starting position offsets.

    Returns -1 if the position is unknown.

    :rtype: int
    '''
    mixer._mixer_init_check()
    if _pos_time < 0:
        return -1

    ticks = 1000 * _pos / _channels / _frequency / ((_format & 0xff) >> 3)
    if not Mix_PausedMusic():
        ticks += SDL_GetTicks() - _pos_time
    return int(ticks)
Beispiel #21
0
def play(loops=0, start=0.0):
    '''Start the playback of the music stream.

    This will play the loaded music stream. If the music is already playing it
    will be restarted.

    The `loops` argument controls the number of repeats a music will play.
    play(5) will cause the music to played once, then repeated five times, for
    a total of six. If `loops` is -1 then the music will repeat until stopped.

    The `start` argument controls where in the music the song starts playing.
    The starting position is dependent on the format of music playing.
    MP3 and OGG use the position as time (in seconds). MOD music it is the
    pattern order number. Passing a value to `start` will raise a
    NotImplementedError if it cannot set the start position

    :Parameters:
        `loops` : int
            Number of times to repeat music after initial play through.
        `start` : float
            Starting time within music track to play from, in seconds.

    '''    
    global _frequency, _format, _channels

    mixer._mixer_init_check()

    if not _current_music:
        raise base.error, 'music not loaded'

    Mix_HookMusicFinished(_endmusic_callback)
    Mix_SetPostMix(_mixmusic_callback, None)
    ready, _frequency, _format, _channels = Mix_QuerySpec()

    if Mix_Linked_Version().is_since((1, 2, 3)):
        volume = Mix_VolumeMusic(-1)
        Mix_FadeInMusicPos(_current_music, loops, 0, start)
        Mix_VolumeMusic(volume)
    else:
        if start:
            raise NotImplementedError, \
                'music start position requires SDL_Mixer 1.2.3 or later'
        Mix_PlayMusic(_current_music, loops)
Beispiel #22
0
def get_pos():
    '''Get the amount of time music has been playing.

    This gets the number of milliseconds that the music has been playing for.
    The returned time only represents how long the music has been playing; it
    does not take into account any starting position offsets.

    Returns -1 if the position is unknown.
    
    :rtype: int
    '''
    mixer._mixer_init_check()
    if _pos_time < 0:
        return -1

    ticks = 1000 * _pos / _channels / _frequency / ((_format & 0xff) >> 3)
    if not Mix_PausedMusic():
        ticks += SDL_GetTicks() - _pos_time
    return int(ticks)
Beispiel #23
0
def load(filename):
    '''Load a music file for playback.

    This will load a music file and prepare it for playback. If a music stream
    is already playing it will be stopped. This does not start the music
    playing.

    Music can only be loaded from filenames, not python file objects like the
    other pygame loading functions.

    :Parameters:
        `filename` : str
            Filename of music to load.

    '''
    global _current_music
    mixer._mixer_init_check()

    _free_loaded()
    _current_music = Mix_LoadMUS(filename)
Beispiel #24
0
def load(filename):
    '''Load a music file for playback.

    This will load a music file and prepare it for playback. If a music stream
    is already playing it will be stopped. This does not start the music
    playing.

    Music can only be loaded from filenames, not python file objects like the
    other pygame loading functions.
    
    :Parameters:
        `filename` : str
            Filename of music to load.

    '''
    global _current_music
    mixer._mixer_init_check()

    _free_loaded()
    _current_music = Mix_LoadMUS(filename)