This article describes in detail how to develop a simple version of online music player in python. it has some reference value. if you are interested, you can refer to the online music player, using the python Tkinter library as an interface, I feel that this library is quite convenient to use. The music data comes from an interface of NetEase Cloud Music, through urllib. the urlopen module opens the URL, parses the data using the Json module, and finally uses the mp3play library to play the music online. you can also download mp3 at the same time. The development environment is python2.7. the Source Code is attached as follows:
# _ * _ Coding: UTF-8 _ * _ from Tkinter import * import tkMessageBoximport urllibimport jsonimport mp3play def music (): text = entry. get () text = text. encode ('utf-8') text = urllib. quote (text) if not text: tkMessageBox. showinfo ('tip. 'You can enter the following content for search \ n1. song name \ n2. singer name \ n3. part of the lyrics') return html = urllib. urlopen (' http://s.music.163.com/search/get/?type=1&s=%s&limit=9 '% Text ). read () text = json. loads (html) list_s = text ['result'] ['Songs '] list_url = [] global list_url list_name = [] global list_name listbox. delete (0, listbox. size () for I in list_s: listbox. insert (END, I ['name'] + "(" + I ['artids'] [0] ['name'] + ")") list_url.append (I ['Audio']) list_name.append (I ['name']) def play (event): global mp3 sy = listbox. curselection () [0] mp3 = mp3play. load (list_url [sy]) mp3.play () urllib. urlretrieve (list_url [sy], list_name [sy] + 'users') root = Tk () root. title ("Tkinter Music") root. geometry ('+ 300 + 100') entry = Entry (root) entry. pack () button = Button (root, text = 'search', command = music) button. pack () listbox = Listbox (root, width = 50) listbox. bind ('
', Play) listbox. pack () mainloop ()
The above is all the content of this article. I hope it will help you learn and support PHP.
For more python-developed simple version online music player sample code articles, please follow the PHP Chinese network!