在Python中播放远程音频文件?

在Python中播放远程音频文件?,第1张

在Python中播放远程音频文件

您可以将GStreamer与python绑定一起使用(需要PyGTK)。

然后,您可以使用以下代码

import pygstimport gstdef on_tag(bus, msg):    taglist = msg.parse_tag()    print 'on_tag:'    for key in taglist.keys():        print 't%s = %s' % (key, taglist[key])#our stream to playmusic_stream_uri = 'http://mp3channels.webradio.antenne.de/chillout'#creates a playbin (plays media form an uri) player = gst.element_factory_make("playbin", "player")#set the uriplayer.set_property('uri', music_stream_uri)#start playingplayer.set_state(gst.STATE_PLAYING)#listen for tags on the message bus; tag event might be called more than oncebus = player.get_bus()bus.enable_sync_message_emission()bus.add_signal_watch()bus.connect('message::tag', on_tag)#wait and let the music playraw_input('Press enter to stop playing...')

GStreamer
playbin文件

更新

控制播放器:

def play():    player.set_state(gst.STATE_PLAYING)def pause():    player.set_state(gst.STATE_PAUSED)def stop():    player.set_state(gst.STATE_NULL)def play_new_uri( new_uri ):    player.set_state(gst.STATE_NULL)    player.set_property('uri', new_uri )    play()


欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/zaji/5666780.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-16
下一篇2022-12-16

发表评论

登录后才能评论

评论列表(0条)

    保存