def play(self, sound, loops=0, maxtime=-1, fade_ms=0): """play Sound on this channel""" # Note: channelnum will equal self.chan if fade_ms > 0: channelnum = sdl.Mix_FadeInChannelTimed(self.chan, sound.chunk, loops, fade_ms, maxtime) else: channelnum = sdl.Mix_PlayChannelTimed(self.chan, sound.chunk, loops, maxtime) if channelnum != -1: sdl.Mix_GroupChannel(channelnum, sound._chunk_tag) _channeldata[channelnum].sound = sound _channeldata[channelnum].queue = None
def queue(self, sound): """ queue(Sound) -> None queue a Sound object to follow the current """ # if nothing is playing if _channeldata[self.chan].sound is None: channelnum = sdl.Mix_PlayChannelTimed(self.chan, sound.chunk, 0, -1) if channelnum != -1: sdl.Mix_GroupChannel(channelnum, sound._chunk_tag) _channeldata[channelnum].sound = sound # sound is playing, queue new sound else: _channeldata[self.chan].queue = sound
def play(self, loops=0, maxtime=-1, fade_ms=0): """play(loops=0, maxtime=-1, fade_ms=0) -> Channel begin sound playback""" if fade_ms > 0: channelnum = sdl.Mix_FadeInChannelTimed(-1, self.chunk, loops, fade_ms, maxtime) else: channelnum = sdl.Mix_PlayChannelTimed(-1, self.chunk, loops, maxtime) if channelnum < 0: # failure return None _channeldata[channelnum].sound = self _channeldata[channelnum].queue = None sdl.Mix_Volume(channelnum, 128) sdl.Mix_GroupChannel(channelnum, self._chunk_tag) return Channel(channelnum)
def _endsound_callback(channelnum): if not _channeldata: return data = _channeldata[channelnum] # post sound ending event if data.endevent != sdl.SDL_NOEVENT and sdl.SDL_WasInit(sdl.SDL_INIT_VIDEO): event = ffi.new('SDL_Event*') event.type = data.endevent if event.type >= sdl.SDL_USEREVENT and event.type < sdl.SDL_NUMEVENTS: event.user.code = channelnum sdl.SDL_PushEvent(event) if data.queue: sound_chunk = data.sound.chunk data.sound = data.queue data.queue = None channelnum = sdl.Mix_PlayChannelTimed(channelnum, sound_chunk, 0, -1) if channelnum != -1: sdl.Mix_GroupChannel(channelnum, data.sound._chunk_tag) else: data.sound = None