9
"""Usage: gst123 [<options>] <input file> ...
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"""
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])
30
def error_cb(bin, element, error, debug):
34
def pad_notify_caps_cb(pad, arg):
35
caps = pad.get_negotiated_caps()
40
for structure in caps:
41
print 'Bitstream is %(channels)d channel(s), %(rate)dHz' % structure
43
def playfile(filename):
44
bin = gst.Thread('player')
45
bin.connect('eos', lambda bin: gst.main_quit())
46
bin.connect('error', error_cb)
48
source = gst.element_factory_make('filesrc', 'src')
49
source.set_property('location', filename)
51
spider = gst.element_factory_make('spider', 'spider')
52
spider.connect('found-tag', found_tags_cb)
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)
59
bin.add_many(source, spider, sink)
60
if not gst.element_link_many(source, spider, sink):
61
print "ERROR: could not link"
64
print 'Playing:', filename
65
if not bin.set_state(gst.STATE_PLAYING):
66
print "ERROR: could not set bin to playing"
73
except KeyboardInterrupt:
74
if not bin.set_state(gst.STATE_PAUSED):
75
print "ERROR: could not set bin to paused"
77
sys.stdout.write("Paused. Press Enter to go back to playing.")
81
if not bin.set_state(gst.STATE_PLAYING):
82
print "ERROR: could not set bin to playing"
85
except KeyboardInterrupt:
89
bin.set_state(gst.STATE_NULL)
93
print 'usage: gst123 files...'
96
args2, opt = getopt.getopt(args[1:], 'b:d:f:hk:vVqz',
97
['help', 'version', 'device=',
98
'file=', 'skip=', 'buffer=',
99
'verbose', 'quiet', 'shuffle'])
103
except KeyboardInterrupt:
106
if __name__ == '__main__':
107
sys.exit(main(sys.argv))
110
for i in range(10, 20, 1):