tags:

views:

146

answers:

2

I've managed to make it play sound but it never gets EOS message. And thus script never exits.

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
+1  A: 
Gst::Message::Type::EOS

should be:

Gst::Message::EOS

same goes for ERROR

Jeremiah Rose
This is nice shortcut but they are the same. Gst::Message::Type::EOS == Gst::Message::EOS # => true
Cheba
+2  A: 

I've found a solution. Sharing with everybody who may run into same problem.

The real problem was that block didn't return true. It has to return true to be kept in watch. This is documented somewhere deep in GStreamer docs but is not mentioned in ruby-gnome2 docs.

Cheba
please explain your answer more clearly. there is no function 'block' in your example code- which block are you referring to?
Jeremiah Rose
The one passed to pipeline.bus.add_watch
Cheba