栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在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()


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/660664.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号