我只想在我的树莓派上构建一个小型的python音乐客户端。我安装了“mpg321”,它工作的很好,但现在我的问题。发送命令后在python中发送关于子进程的命令
os.system("mpg321 -R testPlayer")
python等待用户输入,如播放,暂停或退出。如果我在终端上写下此消息,播放器会暂停音乐或退出。完美,但我想python做到这一点,所以我发送命令
os.system("LOAD test.mp3")
其中LOAD是加载此mp3的命令。但没有任何反应。当我退出终端通过播放器我得到的错误:
sh: 1: LOAD: not found
我认为这意味着
os.system("mpg321 -R testPlayer")
发生的全过程后,我放弃它的Python尝试执行LOAD comman。那么我怎么才能让这些东西一起工作呢?
我的代码:
import os
class PyMusic:
def __init__(self):
print "initial stuff later"
def playFile(self, fileName, directory = ""):
os.system("mpg321 -R testPlayer")
os.system("LOAD test.mp3")
if __name__ == "__main__":
pymusic = PyMusic()
pymusic.playFile("test.mp3")
感谢您的帮助!
+1完整性:) –
谢谢你的完美!也感谢您的提示和信息! – emha