Correct use of xbmc.Player in Python?
#1
Hello,

this is what I try to do with the audio player in my script:
remember current title and time
stop player
clear playlist and repopulate
start playing the playlist from the beginning
if the currently title is the same as it was, seek to the time where we left off

All works well expcept the last step. The player starts to play at the beginning but does not appear to seek. 

Part of my code:


    playList = xbmc.PlayList(0)
    currentPos = playList.getposition()
    numAdded = 0
    
    playList.clear()

    for l in LinkURL:
        if not l == "":
            playList.add(url=l)
            numAdded += 1

    tm = xbmc.Player().getTime()
    fn1 = xbmc.Player().getPlayingFile()
    xbmc.log("current file: %s" % fn1, xbmc.LOGWARNING)
    xbmc.log("current time: %g" % tm, xbmc.LOGWARNING)
    xbmc.Player().stop()
    xbmc.Player().play(item = playList, startpos = 0)
    xbmc.Player().playselected(0)
    fn2 = xbmc.Player().getPlayingFile()
    # fn2 = fn1
    xbmc.log("    new file: %s" % fn2, xbmc.LOGWARNING)
    if fn1 == fn2:
        xbmc.log("before seekTime", xbmc.LOGWARNING)
        xbmc.log("Player.getTime is now: %g" % xbmc.Player().getTime(), xbmc.LOGWARNING)
        xbmc.log("seek to %g" % tm, xbmc.LOGWARNING)
        xbmc.Player().seekTime™
        xbmc.log("Player.getTime is now: %g" % xbmc.Player().getTime(), xbmc.LOGWARNING)
        xbmc.log("after seekTime", xbmc.LOGWARNING)
    else:
        xbmc.log("diferrent file - not seeking", xbmc.LOGWARNING)
        xbmc.Player().playselected(0)

    xbmcgui.Dialog().notification(__scriptname__, "%d titles were added to the playlist" % playList.size())

From the log (to illustrate, no violation of the forum rules intended):

2021-03-07 19:05:48.950 T:16348 WARNING <general>: current time: 51.119
2021-03-07 19:05:49.403 T:7120     INFO <general>: CDVDAudioCodecFFmpeg::Open() Successful opened audio decoder mp3float
2021-03-07 19:05:49.491 T:16348 WARNING <general>:     new file: d:\music\#electronica\Urbs\Toujours le même film... (2005)\Urbs - Toujours le même film... - 01 - So Weit.mp3
2021-03-07 19:05:49.492 T:16348 WARNING <general>: before seekTime
2021-03-07 19:05:49.492 T:16348 WARNING <general>: Player.getTime is now: 51.219
2021-03-07 19:05:49.492 T:16348 WARNING <general>: seek to 51.119
2021-03-07 19:05:49.492 T:16348 WARNING <general>: Player.getTime is now: 51.219
2021-03-07 19:05:49.492 T:16348 WARNING <general>: after seekTime
2021-03-07 19:05:49.492 T:16348    INFO <general>: CPythonInvoker(257, C:\Users\USER\AppData\Roaming\Kodi\addons\script.musicip\xbmcmusicip.py): script successfully run

My observation is that the player stops, then plays the new playlist from the beginning, as expected, but is not affected by seekTime. Oddly, the reported getTime() values appear to be correct!

Thx for your help.
Reply


Messages In This Thread
Correct use of xbmc.Player in Python? - by splatterpop - 2021-03-07, 20:47


Logout Mark Read Team Forum Stats Members Help
Correct use of xbmc.Player in Python?0
This forum uses Lukasz Tkacz MyBB addons.