如果您只是想从特定 URL 播放/流式传输音频,您可以尝试vlc
绑定python
. 更多细节在这里
它可以安装为pip install python-vlc
这是一个直接从 URL 流式传输音频的示例代码。player
对象增加了音频播放器的优势,例如暂停、恢复、停止等控件。
使用的 URL 是m4a
有问题的 url。
源代码
import vlc
import time
url = "http://r2---sn-q4fl6nlr.googlevideo.com/videoplayback?id=ded99df829692710&itag=140&source=youtube&ei=DRvmWa-kDtr9oQObxIuACw&pl=32&ratebypass=yes&mime=audio/mp4&gir=yes&clen=4061037&lmt=1507168899082254&dur=255.651&signature=4380D44827E745850E8034A17DD2CF71493515B2.49EE0269B463E530D2C05D79E658319E3354F4B5&key=cms1&ip=103.200.41.86&ipbits=0&expire=1508274029&sparams=clen,dur,ei,expire,gir,id,initcwndbps,ip,ipbits,ipbypass,itag,lmt,mime,mip,mm,mn,ms,mv,pl,ratebypass,source&rm=sn-52vaavvoapox-itql7l,sn-h55z7z&req_id=ac17cbf87900a3ee&redirect_counter=2&fexp=23702512&cms_redirect=yes&ipbypass=yes&mip=2605:6000:ec02:7e00:6d00:a5a1:a309:abb6&mm=30&mn=sn-q4fl6nlr&ms=nxu&mt=1508259877&mv=m"
#define VLC instance
instance = vlc.Instance('--input-repeat=-1', '--fullscreen')
#Define VLC player
player=instance.media_player_new()
#Define VLC media
media=instance.media_new(url)
#Set player media
player.set_media(media)
#Play the media
player.play()
一些player
控制
>>> play.pause() #pause play back
>>> player.play() #resume play back
>>> player.stop() #stop play back