Fade Between Two Music Tracks in-progress in Pygame

前端 未结 4 1041
南方客
南方客 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:37

    Pseudocode:

    track1 = ...
    track2 = ...
    
    track1.play_forever()
    track1.volume = 100
    track2.play_forever()
    track2.volume = 0
    
    playing = track1
    tracks = [track1, track2]
    
    
    def volume_switcher():
        while True:
            playing.volume = min(playing.volume + 1, 100)
    
            for track in tracks:
                if track != playing:
                    track.volume = max(track.volume - 1, 100)
    
            time.sleep(0.1)
    
    Thread(target=volume_switcher).start()
    

提交回复
热议问题