A simple and fun python music player

Source: Internet
Author: User

(For beginners, the birds bypass 0.0)

Python version: 3.5.2

The source code is as follows:

__Author__ = "Lance#"# -*- coding = utf-8 -*-#导入相应模块from pygame import mixerfrom pynput import keyboardfrom pynput.keyboard import Key#音量初始值(范围是 0~1 )value = 0.5#混音器初始化、加载音乐、播放音乐mixer.init()mixer.music.load("xxx.mp3")mixer.music.play()#设置初始音量mixer.music.set_volume(value)def on_press(key):    global value    if key == Key.left:        #暂停        mixer.music.pause()    elif key == Key.right:        #恢复暂停        mixer.music.unpause()    elif key == Key.up:        if value < 1:            value += 0.1        mixer.music.set_volume(value)    elif key == Key.down:        if value > 0:            value -= 0.1        mixer.music.set_volume(value)#开始监听键盘的动作with keyboard.Listener(on_press=on_press) as listener:    listener.join()while True:    pass

You can control the volume of the song, pause or not, by the left and right arrow keys.

If your environment does not have a module installed by the blogger, you can go to the command line and get the installation through the PIP Install Module name command.

I hope you enjoy your stay ^_^

A simple and fun python music player

Related Article

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.