安装开发依赖
上述软件只需要两个python包
- pip install python-vlc -i https://pypi.douban.com/simple/
- pip install PySimpleGUI -i https://pypi.douban.com/simple/
大家看到我安装的时候指定了python的pip源,因为不指定报错如下:
然后将下述代码拷贝到本地执行
import PySimpleGUI as sg
import vlc
controls = [sg.Button("Play"), sg.Button("Pause"), sg.Button("Stop")]
layout = [[sg.FileBrowse(key="-MP3-", enable_events=True)], controls]
player = None
# Create the window
window = sg.Window("MP3 Player", layout)
# Create an event loop
while True:
event, values = window.read()
# End program if user closes window or
# presses the OK button
if event == "OK" or event == sg.WIN_CLOSED:
break
if event == "-MP3-":
player = vlc.MediaPlayer(values['-MP3-'])
if event == "Play" and player is not None:
player.play()
if event == "Pause" and player is not None:
player.pause()
if event == "Stop" and player is not None:
player.stop()
window.close()