K
K
Konstantin2020-08-15 17:47:24
Python
Konstantin, 2020-08-15 17:47:24

Audio not playing in tkinter?

from tkinter import *
from tkinter.ttk import *
from tkinter import filedialog as fd
from mutagen.mp3 import MP3
import ntpath
import datetime
import pygame
from pymsgbox import *

def open():
  global fileName, org_timeMinutes, org_timeSeconds
  filePath = fd.askopenfilename()
  fileName = ntpath.basename(filePath)
  root.title("Simple Audio Player: Selected: "+fileName)
  f = MP3(filePath)
  org_timeDuration = datetime.timedelta(seconds=int(f.info.length))
  org_timeMinutes = str(int(org_timeDuration.seconds / 60))
  org_timeSeconds = str(org_timeDuration.seconds - int(org_timeDuration.seconds / 60) * 60)
  print(org_timeMinutes + ":" + org_timeSeconds)

def play():
  root.title("Simple Audio Player: Playing: "+fileName)
  pygame.init()
  pygame.mixer.music.load(filePath)
  pygame.mixer.music.play()

root = Tk()
root.title("Simple Audio Player")
root.geometry("600x350")
root.resizable(False, False)

openButton = Button(text="Open", command=open)
openButton.pack()

playButton = Button(text="Play", command=play)
playButton.pack()

root.mainloop()

I am making my own audio player in python. I ran into a problem that pygame does not find a variable with the path to the audio file. Can you help in any way?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question