我在Raspberry Pi上有一个Python脚本,用于传输无线电。它在很长一段时间内都很好用,但今天并没有那么多。这是一个可重现的示例,它会生成错误消息:
import pygst
import gst
import time
import subprocess
def 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 play
music_stream_uri = "http://streams.kqed.org/kqedradio"
##
###creates a playbin (plays media form an uri)
player = gst.element_factory_make("playbin", "player")
##
###set the uri
player.set_property('uri', music_stream_uri)
##
###start playing
player.set_state(gst.STATE_PLAYING)
#listen for tags on the message bus; tag event might be called more than once
bus = player.get_bus()
bus.enable_sync_message_emission()
bus.add_signal_watch()
bus.connect('message::tag', on_tag)
#wait and let the music play
raw_input('Press enter to stop playing...')
以下是错误消息:
** (test.py:2844): WARNING **: Cannot autolaunch D-Bus without X11 $DISPLAY
** (test.py:2844): WARNING **: Cannot autolaunch D-Bus without X11 $DISPLAY
** (test.py:2844): WARNING **: Cannot autolaunch D-Bus without X11 $DISPLAY
** (test.py:2844): WARNING **: Cannot autolaunch D-Bus without X11 $DISPLAY
** (test.py:2844): WARNING **: Cannot autolaunch D-Bus without X11 $DISPLAY
** (test.py:2844): WARNING **: Cannot autolaunch D-Bus without X11 $DISPLAY
** (test.py:2844): WARNING **: Cannot autolaunch D-Bus without X11 $DISPLAY
** (test.py:2844): WARNING **: Cannot autolaunch D-Bus without X11 $DISPLAY
** (test.py:2844): WARNING **: Cannot autolaunch D-Bus without X11 $DISPLAY
** (test.py:2844): WARNING **: Cannot autolaunch D-Bus without X11 $DISPLAY
Press enter to stop playing...Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
这个答案说有关显示的部分是harmless,我相信我之前看过那条消息,没有播放无线电流的问题。我尝试了这个answer,但它也返回了一个关于显示的错误(不确定是什么脉冲无线电,但我根据答案尝试了它。)
pi@raspberrypi ~ $ pulseaudio --kill
-bash: pulseaudio: command not found
pi@raspberrypi ~ $ jack_control start
Traceback (most recent call last):
File "/usr/bin/jack_control", line 374, in <module>
main()
File "/usr/bin/jack_control", line 135, in main
bus = dbus.SessionBus()
File "/usr/lib/python2.7/dist-packages/dbus/_dbus.py", line 211, in __new__
mainloop=mainloop)
File "/usr/lib/python2.7/dist-packages/dbus/_dbus.py", line 100, in __new__
bus = BusConnection.__new__(subclass, bus_type, mainloop=mainloop)
File "/usr/lib/python2.7/dist-packages/dbus/bus.py", line 122, in __new__
bus = cls._new_for_bus(address_or_type, mainloop=mainloop)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NotSupported: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
值得注意的是,没有显示,我通过PuTTY访问Raspberry Pi。这个question有一个非常类似的问题,但我不知道这个answer如何应用于我的脚本。这个answer(也是一个非常相似的问题)抑制了X11错误,但我仍然得到关于jackbus的错误:
Press enter to stop playing...Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
最后,我将alsamixer重置为无效sudo /etc/init.d/alsa-utils reset
更新
我是个天才。事实证明我不小心将音频输出线插入扬声器的耳机插孔而不是音频输入插孔。显然我总是得到这个错误信息,从来没有注意到它,因为我仍然没有问题(至少只要我不搞砸电缆!)。我仍然会对这个错误信息的解释感兴趣,因为事实证明它完全是错误的,而树莓派确实在输出声音。