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

首頁 > 編程 > Python > 正文

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

2020-02-23 00:51:47
字體:
來源:轉載
供稿:網友

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

''' 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程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 集安市| 彩票| 高陵县| 朔州市| 静安区| 襄樊市| 钦州市| 闽侯县| 安国市| 资兴市| 嵊泗县| 尼木县| 通化市| 弋阳县| 白玉县| 庄浪县| 姜堰市| 大丰市| 澄江县| 安宁市| 白朗县| 晴隆县| 崇阳县| 江油市| 盐城市| 斗六市| 通山县| 行唐县| 北宁市| 神池县| 益阳市| 响水县| 虎林市| 武隆县| 巴里| 延川县| 阿拉善左旗| 大新县| 阳谷县| 弋阳县| 临桂县|