Playback.stop() doesnt work if playback.seek() is used

Hello,

Sorry for the long delay but had some challenges in my professional live.
Looking in to the code of PlaybackController.seek(time_position ) I found:

if self.get_state() == PlaybackState.STOPPED:
            self.play()

So I thought it should be enough to use seek, but also with the fix that doesnt work.

I tested the fix with sleep and that works with the disadvantage that sometimes the first few milliseconds of the track are played before it seeks too the new position:

def cb_card_inserted(self):
        self.seek_time = 160000
        logger.info("Card inserted")
        track_uris = ['file:///home/pi/Music/Blues/004%20doggin%27%20the%20blues.mp3', 'file:///home/pi/Music/Blues/003%20friendless%20blues.mp3']
        self.core.tracklist.add(uris=track_uris)
        play = self.core.playback.play().get()
        sleep(1)
        seek = self.core.playback.seek(160000).get()
        sleep(1)
        logger.info("Playback State: {0}".format(self.core.playback.get_state().get()))
        logger.info("Seek command result: {0}".format(seek))

Using track_playback_started would initiate a seek with every new track. I therfore used that instead:

def playback_state_changed(self, old_state, new_state):
        logger.info("Playback State changed from: {0} to: {1}".format(old_state, new_state))
        if old_state == "stopped":
            seek = self.core.playback.seek(self.seek_time).get()
            logger.info("Seek command result: {0}".format(seek))
            self.seek_time = 0

If there is no other solution available from developement of mopidy I will see what way I will go in my project.

BTW. In the seek function you use two times:

if time_position < 0:
    time_position = 0

Not that this cause issues or would be important but you can save two lines of code and make the code clearer/cleaner :nerd_face:.

Thank you very much for the fix and I will look forward to test it in the new release of mopidy.

cheers

Michael

Did you try the fix at Fix/seek when stopped by kingosticks · Pull Request #2006 · mopidy/mopidy · GitHub ?

Thats the fix I am talking about:

(mopidy) pi@musicpy4:~/develop/mopidy-dev/mopidy $ git status -
On branch fix/seek-when-stopped
Your branch is up to date with 'kingosticks/fix/seek-when-stopped'.

Latest commit:

commit c5d4f83c917f70b78607d3d572d1d8555a6b72a5 (HEAD -> fix/seek-when-stopped, kingosticks/fix/seek-when-stopped)
Author: Nick Steel <nick@nsteel.co.uk>
Date:   Tue Aug 10 12:34:09 2021 +0100

    Set state to PLAYING regardless of seek success.
    
    Added comment regarding `seek` returning False when state is STOPPED.

Ok, thanks for clarifying that. I had high hopes for that fix (it definitely fixes a bug, at least). I’m about to go on holiday so this will have to wait until I get back, at which point I’ll merge that “fix” and take another look.

No worries, I wish you a nice and relaxing vacation.

@kingosticks Hello, I am wondering how I can further support here to debug or troubleshoot?

Thanks

Michael

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.