国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python使用PyGame播放Midi和Mp3文件的方法

2019-11-25 17:39:45
字體:
來源:轉載
供稿:網友

本文實例講述了python使用PyGame播放Midi和Mp3文件的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:

''' pg_midi_sound101.pyplay midi music files (also mp3 files) using pygametested with Python273/331 and pygame192 by vegaseat'''import pygame as pgdef play_music(music_file):  '''  stream music with mixer.music module in blocking manner  this will stream the sound from disk while playing  '''  clock = pg.time.Clock()  try:    pg.mixer.music.load(music_file)    print("Music file {} loaded!".format(music_file))  except pygame.error:    print("File {} not found! {}".format(music_file, pg.get_error()))    return  pg.mixer.music.play()  # check if playback has finished  while pg.mixer.music.get_busy():    clock.tick(30)# pick a midi or MP3 music file you have in the working folder# or give full pathnamemusic_file = "Latin.mid"#music_file = "Drumtrack.mp3"freq = 44100  # audio CD qualitybitsize = -16  # unsigned 16 bitchannels = 2  # 1 is mono, 2 is stereobuffer = 2048  # number of samples (experiment to get right sound)pg.mixer.init(freq, bitsize, channels, buffer)# optional volume 0 to 1.0pg.mixer.music.set_volume(0.8)try:  play_music(music_file)except KeyboardInterrupt:  # if user hits Ctrl/C then exit  # (works only in console mode)  pg.mixer.music.fadeout(1000)  pg.mixer.music.stop()  raise SystemExit

希望本文所述對大家的Python程序設計有所幫助。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 乃东县| 卫辉市| 长白| 五莲县| 四会市| 阳山县| 循化| 沙洋县| 宜兰市| 阿瓦提县| 朝阳县| 新巴尔虎右旗| 江川县| 清水县| 华容县| 铜鼓县| 平乡县| 高邮市| 嘉峪关市| 红河县| 互助| 耿马| 扬州市| 方山县| 永康市| 获嘉县| 衡东县| 茶陵县| 陆丰市| 宜黄县| 西吉县| 漳州市| 苏尼特右旗| 郓城县| 襄垣县| 樟树市| 建昌县| 卢龙县| 崇文区| 波密县| 河池市|