在pcDuino上新研究的一个小应用,装上 doufan.fm播放器。思路来自这篇帖子,在ubuntu下制作doufan.fm播放器,
首先配置自己pcduino的环境:
#sudo apt-get install python-dev
没有播放器的可以先下载一个:
#sudo apt-get install gnome-mplayer
然后运行python代码:
#sudo python test.py
插上USB声卡,接上耳机或音响就可以听歌了。
程序代码:
#!/usr/bin/python# coding: utf-8 import httplib import json import os import sys import subprocess import time reload(sys) sys.setdefaultencoding('utf-8') while True: # 获取播放列表 httpConnection = httplib.HTTPConnection('douban.fm') httpConnection.request('GET', '/j/mine/playlist?type=n&channel=0') song = json.loads(httpConnection.getresponse().read())['song'] # 播放 player = subprocess.Popen(['mplayer', song[0]['url']]) time.sleep(song[0]['length']) player.kill()