Skip to content

Commit

Permalink
Simplify channel
Browse files Browse the repository at this point in the history
  • Loading branch information
kinuax committed May 11, 2024
1 parent 1c12531 commit ef87dab
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions rolabesti/views/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ def pipes():
import pygame


pygame.mixer.init()
channels = [pygame.mixer.Channel(0), pygame.mixer.Channel(1)]


def play_mp3(trackpath: Path, channel: int) -> None:
"""Play the track located at trackpath on the given channel."""
pygame.mixer.init()
channel = pygame.mixer.Channel(channel)
# Avoid messages from C libraries.
with pipes():
try:
Expand All @@ -34,4 +32,4 @@ def play_mp3(trackpath: Path, channel: int) -> None:
with tempfile.TemporaryFile() as wav_file:
AudioSegment.from_mp3(trackpath).export(wav_file, format="wav")
sound = pygame.mixer.Sound(wav_file)
channels[channel].play(sound)
channel.play(sound)

0 comments on commit ef87dab

Please sign in to comment.