Skip to content

Commit

Permalink
Bug Fix: Sometimes fails to remember playtime time
Browse files Browse the repository at this point in the history
  • Loading branch information
owais committed Nov 11, 2011
1 parent 234664d commit 0322e7a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
6 changes: 6 additions & 0 deletions debian/changelog
@@ -1,3 +1,9 @@
remember-the-rhythm (0.1.2) oneiric; urgency=low

* Bug Fix: Sometimes doesn't remember playback time

-- Owais Lone <hello@owaislone.org> Fri, 11 Nov 2011 23:26:11 +0530

remember-the-rhythm (0.1.1) oneiric; urgency=low

* Now at least remembers the song if rhythmbox crashes
Expand Down
31 changes: 20 additions & 11 deletions src/remember-the-rhythm.py
Expand Up @@ -15,11 +15,14 @@ class RememberTheRhythm(GObject.Object, Peas.Activatable):
object = GObject.property(type=GObject.Object)
location = None
playback_time = None
first_run = False

def __init__(self):
GObject.Object.__init__(self)
try:
config_data = open(CONFIG_FILE, 'r').read()
config_file = open(CONFIG_FILE, 'r')
config_data = config_file.read()
config_file.close()
except IOError:
return
config_data = config_data.split()
Expand All @@ -30,9 +33,9 @@ def do_activate(self):
self.shell = self.object
self.shell_player = self.shell.props.shell_player
self.db = self.shell.props.db
self.shell.connect('database-load-complete', self.load_complete)
self.shell_player.connect('elapsed-changed', self.elapsed_changed)
self.shell_player.connect('playing-song-changed', self.playing_changed)
self.shell.connect('database-load-complete', self.load_complete)

def do_deactivate(self):
self.save_rhythm()
Expand All @@ -42,19 +45,25 @@ def load_complete(self, *args, **kwargs):
entry = self.db.entry_lookup_by_location(self.location)
source = self.shell.guess_source_for_uri(self.location)
self.shell_player.play_entry(entry, source)
if self.playback_time:
self.shell_player.set_playing_time(long(self.playback_time))
self.first_run = True

def save_rhythm(self):
config_file = open(CONFIG_FILE, 'w')
config_data = '\n'.join([self.location, self.playback_time])
config_file.write(config_data)
config_file.close()
def save_rhythm(self, pb_time=None):
if self.location:
pb_time = pb_time == None and self.playback_time or pb_time
config_file = open(CONFIG_FILE, 'w')
config_data = '\n'.join([self.location, pb_time])
config_file.write(config_data)
config_file.close()

def playing_changed(self, player, entry, data=None):
if self.first_run and self.playback_time:
self.shell_player.set_playing_time(long(self.playback_time))
self.first_run = False
try:
self.location = str(entry.get_string(RB.RhythmDBPropType.LOCATION))
self.save_rhythm()
new_location = str(entry.get_string(RB.RhythmDBPropType.LOCATION))
if not new_location == self.location:
GObject.idle_add(self.save_rhythm, '0')
self.location = new_location
except:
pass

Expand Down

0 comments on commit 0322e7a

Please sign in to comment.