Correct use of xbmc.Player in Python?
#3
Thanks for the reply! I am doing a basic integration of MusicIP server into Kodi.

The MusicIP server is able to generate a mix of similar tracks based on a seed track, returned as a delimited list. What I want is to have a "more like this" menu item. The current music playlist should then be replaced with the new tracks.

The first track returned can be the seed track, based on settings, and if so I was thinking of resuming playback kind of seamlessly. All works well, except for this part. 

Here's the full script!



import xbmc
import xbmcgui
import urllib.request
import urllib.parse
import re
import os

__scriptname__ = "Music IP"

if xbmc.Player().isPlayingAudio() == False:
    xbmcgui.Dialog().notification(__scriptname__, "Not currently playing audio")
else:
    currentlyPlaying = xbmc.Player().getMusicInfoTag().getURL()

    size=str(25)
    apiPath = 'http://localhost:10002/api/mix?song='
    options = '&size='+size+'&sizeType=tracks&content=text'

    # The url in which to use
    Base_URL = apiPath + urllib.parse.quote(currentlyPlaying.encode('iso-8859-1')) + options
    #Pre-define global Lists
    LinkURL = []

    WebSock = urllib.request.urlopen(Base_URL)  # Opens a 'Socket' to URL
    WebHTML = WebSock.read()            # Reads Contents of URL and saves to Variable
    WebSock.close()                     # Closes connection to url

    LinkURL = WebHTML.split(b'\n')
    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().lower()
    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().lower()

    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)

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

Reply


Messages In This Thread
RE: Correct use of xbmc.Player in Python? - by splatterpop - 2021-03-08, 22:09


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