seems i’m missing something querying song duration through gstreamer.
i’ve seen this post http://www.ruby-forum.com/topic/206849 , and the
proof-of-concept app, as well as duration meters in other players (zik)
which use the same method. this code however:
pipeline = Gst::ElementFactory.make(“playbin2”)
pipeline.uri= “file://home/jk/ruby/test.mp3”
d = Gst::QueryDuration.new(Gst::Format::Type::TIME)
pipeline.query(d)
gstdur = d.parse[1]/1000000
p “gstdur= #{gstdur}”
returns:
“gstdur= -1”
at the moment i’m using the gem ‘mp3info’ for duration, and querying
the same file with mp3info, like this:
audio = “/home/jk/ruby/test.mp3”
Mp3Info.open(audio){|data| @infodur = data.length}
p “infodur= #{@infodur}”
returns:
“infodur= 227.5791875”
any ideas what i’m doing wrong in the gstreamer query?
pipeline = Gst::ElementFactory.make(“playbin2”)
pipeline.uri= “file:/home/jk/ruby/test.mp3”
bus = pipeline.bus
bus.add_watch {|bus, message|
case message.type
when Gst::Message::DURATION
dur = message
p dur.parse[1]/1000000
end
true}
pipeline.play
i thought the same, but oddly i get an error with the extra ‘/’, and
the file doesn’t play -
pipeline.uri= “file://home/jk/ruby/test.mp3”
[#<GLib::Error: Resource not found.>, “gstgiosrc.c(313):
gst_gio_src_get_stream ():
/GstPlayBin2:playbin20/GstURIDecodeBin:uridecodebin0/GstGioSrc:source:\nCould
not open location file:///jk/ruby/test.mp3 for reading: Error opening
file: No such file or directory”]
I guess you now miss “home”
file:///home/jk/ruby/test.mp3 and not file:///jk/ruby/test.mp3
Posted via http://www.ruby-forum.com/.
I think you are missing “/” here. file:///home/jk/ruby/test.mp3
protocole(file)://path(/home/jk/ruby/test.mp3)
i thought the same, but oddly i get an error with the extra ‘/’, and
the file doesn’t play -
pipeline.uri= “file://home/jk/ruby/test.mp3”
[#<GLib::Error: Resource not found.>, “gstgiosrc.c(313):
gst_gio_src_get_stream ():
/GstPlayBin2:playbin20/GstURIDecodeBin:uridecodebin0/GstGioSrc:source:\nCould
not open location file:///jk/ruby/test.mp3 for reading: Error opening
file: No such file or directory”]
when i remove the first ‘/’, the file is found and plays…
Instead of sleep I would have use GLib::Timeout.add method. It should
allows other events to be processed during the 0.125 s.
def getDuration
GLib::Timeout.add(125){
qd = Gst::QueryDuration.new(Gst::Format::Type::TIME) @pipeline.query(qd) @dur = qd.parse[1]/1000000000
if @dur<0
true#TODO : add a limit for the number of queries
else
false
end
}
interesting, it turns out that there is a lag in the duration query
(at least with 1.8.7, gtk2 0.19.3 and gstreamer 0.10.x.) when i put the
query in the timeout loop for showing position, it would first show -1 a
couple of times, and then show the duration parsed to seconds after a
bit. i ended up solving my problem writing a simple getDuration method,
which includes an 1/8 of a second sleep, to let the pipeline get rolling
before the query takes place.