Python development simple edition online music player Sample code

Source: Internet
Author: User
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.