import subprocess as sp
sp.call("afplay","music.mp3")
这是我在Python中播放音乐的代码,但它给了我下面的错误。
TypeError Traceback (most recent call last)
<ipython-input-18-a28808f89c81> in <module>()
1 import subprocess as sp
----> 2 sp.call("afplay","3peg")
/home/pir4t3/anaconda2/lib/python2.7/subprocess.pyc in call(*popenargs, **kwargs)
166 retcode = call(["ls", "-l"])
167 """
--> 168 return Popen(*popenargs, **kwargs).wait()
169
170
/home/pir4t3/anaconda2/lib/python2.7/subprocess.pyc in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags)
337
338 if not isinstance(bufsize, (int, long)):
--> 339 raise TypeError("bufsize must be an integer")
340
341 if mswindows:
TypeError: bufsize must be an integer
任何想法?
或任何其他想法,在Linux上用Python播放音乐(mp3文件)
我想你需要为它设置一个变量,否则它就不会工作。试试这样做。
play = sp.call(["afplay", "music.mp3"])
希望这能行!