11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/vimamsa/audio.rb', line 11
def self.play(fn)
playbin = @@playbin
if playbin.nil?
playbin = Gst::ElementFactory.make("playbin")
if playbin.nil?
puts "'playbin' gstreamer plugin missing"
return
end
else
if playbin.current_state == "playing"
playbin.stop
end
end
if Gst.valid_uri?(fn)
uri = fn
else
uri = Gst.filename_to_uri(fn)
end
playbin.uri = uri
@@playbin = playbin
bus = playbin.bus
bus.add_watch do |bus, message|
case message.type
when Gst::MessageType::EOS
puts "End-of-stream"
when Gst::MessageType::ERROR
error, debug = message.parse_error
puts "Debugging info: #{debug || "none"}"
puts "Error: #{error.message}"
end
true
end
message("Start playing audio: #{fn}")
playbin.play
end
|