Fade Between Two Music Tracks in-progress in Pygame

前端 未结 4 1044
南方客
南方客 2020-12-31 11:50

My intention is to have two music tracks, which are similar in nature, fade between each other at various times. When such a fade occurs,

4条回答
  •  渐次进展
    2020-12-31 12:35

    This isn't exactly an answer to the question, but for future-googlers I wrote a script to fade-in my music from volume 0 in the morning and this is what I used:

    max_volume = 40 
    current_volume = 0
    
    # set the volume to the given percent using amixer
    def set_volume_to(percent):
        subprocess.call(["amixer", "-D", "pulse", "sset", "Master", 
                         str(percent) + "%", "stdout=devnull"])
    
    # play the song and fade in the song to the max_volume 
    def play_song(song_file):
        global current_volume
        print("Song starting: " + song_file)
        pygame.mixer.music.load(song_file)
        pygame.mixer.music.play()
    
        # gradually increase volume to max
        while pygame.mixer.music.get_busy():
            if current_volume < max_volume: 
                set_volume_to(current_volume)
                current_volume += 1
    
            pygame.time.Clock().tick(1)
    
     play_song("foo.mp3")
    

提交回复
热议问题