M
M
MrZed2020-01-03 20:19:53
Python
MrZed, 2020-01-03 20:19:53

Pyglet How to play next audio file?

Hey! Faced a problem with audio playback in pyglet.
Problem: When I downloaded and played the 1st file and after 5 seconds I try to download the 2nd file and play it, nothing comes out!
The code:

import pyglet 
from time import sleep

player = pyglet.media.Player()
Music_Path ="C:\\file.mp3"

file = pyglet.media.load(Music_Path) 
player.queue(file) 

player.play()
sleep(5)
Music_Path2 ="C:\\file2.mp3"
file2 = pyglet.media.load(Music_Path2) 
player.queue(file2) 

player.play()
sleep(6)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MrZed, 2020-01-03
@MrZed

Found a solution!

import pyglet 
from time import sleep

player = pyglet.media.Player()
Music_Path ="C:\\file.mp3"

file = pyglet.media.load(Music_Path) 
player.queue(file) 

player.play()
sleep(5)

player.on_eos() # ВОТ ФУНКЦИЯ ДЛЯ ВОСПРОИЗВЕДЕНИЯ СЛЕДУЮЩИХ ФАЙЛОВ(но точнее я её так использовал)

Music_Path2 ="C:\\file2.mp3"
file2 = pyglet.media.load(Music_Path2) 
player.queue(file2) 

player.play()
sleep(6)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question