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


Python Sound.get_length方法代码示例

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


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

示例1: SoundDecorator

# 需要导入模块: from pygame.mixer import Sound [as 别名]
# 或者: from pygame.mixer.Sound import get_length [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: thunder

# 需要导入模块: from pygame.mixer import Sound [as 别名]
# 或者: from pygame.mixer.Sound import get_length [as 别名]
    def thunder(self, inc):
        wait = random.randint(0, 2+inc)

        while (self._last == wait):
            wait = random.randint(0, 2+inc)

        self._last = wait
        print "intensity:", wait
        thunder = Sound("%s/thunder_0%d.wav" % (self._data_folder, wait))
        if wait < 6:
            self.lightning.set_C(ON)
            self.lightning.send()
            time.sleep(random.uniform(0.5, 1.5))
            self.lightning.set_C(OFF)
            self.lightning.send()
            time.sleep(wait)

        if wait < 6:
            self.lightning.set_B(OFF)
            self.lightning.send()
        thunder.play()
        if wait < 6:
            time.sleep(0.3)
            self.lightning.set_B(ON)
            self.lightning.send()
        time.sleep(thunder.get_length()-0.3)
        thunder.fadeout(200)
        time.sleep(wait)
开发者ID:aleneum,项目名称:python-multimedia-authoring,代码行数:30,代码来源:main.py

示例3: IntroAnimator

# 需要导入模块: from pygame.mixer import Sound [as 别名]
# 或者: from pygame.mixer.Sound import get_length [as 别名]
class IntroAnimator(object):
    """This class is in charge of animating the Title Screen's
    introductory animation.

    Attributes:
        is_running: A Boolean indicating whether the animation is
            currently being shown.
        voice: A PyGame Sound with the announcer stating the game's
            title.
        voice_timer: An integer counter that keeps track of how many
            update cycles have passed since the voice clip started
            playing.
        voice_has_played: A Boolean indicating whether the voice clip
            has already played.
        voice_duration: An integer for the duration of the voice clip,
            in update cycles.
    """
    def __init__(self):
        """Declare and initialize instance variables."""
        self.is_running = False
        self.voice = Sound(VOICE_PATH)
        self.voice_duration = (self.voice.get_length() * FRAME_RATE)
        self.voice_timer = 0
        self.voice_has_played = False

    def update(self, time, bg, logo, sound_channel):
        """Update the animation's processes.

        The animation will proceed as follows:
            1. Scroll the background up from the bottom edge until it
               fills the screen.
            2. Fade in the logo.
            3. As it fades in, play the voice clip.
            4. Once the voice clip finishes, play the title theme and
               activate the logo's animation.

        Args:
            time: A float for the time elapsed, in seconds, since the
                last update cycle.
            bg: The Title Screen's background Animation.
            logo: The game logo Animation.
            sound_channel: The PyGame Channel that will be used to
                play the announcer's voice.
        """
        if bg.exact_pos[1] > 0.0:
            self.move_background_up(bg, time)
        elif logo.image.get_alpha() < 255:
            self.fade_in_logo(logo)

        if (logo.image.get_alpha() >= FADE_DELAY
                and (not self.voice_has_played)):
            sound_channel.play(self.voice)
            self.voice_has_played = True
        elif (self.voice_has_played and
              self.voice_timer < self.voice_duration):
            self.voice_timer += 1
        elif self.voice_timer >= self.voice_duration:
            pygame.mixer.music.play(-1)
            logo.is_animated = True
            self.is_running = False

    def move_background_up(self, bg, time):
        """Move the background up at a set speed.

        The background will not move past the top edge of the screen.

        Args:
            bg: The Title Screen's background Animation.
            time: A float for the amount of time, in seconds, elapsed
                since the last update cycle.
        """
        distance = -1 * BG_SCROLL_SPEED * time
        bg.move(0, distance)

        if bg.exact_pos[1] < 0.0:
            distance = 0.0 - bg.exact_pos[1]
            bg.move(0, distance)

    def fade_in_logo(self, logo):
        """Gradually increase the opacity of the game logo.

        Args:
            logo: The game logo Animation.
        """
        old_alpha = logo.image.get_alpha()
        logo.image.set_alpha(old_alpha + FADE_LOGO_RATE)

    def skip_intro(self, bg, logo, sound_channel):
        """Skip to the end of animation immediately.

        Args:
            bg: The Title Screen's background Animation.
            logo: The game logo Animation.
            sound_channel: The PyGame Channel that will be used to
                play the announcer's voice.
        """
        if not self.voice_has_played:
            sound_channel.play(self.voice)

        bg.move(0, -1 * bg.rect[1])
#.........这里部分代码省略.........
开发者ID:MarquisLP,项目名称:Sidewalk-Champion,代码行数:103,代码来源:title_state.py


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