File: xml-ogg-player.rb

package info (click to toggle)
ruby-gnome2 0.15.0-1.1
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 7,692 kB
  • ctags: 8,558
  • sloc: ansic: 69,912; ruby: 19,511; makefile: 97; xml: 35; sql: 13
file content (51 lines) | stat: -rw-r--r-- 1,010 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
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

# A simple OGG/Vorbis player which uses GStreamer's XML serialization feature
# to save and load a Gst::Pipeline.

require 'gst'

Gst.init

XML_FILE = "/tmp/ogg_pipeline"

unless ARGV.length == 1
    puts "Usage: #{__FILE__} [ogg_file]"
    exit 1
end

def build_pipeline(file)
    src = Gst::ElementFactory.make("filesrc")
    dec = Gst::ElementFactory.make("vorbisfile")
    sink = Gst::ElementFactory.make("osssink")
    src.location = file
    src >> dec >> sink
    pipe = Gst::Pipeline.new("our_ogg_pipeline")
    pipe.add(src, dec, sink)
    pipe
end

def write_pipeline(pipe, file)
    Gst::XML.write_file(pipe, file)
end

def read_pipeline(file)
    xml = Gst::XML.new
    xml.parse_file(file)
    xml.get_element("our_ogg_pipeline")
end

def play_pipeline(pipe)
    pipe.play
    begin 
        while pipe.iterate do end
    rescue Interrupt
    ensure 
        pipe.stop 
    end
end

pipe = build_pipeline ARGV.first
write_pipeline pipe, XML_FILE
pipe = read_pipeline XML_FILE
play_pipeline pipe