我设法让它播放声音,但它永远不会得到EOS消息。 因此脚本永远不会退出。
require 'gst'
main_loop = GLib::MainLoop.new
pipeline = Gst::Pipeline.new "audio-player"
source = Gst::ElementFactory.make "filesrc", "file-source"
source.location = "/usr/share/sounds/gnome/default/alerts/bark.ogg"
decoder = Gst::ElementFactory.make "decodebin", "decoder"
conv = Gst::ElementFactory.make "audioconvert", "converter"
sink = Gst::ElementFactory.make "alsasink", "output"
pipeline.add source, decoder, conv, sink
source >> decoder
conv >> sink
decoder.signal_connect "pad-added" do |element, pad, data|
pad >> conv['sink']
end
pipeline.bus.add_watch do |bus, message|
puts "Message: #{message.inspect}"
case message.type
when Gst::Message::Type::ERROR
puts message.structure["debug"]
main_loop.quit
when Gst::Message::Type::EOS
puts 'End of stream'
main_loop.quit
end
end
pipeline.play
begin
puts 'Running main loop'
main_loop.run
ensure
puts 'Shutting down main loop'
pipeline.stop
end
答案 0 :(得分:2)
我找到了解决方案。与可能遇到同样问题的每个人分享。
真正的问题是阻止没有返回true
。它必须返回true
才能被关注。这在GStreamer文档的深处有记载,但在ruby-gnome2文档中没有提到。
答案 1 :(得分:1)
Gst::Message::Type::EOS
应该是:
Gst::Message::EOS
同样适用于ERROR