I'm trying to write a script that plays audio files in background on loop. The audio to play is chosen randomly in a list of audio files.
I tried to do this: http://www.nerdparadise.com/tech/python/pygame/basics/part3/
And wrote:
from tkinter import *
import random
import pygame
_songs = ['audio1.ogg', 'audio2.ogg', 'audio3.ogg']
pygame.mixer.init()
_currently_playing_song = None
SONG_END = pygame.USEREVENT+1
pygame.mixer.music.set_endevent(SONG_END)
next_song = random.choice(_songs)
while next_song == _currently_playing_song:
next_song = random.choice(_songs)
_currently_playing_song = next_song
pygame.mixer.music.load(next_song)
pygame.mixer.music.play()
while True:
for event in pygame.event.get():
if event.type == SONG_END:
pygame.mixer.music.load(next_song)
pygame.mixer.music.play()
tk = Tk()
photo = PhotoImage(file="image.GIF")
image_label=Label(tk, image=photo)
image_label.grid(row=0, column=2)
tk.mainloop()
But I get this error:
for event in pygame.event.get():
pygame.error: video system not initialized
Is there a way to solve this or use pygame using tkinter instead than pygame video system?