用Python播放音乐

时间:2017-10-02 12:16:29

标签: python subprocess

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

有什么想法吗?

或通过Python在Linux上播放音乐(mp3文件)的任何其他想法

1 个答案:

答案 0 :(得分:0)

我认为您需要为其设置一个变量,否则它将不起作用。尝试这样做:

play = sp.call(["afplay", "music.mp3"])

希望这行得通!