mac上二三行代码用python 3播放mp3文件

in note-timknip •  4 years ago 
  1. 先安装个库和它的依赖项:
    pip3 install playsound PyObjC

  2. 引用这个库后直接播放 playsound.py

>import playsound
>playsound.playsound("./bensound-summer.mp3")

bensound-summer.mp3 放在playsound.py同一目录下。 如果需要后台播放改成下面的参数

import playsound
import time

playsound.playsound("./bensound-summer.mp3",False)
print("play the music for 5 minutes")
time.sleep(300)

---参考文档
[1].Import Error: No module named AppKit. https://stackoverflow.com/questions/12767669/import-error-no-module-named-appkit

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!