派格勒:和#x27;str';对象没有属性';音频格式';(python)

派格勒:和#x27;str';对象没有属性';音频格式';(python),python,multithreading,audio,pyglet,Python,Multithreading,Audio,Pyglet,我试图在pyglet中播放通过“打开文件”对话框选择的文件中的Mp3文件,但即使该文件以.Mp3扩展名结尾,我仍然收到错误: Exception in thread Thread-1: Traceback (most recent call last): File "C:\Python34\lib\threading.py", line 921, in _bootstrap_inner self.run() File "C:\Python34\lib\threading.py",

我试图在pyglet中播放通过“打开文件”对话框选择的文件中的Mp3文件,但即使该文件以.Mp3扩展名结尾,我仍然收到错误:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "C:\Python34\lib\threading.py", line 921, in _bootstrap_inner
    self.run()
  File "C:\Python34\lib\threading.py", line 869, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Python34\MP2.py", line 44, in real_playMusic
    player.queue(f)
  File "C:\Python34\lib\site-packages\pyglet-1.2.3a1-py3.4.egg\pyglet\media\__init__.py", line 977, in queue
    group = SourceGroup(source.audio_format, source.video_format)
AttributeError: 'str' object has no attribute 'audio_format'
我想知道如何克服这个错误,并能够有文件读取和播放

代码:

from tkinter import *
from tkinter.filedialog import askopenfilename
import pyglet
import pyglet.media as media
from threading import Thread

app = Tk()
app.title("Music Player")
app.geometry("600x200")
have_avbin = True 

f='' #intialize variable

def openFile():
    global f
    f =  filedialog.askopenfilename(filetypes = (("Mp3 files", "*.mp3"),("Wav files", "*.wav"),("All files","*.*")))




#Creates menu bar for opening MP3s, and closing the program
menu = Menu(app)
file = Menu(menu)
file.add_command(label='Open', command=  openFile) # replace 'print' with the name of your open function
file.add_command(label='Exit', command=app.destroy) # closes the tkinter window, ending the app
menu.add_cascade(label='File', menu=file)
app.config(menu=menu)

#Run each app library mainloop in different python thread to prevent freezing
def playMusic():
    global player_thread
    player_thread = Thread(target=real_playMusic)
    player_thread.start()

def stopMusic():
    global player_thread
    player_thread = Thread(target=real_stopMusic)
    player_thread.start()

#Play open file function attached to button
def real_playMusic():
    src=pyglet.media.load(f, streaming=False)
    player = pyglet.media.Player();
    player.queue(f)
    player.play()
    pyglet.app.run()

#Stop the music function
def real_stopMusic():
     pyglet.app.event_loop.stop()




#Play button creation
btnPlay = Button(app, text ="Play", command = playMusic)
btnPlay.grid(row =10, column = 0)


#Pause button creation
btnPause = Button(app)
btnPause.grid()
btnPause.configure(text = "Stop", command = stopMusic)



app.mainloop() # keep at the end
这应该起作用:

player.queue(src)