Allow scanner to stop nicely when it runs out of files
This commit is contained in:
parent
89fe08a583
commit
21123e3cd9
@ -15,6 +15,7 @@ class Scanner(object):
|
|||||||
def __init__(self, files, callback):
|
def __init__(self, files, callback):
|
||||||
self.uris = [path_to_uri(abspath(f)) for f in files]
|
self.uris = [path_to_uri(abspath(f)) for f in files]
|
||||||
self.callback = callback
|
self.callback = callback
|
||||||
|
self.loop = gobject.MainLoop()
|
||||||
|
|
||||||
self.pipe = gst.element_factory_make('playbin2')
|
self.pipe = gst.element_factory_make('playbin2')
|
||||||
|
|
||||||
@ -24,8 +25,6 @@ class Scanner(object):
|
|||||||
|
|
||||||
self.next_uri()
|
self.next_uri()
|
||||||
|
|
||||||
gobject.MainLoop().run()
|
|
||||||
|
|
||||||
def process_message(self, bus, message):
|
def process_message(self, bus, message):
|
||||||
data = message.parse_tag()
|
data = message.parse_tag()
|
||||||
self.callback(dict([(k, data[k]) for k in data.keys()]))
|
self.callback(dict([(k, data[k]) for k in data.keys()]))
|
||||||
@ -33,17 +32,14 @@ class Scanner(object):
|
|||||||
|
|
||||||
def next_uri(self):
|
def next_uri(self):
|
||||||
if not self.uris:
|
if not self.uris:
|
||||||
sys.exit(0)
|
return self.stop()
|
||||||
|
|
||||||
self.pipe.set_state(gst.STATE_NULL)
|
self.pipe.set_state(gst.STATE_NULL)
|
||||||
self.pipe.set_property('uri', self.uris.pop())
|
self.pipe.set_property('uri', self.uris.pop())
|
||||||
self.pipe.set_state(gst.STATE_PAUSED)
|
self.pipe.set_state(gst.STATE_PAUSED)
|
||||||
|
|
||||||
def debug(data):
|
def start(self):
|
||||||
print data
|
self.loop.run()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
def stop(self):
|
||||||
if len(sys.argv) == 1:
|
self.loop.quit()
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
Scanner(sys.argv[1:], debug)
|
|
||||||
|
|||||||
Binary file not shown.
Loading…
Reference in New Issue
Block a user