当前位置: 首页>>代码示例>>Python>>正文


Python Sound.stop方法代码示例

本文整理汇总了Python中pygame.mixer.Sound.stop方法的典型用法代码示例。如果您正苦于以下问题:Python Sound.stop方法的具体用法?Python Sound.stop怎么用?Python Sound.stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pygame.mixer.Sound的用法示例。


在下文中一共展示了Sound.stop方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: SoundDecorator

# 需要导入模块: from pygame.mixer import Sound [as 别名]
# 或者: from pygame.mixer.Sound import stop [as 别名]
class SoundDecorator(FrameDecorator):
    def __init__(self, parent_component=NullComponent(), sound_file_path=''):
        self.sound_file_path = sound_file_path
        self.parent = parent_component
        self.sound = Sound(sound_file_path)
        self.start_time = 0

    def get_parent(self):
        return self.parent

    def set_parent(self, new_parent):
        self.parent = new_parent

    def get_landmarks(self):
        self.parent.get_landmarks()

    def get_image(self):
        self.play()
        return self.parent.get_image()

    def play(self):
        if not self.is_playing():
            self.start_time = time()
            self.sound.play()

    def is_playing(self):
        now = time()
        return self.sound.get_length() > now - self.start_time

    def stop(self):
        self.sound.stop()
        self.start_time = 0

    def copy(self):
        return SoundDecorator(parent_component=self.parent.copy(), sound_file_path=self.sound_file_path)
开发者ID:joanaferreira0011,项目名称:ml-in-cv,代码行数:37,代码来源:sounddecorator.py

示例2: __init__

# 需要导入模块: from pygame.mixer import Sound [as 别名]
# 或者: from pygame.mixer.Sound import stop [as 别名]
class Sound:
    """Class wrapping ``pygame.mixer.Sound`` with the ability to enable/disable sound globally

    Use this instead of ``pygame.mixer.Sound``. The interface is fully transparent.
    """
    def __init__(self, source):
        if config.SOUND:
            self.sound = OldSound(source)

    def play(self, loops=0, maxtime=0, fade_ms=0):
        if config.SOUND:
            self.sound.play(loops, maxtime, fade_ms)

    def stop(self):
        if config.SOUND:
            self.sound.stop()

    def fadeout(self, time):
        if config.SOUND:
            self.sound.fadeout(time)

    def set_volume(self, value):
        if config.SOUND:
            self.sound.set_volume(value)

    def get_volume(self):
        if config.SOUND:
            return self.sound.get_volume()

    def get_num_channels(self):
        if config.SOUND:
            return self.sound.get_num_channels()

    def get_length(self):
        if config.SOUND:
            return self.get_length()

    def get_raw(self):
        if config.SOUND:
            return self.sound.get_raw()
开发者ID:pstray,项目名称:rpi_lcars,代码行数:42,代码来源:sound.py

示例3: __init__

# 需要导入模块: from pygame.mixer import Sound [as 别名]
# 或者: from pygame.mixer.Sound import stop [as 别名]

#.........这里部分代码省略.........
        glPushMatrix()

        glRotate(self.angle,0.0,0.0,1.0)
        glRotate(90.0,-1.0,0.0,0.0)

        glCallList(self.model.gl_list)
        glPopMatrix()

    def draw(self):

        glPushMatrix()

        glTranslate(-self.position.x, -self.position.y, 0.0)

        self._draw_sprites()
        self._draw_shader()

        glPopMatrix()

#        _draw_bounding_box(self.bounding_box)

    def _fire(self):
#    angle, position, blaster_color, blaster_list):

        direction=Vector2D(math.sin(math.radians(self.angle)),
                           -math.cos(math.radians(self.angle)))

        self.blaster_list.append(Blaster(self.blaster_color,
                                         self.position+2.001*direction,
                                         direction))

    def update(self,clock):

        seconds_passed=clock.get_time()/1000.0

        self.angle += (self.maximum_roll_rate*
                       self.controls.get_rotate()*
                       seconds_passed)

        if 0 < self.controls.get_throttle():
            if self.plume.is_off():
                self.plume.on()

            self.engine_sound.play()

            self.plume.throttle=self.controls.get_throttle()

            thrust=self.maximum_acceleration*seconds_passed*self.plume.throttle

            accel=Vector2D(math.sin(math.radians(self.angle))*thrust,
                           -math.cos(math.radians(self.angle))*thrust)
            
            self.velocity += accel
            
        elif self.controls.get_throttle() <= 0 and self.plume.is_on():
            self.plume.off()
            self.engine_sound.stop()

        self.velocity += self.gravity*seconds_passed

        speed = self.velocity.length()
 
        if self.maximum_speed < speed:
            self.velocity *= self.maximum_speed/speed

        self.position += self.velocity*seconds_passed

        self.bounding_box.position=self.position
        self.bounding_box.angle=self.angle

        self.bounding_box.update()

        if self.controls.get_beam_activated() and self.beam.is_off():
            tmp_beam_angle = self.controls.get_beam_angle()

            if tmp_beam_angle is None:
                self.beam.angle = self.angle + 90
            else:
                self.beam.angle = math.degrees(tmp_beam_angle)

            self.beam.on()
        elif not self.controls.get_beam_activated():
            self.beam.off()

        if self.controls.fire() or (0 < self.fire_counter < 3) :
            if 0 < self.fire_counter:
                self.blaster_sound.play()
                self._fire()
                self.fire_counter -= 1
        else:
            self.fire_counter=3

        self.beam.update(clock)
        self.plume.update(clock)

        self.plume.angle = self.angle


        if self.beam.is_on() and not self.beam.is_extending():
            self.beam.off()
开发者ID:aukeman,项目名称:pygame_rockets,代码行数:104,代码来源:rocket.py

示例4: Audio

# 需要导入模块: from pygame.mixer import Sound [as 别名]
# 或者: from pygame.mixer.Sound import stop [as 别名]
class Audio(GameChild):

    current_channel = None
    paused = False
    muted = False

    def __init__(self, game):
        GameChild.__init__(self, game)
        self.load_fx()
        self.subscribe_to(self.get_custom_event_id(), self.mute)

    def load_fx(self):
        fx = {}
        if self.get_configuration().has_option("audio", "sfx-path"):
            root = self.get_resource("audio", "sfx-path")
            for name in listdir(root):
                fx[name.split(".")[0]] = Sound(join(root, name))
        self.fx = fx

    def mute(self, event):
        if self.is_command(event, "mute"):
            self.muted = not self.muted
            self.set_volume()

    def set_volume(self):
        volume = int(not self.muted)
        music.set_volume(volume)
        if self.current_channel:
            self.current_channel.set_volume(volume)

    def play_bgm(self, path, stream=False):
        self.stop_current_channel()
        if stream:
            music.load(path)
            music.play(-1)
        else:
            self.current_channel = Sound(path).play(-1)
        self.set_volume()

    def stop_current_channel(self):
        music.stop()
        if self.current_channel:
            self.current_channel.stop()
        self.current_channel = None
        self.paused = False

    def play_fx(self, name):
        if not self.muted:
            self.fx[name].play()

    def pause(self):
        channel = self.current_channel
        paused = self.paused
        if paused:
            music.unpause()
            if channel:
                channel.unpause()
        else:
            music.pause()
            if channel:
                channel.pause()
        self.paused = not paused
开发者ID:ohsqueezy,项目名称:pgfw,代码行数:64,代码来源:Audio.py


注:本文中的pygame.mixer.Sound.stop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。