Allow scanner to stop nicely when it runs out of files

This commit is contained in:
Thomas Adamcik 2010-10-25 23:18:35 +02:00
parent 89fe08a583
commit 21123e3cd9
2 changed files with 6 additions and 10 deletions

View File

@ -15,6 +15,7 @@ class Scanner(object):
def __init__(self, files, callback):
self.uris = [path_to_uri(abspath(f)) for f in files]
self.callback = callback
self.loop = gobject.MainLoop()
self.pipe = gst.element_factory_make('playbin2')
@ -24,8 +25,6 @@ class Scanner(object):
self.next_uri()
gobject.MainLoop().run()
def process_message(self, bus, message):
data = message.parse_tag()
self.callback(dict([(k, data[k]) for k in data.keys()]))
@ -33,17 +32,14 @@ class Scanner(object):
def next_uri(self):
if not self.uris:
sys.exit(0)
return self.stop()
self.pipe.set_state(gst.STATE_NULL)
self.pipe.set_property('uri', self.uris.pop())
self.pipe.set_state(gst.STATE_PAUSED)
def debug(data):
print data
def start(self):
self.loop.run()
if __name__ == '__main__':
if len(sys.argv) == 1:
sys.exit(1)
Scanner(sys.argv[1:], debug)
def stop(self):
self.loop.quit()

Binary file not shown.