File: mp3-player.rb

package info (click to toggle)
ruby-gnome2 0.15.0-1.1etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 7,704 kB
  • ctags: 8,558
  • sloc: ansic: 69,912; ruby: 19,511; makefile: 97; xml: 35; sql: 13
file content (48 lines) | stat: -rw-r--r-- 1,007 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

require 'gst'

def usage
    puts "Usage: #{__FILE__} mp3-file"
    exit
end

def main
    usage if ARGV.length != 1 
    file = ARGV[0]
    
    # Create a pipeline to hold the elements
    pipeline = Gst::Pipeline.new("my_pipeline")
    
    # Create a disk reader
    filesrc = Gst::ElementFactory.make("filesrc", "my_disk_source")
    filesrc.location = file 

    # Now it's time to get the MP3 decoder
    decoder = Gst::ElementFactory.make("mad", "my_decoder")

    # And an audio sink
    audiosink = Gst::ElementFactory.make("osssink", "my_audio_player")

    # Add objects to the main pipeline
    pipeline.add(filesrc, decoder, audiosink)

    # Link disk source => decoder => audio player 
    filesrc >> decoder >> audiosink

    # Start playing
    puts "Playing #{file}..."
    pipeline.play

    begin
        # Wait until the file is played
        while pipeline.iterate do end
    rescue Interrupt
    ensure
        # Stop the pipeline
        pipeline.stop
    end
end

Gst.init
main