蝙蝠岛资源网 Design By www.hbtsch.com
本人最近在学习python,在看了一些教程后,用python写了一个简单的云音乐播放器,下面把主要代码贴上来,其中用到了github上他人写的一个汉字转拼音的库,大家可以在github上找到。
#coding=utf-8 from Tkinter import * import tkMessageBox import urllib import json import mp3play import time import threading from pinyin import PinYin import os import stat test = PinYin() test.load_word() stop=0 def music(): if not entry.get(): tkMessageBox.showinfo("温馨提示","搜索内容不能为空") return name = test.hanzi2pinyin_split(entry.get()) html=urllib.urlopen("http://s.music.163.com/search/get/"%name).read() js=json.loads(html) n = 0 global x x = [] for i in js['result']['songs']: listbox.insert(n,'%s(%s)'%(i['name'],i['artists'][0]['name'])) n+=1 x.append(i['audio']) count = 0 #isplaying = None def play(): global count count += 1 index=listbox.curselection() var1.set(u"正在加载"+listbox.get(index,last=None)) urllib.urlretrieve(x[index[0]],'tmp%s.mp3'%str(count)) var1.set(u"正在播放"+listbox.get(index,last=None)) mp3=mp3play.load("tmp%s.mp3"%str(count)) mp3.play() time.sleep(mp3.seconds()) import inspect import ctypes def _async_raise(tid, exctype): """raises the exception, performs cleanup if needed""" tid = ctypes.c_long(tid) if not inspect.isclass(exctype): exctype = type(exctype) res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, ctypes.py_object(exctype)) if res == 0: raise ValueError("invalid thread id") elif res != 1: ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, None) raise SystemError("PyThreadState_SetAsyncExc failed") def stop_thread(thread): _async_raise(thread.ident, SystemExit) threads=list() t=None def excute(event): global t for i in threads: stop_thread(i) t = threading.Thread(target=play) t.setDaemon(True) t.start() threads.append(t) root = Tk()#创建一个窗口 root.title("云音乐") root.geometry("500x300+500+200") entry=Entry(root)#创建输入框(单行),置父 entry.pack() btn=Button(root,text="搜 索",command=music) btn.pack()#布局方式必须用同一种 var=StringVar() listbox=Listbox(root,width=50,listvariable=var) listbox.bind('<Double-Button-1>',excute) listbox.pack() var1=StringVar() label=Label(root,text="云音乐播放器",fg="purple",textvariable=var1) var1.set("云音乐播放器") label.pack() root.mainloop()#显示窗口
由于最近事情较多加上我的技术还不到位,这个播放器有一个BUG我还没有解决,就是在选择播放第二首歌时,第一首歌不会停止。如果有小伙伴解决了这个BUG的话,欢迎指正。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
蝙蝠岛资源网 Design By www.hbtsch.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
蝙蝠岛资源网 Design By www.hbtsch.com
暂无python实现简易云音乐播放器的评论...
更新日志
2025年04月30日
2025年04月30日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]