~ubuntu-branches/ubuntu/precise/gst0.10-python/precise

« back to all changes in this revision

Viewing changes to examples/gst123

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Wirt
  • Date: 2008-09-08 20:22:47 UTC
  • mfrom: (4.1.15 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080908202247-nkwix5wpfasoygy0
Tags: 0.10.12-1.1
* Non-maintainer upload.
* Add dependency to python-libxml2 and change load order in
  the init of gst0.10-python (Closes: #449341)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
# -*- Mode: python -*-
3
 
 
4
 
import getopt
5
 
import sys
6
 
 
7
 
import gst
8
 
 
9
 
"""Usage: gst123 [<options>] <input file> ...
10
 
 
11
 
  -h, --help           this help
12
 
  -V, --version        display gst123 version
13
 
  -d, --device=d       uses 'd' as an output device
14
 
                       Possible devices are ('*'=live, '@'=file):
15
 
                         null* wav@ raw@ au@ arts* esd* oss*
16
 
  -f, --file=filename  Set the output filename for a previously
17
 
                       specified file device (with -d).
18
 
  -k n, --skip n       Skip the first 'n' seconds
19
 
  -b n, --buffer n     use an input buffer of 'n' kilobytes
20
 
  -v, --verbose        display progress and other status information
21
 
  -q, --quiet          don't display anything (no title)
22
 
  -z, --shuffle        shuffle play"""
23
 
 
24
 
def found_tags_cb(element, source, tags):
25
 
    for tag in tags.keys():
26
 
        if tag in ['title', 'artist', 'genre', 'album']:
27
 
            ntag = tag[0].upper() + tag[1:] + ':'
28
 
            print '%-8s %s' % (ntag, tags[tag])
29
 
        
30
 
def error_cb(bin, element, error, debug):
31
 
    print error
32
 
    raise SystemExit
33
 
 
34
 
def pad_notify_caps_cb(pad, arg):
35
 
    caps = pad.get_negotiated_caps()
36
 
    
37
 
    if not caps:
38
 
        return
39
 
    
40
 
    for structure in caps:
41
 
        print 'Bitstream is %(channels)d channel(s), %(rate)dHz' % structure
42
 
 
43
 
def playfile(filename):
44
 
    bin = gst.Thread('player')
45
 
    bin.connect('eos', lambda bin: gst.main_quit())
46
 
    bin.connect('error', error_cb)
47
 
    
48
 
    source = gst.element_factory_make('filesrc', 'src')
49
 
    source.set_property('location', filename)
50
 
 
51
 
    spider = gst.element_factory_make('spider', 'spider')
52
 
    spider.connect('found-tag', found_tags_cb)
53
 
    
54
 
    sink = gst.element_factory_make('osssink', 'sink')
55
 
    #sink.set_property('release-device', 1)
56
 
    pad = sink.get_pad('sink')
57
 
    pad.connect('notify::caps', pad_notify_caps_cb)
58
 
    
59
 
    bin.add_many(source, spider, sink)
60
 
    if not gst.element_link_many(source, spider, sink):
61
 
        print "ERROR: could not link"
62
 
        sys.exit(1)
63
 
 
64
 
    print 'Playing:', filename
65
 
    if not bin.set_state(gst.STATE_PLAYING):
66
 
        print "ERROR: could not set bin to playing"
67
 
        sys.exit(1)
68
 
 
69
 
    while 1:
70
 
        try:
71
 
            if not gst.main():
72
 
                break
73
 
        except KeyboardInterrupt:
74
 
            if not bin.set_state(gst.STATE_PAUSED):
75
 
                print "ERROR: could not set bin to paused"
76
 
                sys.exit(1)
77
 
            sys.stdout.write("Paused.  Press Enter to go back to playing.")
78
 
            sys.stdout.flush()
79
 
            try:
80
 
                sys.stdin.readline()
81
 
                if not bin.set_state(gst.STATE_PLAYING):
82
 
                    print "ERROR: could not set bin to playing"
83
 
                    sys.exit(1)
84
 
                print "Playing."
85
 
            except KeyboardInterrupt:
86
 
                print
87
 
                break
88
 
 
89
 
    bin.set_state(gst.STATE_NULL)
90
 
    
91
 
def main(args):
92
 
    if len(args) > 2:
93
 
        print 'usage: gst123 files...'
94
 
        return 2
95
 
    
96
 
    args2, opt = getopt.getopt(args[1:], 'b:d:f:hk:vVqz',
97
 
                              ['help', 'version', 'device=',
98
 
                               'file=', 'skip=', 'buffer=',
99
 
                               'verbose', 'quiet', 'shuffle'])
100
 
    for arg in args[1:]:
101
 
        try:
102
 
            playfile(arg)
103
 
        except KeyboardInterrupt:
104
 
            raise SystemExit
105
 
 
106
 
if __name__ == '__main__':
107
 
    sys.exit(main(sys.argv))
108
 
 
109
 
 
110
 
for i in range(10, 20, 1):
111
 
    pass