How to use the win32com library to play mp3 files in python

Source: Internet
Author: User
This article mainly introduces how python uses the win32com library to play mp3 files. it involves related techniques for Python to use the win32com library to operate audio files, for more information about how to use the win32com library to play mp3 files, see the example in this article. Share it with you for your reference. The specific implementation method is as follows:

# Python supports COM, if you have the Win32 extensions# check your Python folder eg. D:\Python23\Lib\site-packages\win32com# also http://starship.python.net/crew/mhammond/win32/Downloads.html# this program will play MP3, WMA, MID, WAV files via the WindowsMediaPlayerfrom win32com.client import Dispatchmp = Dispatch("WMPlayer.OCX")# use an mp3 file you have ...#tune = mp.newMedia("C:/Program Files/Common Files/HP/Memories Disc/2.0/audio/Swing.mp3")# or copy one to the working folder ...#tune = mp.newMedia("Bier1.mp3")# you can also play wma files, this cool sound came with XP ...tune = mp.newMedia("C:/WINDOWS/system32/oobe/images/title.wma")mp.currentPlaylist.appendItem(tune)mp.controls.play()# to stop playing useraw_input("Press Enter to stop playing")mp.controls.stop()

I hope this article will help you with Python programming.

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.