This article mainly introduces the relevant information of Python to implement online music player in detail, which has certain reference value. Interested friends can refer to it
In the past few days, I have learned a lot After learning about Python, I became more interested in crawlers, so I made a simple crawler project. I used the Python library Tkinsert to create an interface. I feel that this library is quite convenient to use. The music data comes from an interface of NetEase Cloud Music, through requests module, get the data through get request, use the Json module to parse the data, and finally use python's mp3play library to play the music online. The following is the source code of the program.
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2016-12-28 21:03:21 # @Author : Donoy (172829352@qq.com) # @Link : http://www.cnblogs.com/Donoy/ # @Version : $Id$ from Tkinter import * import tkMessageBox import requests import json import urllib import mp3play import threading import time def center_window(root, width, height): screenwidth = root.winfo_screenwidth() screenheight = root.winfo_screenheight() size = '%dx%d+%d+%d' % (width, height, (screenwidth - width)/2, (screenheight - height)/2) root.geometry(size) def createWnd(): global root global listBox global text root = Tk() root.title('-----DMPlayer------来自网易云音乐-----') center_window(root, 440, 250) root['background'] = '#C7EDCC' text = Entry(font='宋体',width=36) text.pack() button = Button(root,text='搜索',width=18,fg='red',background='#CDCDC1',command=searchM).pack() listBox = Listbox(root, height=12,width=72,background='#C7EDCC') listBox.bind('<Double-Button-1>',play) listBox.pack() root.mainloop() def searchM(): global m_List itemCount = 50 if not text.get(): tkMessageBox.showinfo('温馨提示','您可以输入以下内容进行搜索\n1.歌曲名\n2.歌手名\n3.部分歌词') return #获得输入的歌名 url = 'http://s.music.163.com/search/get/?type=1&s=%s&limit=%s'%(text.get(),itemCount) #get请求 header = {'User-Agent':'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.75 Safari/537.36'} html = requests.get(url,header) data = json.loads(html.text) m_List = [] try: listBox.delete(0,listBox.size()) for MusicData in data['result']['songs']: listBox.insert(END,MusicData['name'] +'------'+'(' +MusicData['artists'][0]['name'] + ')') m_List.append(MusicData['audio']) except Exception as e: tkMessageBox.showinfo('温馨提示','查询过程出现错误,请重试') #print '查询过程出现错误,请重试' def play(args): try: global mp3 sy = listBox.curselection()[0] mp3 = mp3play.load(m_List[int(sy)]) mp3.play() #time.sleep(1000) except Exception as e: pass def main(): createWnd() if __name__ == '__main__': main()
Program running results:
The above is the entire content of this article, I hope it will help everyone learn It is helpful, and I hope everyone will support the PHP Chinese website.
For more articles related to Python implementation of online music player examples, please pay attention to the PHP Chinese website!

This article explains how to use Beautiful Soup, a Python library, to parse HTML. It details common methods like find(), find_all(), select(), and get_text() for data extraction, handling of diverse HTML structures and errors, and alternatives (Sel

Python's statistics module provides powerful data statistical analysis capabilities to help us quickly understand the overall characteristics of data, such as biostatistics and business analysis. Instead of looking at data points one by one, just look at statistics such as mean or variance to discover trends and features in the original data that may be ignored, and compare large datasets more easily and effectively. This tutorial will explain how to calculate the mean and measure the degree of dispersion of the dataset. Unless otherwise stated, all functions in this module support the calculation of the mean() function instead of simply summing the average. Floating point numbers can also be used. import random import statistics from fracti

Serialization and deserialization of Python objects are key aspects of any non-trivial program. If you save something to a Python file, you do object serialization and deserialization if you read the configuration file, or if you respond to an HTTP request. In a sense, serialization and deserialization are the most boring things in the world. Who cares about all these formats and protocols? You want to persist or stream some Python objects and retrieve them in full at a later time. This is a great way to see the world on a conceptual level. However, on a practical level, the serialization scheme, format or protocol you choose may determine the speed, security, freedom of maintenance status, and other aspects of the program

This article compares TensorFlow and PyTorch for deep learning. It details the steps involved: data preparation, model building, training, evaluation, and deployment. Key differences between the frameworks, particularly regarding computational grap

The article discusses popular Python libraries like NumPy, Pandas, Matplotlib, Scikit-learn, TensorFlow, Django, Flask, and Requests, detailing their uses in scientific computing, data analysis, visualization, machine learning, web development, and H

This article guides Python developers on building command-line interfaces (CLIs). It details using libraries like typer, click, and argparse, emphasizing input/output handling, and promoting user-friendly design patterns for improved CLI usability.

This tutorial builds upon the previous introduction to Beautiful Soup, focusing on DOM manipulation beyond simple tree navigation. We'll explore efficient search methods and techniques for modifying HTML structure. One common DOM search method is ex

The article discusses the role of virtual environments in Python, focusing on managing project dependencies and avoiding conflicts. It details their creation, activation, and benefits in improving project management and reducing dependency issues.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

WebStorm Mac version
Useful JavaScript development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Linux new version
SublimeText3 Linux latest version

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
