It's cool! Python uses 37 lines of code to create its own music player, attached to the source

Source: Internet
Author: User

Want to manually create a player that belongs to you, while practicing Python programming?

If you want, then act now!

Required libraries
Pygame
Tkinter
Mutagen

As for their use, you can browse through the documentation, if you want to do a more powerful player, then you must take a good look at Oh!

Design ideas
As version 0, we do not want to do too complex projects. Here are just a few features:

To display the MP3 file name in a directory in a ListBox

Displays the name of the currently playing song

Play a previous song

Play the next song

Stop playing

Get the MP3 file under the directory
Directly on the code!

Def directorychooser ():
directory = Tkinter.filedialog.askdirectory ()
Os.chdir (directory)
For files in Os.listdir (directory):
If Files.endswith ('. mp3 '):
Realdir = Os.path.realpath (Files)
Audio = ID3 (Realdir)
Realnames.append (audio[' TIT2 '].text[0])
Listofsongs.append (Files)

Print (Files)
pygame.mixer.init()pygame.mixer.music.load(listofsongs[0])pygame.mixer.music.play()

button-related functions
def nextsong (event):
Global index
If index < Len (listofsongs)-1:
Index + = 1
Else
index = 0;
Pygame.mixer.music.load (Listofsongs[index])
Pygame.mixer.music.play ()
Updatelabel ()
def previoussong (event):
Global index
If index > 0:
Index-= 1
Else
index = Len (listofsongs)-1
Pygame.mixer.music.load (Listofsongs[index])
Pygame.mixer.music.play ()
Updatelabel ()
def stopsong (event):
Pygame.mixer.music.stop ()
V.set ("")
Update the currently playing song name

Def Updatelabel ():
Global index
V.set (Realnames[index])

Small series have their own Python learning Exchange group, if you want to learn, you can add: 588+090+942 Whether you are small white or Daniel, small parts are welcome, and small series in the group will not regularly share dry goods, including a small series of their own finishing a 2018 of the latest learning materials and 0 Basic introductory tutorial , Welcome to beginner and advanced in the small partners

It's cool! Python uses 37 lines of code to create its own music player, attached to the source

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.