我正在制作媒体播放器,我想有一种打开声音文件的方法。我似乎找不到一种以我想要的方式播放声音的方法。我希望声音只在后台播放,而不是在Groove Music或任何其他第三方应用程序的新窗口中播放。大多数模块不适用于.mp3,.wav和.ogg文件。此外,我想将按键设置为如果我按该按键,声音会停止播放。
我尝试了许多不同的模块:
我得到一个烦人的弹出窗口,该弹出窗口给出了该版本,并显示消息“ pygame社区https://www.pygame.org/contribute.html向您问好”。而且,声音只播放大约一秒钟,而不是持续整个时间
这会在Groove Music中打开文件,我不想,我只希望文件在后台运行。
仅支持.wav文件,不支持.mp3文件。准系统,功能有限
我收到错误消息:“找不到模块'avutil-56'。尝试使用具有构造函数语法的完整路径。”
不支持.mp3或.wav以外的许多其他文件类型。
给我一个错误,提示它找不到文件“ libvlc.dll”
os.startfile()和os.system()无效或打开了第三方应用程序来播放声音。
from playsound import playsound
import ctypes
import time
import turtle
import os
import tkinter as tk
from tkinter import filedialog
import pyglet
#changes title of window
ctypes.windll.kernel32.SetConsoleTitleW("Media Player")
def func_path():
#brings up open file dialog
print("Locate your file.")
root = tk.Tk()
root.withdraw()
file_path = filedialog.askopenfilename()
confirm_path = input("is this the correct path? (y/n)" + file_path + ">>>")
#if the path is confirmed, play the file
if confirm_path == "y":
#opens volume mixer
os.startfile("vol.lnk")
#i want to play sound on this line.
#i want to have a way to make it so that during the sound playing, if i hit a key it will pause the sound, and if i press the key again, it will resume playing.
player_prompt = input("""Welcome to Media Player.
Please select one of the options below.
play a song
>>>""")
while player_prompt != "play a song":
invalid_input_prompt = input("Invalid Command. Please enter a valid command.")
if invalid_input_prompt == "play a song":
break
func_path()