コード例 #1
0
ファイル: mixer_music.py プロジェクト: vavilon/pygame_cffi
def play(loops=0, startpos=0.0):
    """play(loops=0, start=0.0): return None
       Start the playback of the music stream"""
    global _current_music, _music_pos, _music_pos_time, \
           _music_frequency, _music_format, _music_channels
    check_mixer()

    if not _current_music:
        raise SDLError("music not loaded")

    sdl.Mix_HookMusicFinished(_endmusic_callback)
    sdl.Mix_SetPostMix(_mixmusic_callback, ffi.NULL)
    frequency, format, channels = (ffi.new('int*'), ffi.new('uint16_t*'),
                                   ffi.new('int*'))
    sdl.Mix_QuerySpec(frequency, format, channels)
    _music_pos = 0
    _music_pos_time = sdl.SDL_GetTicks()
    _music_frequency = frequency[0]
    _music_format = format[0]
    _music_channels = channels[0]
    volume = sdl.Mix_VolumeMusic(-1)
    val = sdl.Mix_FadeInMusicPos(_current_music, loops, 0, startpos)
    sdl.Mix_VolumeMusic(volume)
    if val == -1:
        raise SDLError.from_sdl_error()
コード例 #2
0
ファイル: mixer_music.py プロジェクト: tazjel/pygame_cffi
def _endmusic_callback():
    global _current_music, _queue_music, _music_pos, _music_pos_time
    if _endmusic_event is not None and sdl.SDL_WasInit(sdl.SDL_INIT_AUDIO):
        event.post(event.Event(_endmusic_event))

    if _queue_music:
        if _current_music:
            sdl.Mix_FreeMusic(_current_music)
        _current_music = _queue_music
        _queue_music = None
        sdl.Mix_HookMusicFinished(_endmusic_callback)
        _music_pos = 0
        sdl.Mix_PlayMusic(_current_music, 0)
    else:
        _music_pos_time = -1
        sdl.Mix_SetPostMix(ffi.NULL, ffi.NULL)
コード例 #3
0
ファイル: mixer_music.py プロジェクト: vavilon/pygame_cffi
def _endmusic_callback():
    global _current_music, _queue_music, _music_pos, _music_pos_time
    if _endmusic_event is not None and sdl.SDL_WasInit(sdl.SDL_INIT_AUDIO):
        # Pygame doesn't do the same checks for this path as in
        # event.post, and people rely on that, so we also duplicate
        # the logic
        event = ffi.new('SDL_Event*')
        event.type = _endmusic_event
        sdl.SDL_PushEvent(event)

    if _queue_music:
        if _current_music:
            sdl.Mix_FreeMusic(_current_music)
        _current_music = _queue_music
        _queue_music = None
        sdl.Mix_HookMusicFinished(_endmusic_callback)
        _music_pos = 0
        sdl.Mix_PlayMusic(_current_music, 0)
    else:
        _music_pos_time = -1
        sdl.Mix_SetPostMix(ffi.NULL, ffi.NULL)