I have a folder with some video and I would like to play just one random video before continue my python script.
Now I'm using
Code:
xbmc.executebuiltin('xbmc.PlayMedia("/path_to_video/","isdir")')
xbmc.executebuiltin('xbmc.PlayerControl(random)')
xbmc.executebuiltin("Action(Fullscreen)")
But in that way the script plays randomly any video in the folder. How can I trigger the end of the video on my script before do the next action?
Another approach could be to create a python list and then use PlayMedia with 'list[position]', but xbmc.executebuiltin doesn't seems to like much normal placeholders...
Thanks.
F.
Since I don't like the above solution, I'm starting with a new script but as I fear, the python interpreter has some problem with common syntax.
I'm selecting the name of the videos to be played from a txt, needed for generating a list and point a variable to the right entry (for now just the first [0]).
My code:
Code:
import xbmc, imp
pvideo = open("/home/effe/Imagens/Italia/list.txt").readlines(); num = 0; curvideo = "'"+pvideo[num]+"'"
def main():
monitor = xbmc.Monitor()
if monitor.waitForAbort(10):
return
while True:
xbmc.executebuiltin("xbmc.PlayMedia({0})".format(curvideo))
xbmc.executebuiltin('xbmc.PlayerControl(playpause)')
xbmc.executebuiltin("Action(Fullscreen)")
if monitor.waitForAbort(300):
break
if __name__ == '__main__':
main()
The log is pretty clear, there is an issue with the file name, where there are spaces after the last character:
Code:
19:26:50 T:140083018942400 NOTICE: DVDPlayer: Opening: '/home/effe/Imagens/Italia/A Glimpse of Italy.mp4
'
19:26:50 T:140083018942400 WARNING: CDVDMessageQueue(player)::Put MSGQ_NOT_INITIALIZED
19:26:50 T:140081075521280 NOTICE: Thread DVDPlayer start, auto delete: false
19:26:50 T:140081075521280 NOTICE: Creating InputStream
19:26:50 T:140081075521280 ERROR: CDVDPlayer::OpenInputStream - error opening ['/home/effe/Imagens/Italia/A Glimpse of Italy.mp4
']
19:26:50 T:140081075521280 NOTICE: CDVDPlayer::OnExit()
19:26:50 T:140083018942400 ERROR: PlayMedia could not play media: '/home/effe/Imagens/Italia/A Glimpse of Italy.mp4
'
19:26:50 T:140083018942400 NOTICE: CDVDPlayer::CloseFile()
19:26:50 T:140083018942400 NOTICE: DVDPlayer: waiting for threads to exit
19:26:50 T:140083018942400 NOTICE: DVDPlayer: finished waiting
19:26:50 T:140083018942400 NOTICE: CDVDPlayer::CloseFile()
Problem is the normal rstrip() or a replace (" " with "") doesn't works and the spaces are still here.
If I use directly a complete path to the file on my variable
Code:
curvideo = '/home/effe/Imagens/Italia/A Glimpse of Italy.mp4'
Kodi will accept it and will works as expected.
Any tips?
Solved!
The problem was a rstrip on a string with quotes. Pulling out quotes solved the issue.
for the sake of knowledge here is my revised code:
Code:
import xbmc, imp
pvideo = open("/home/effe/Imagens/Italia/list.txt").readlines(); num = 1; curvideo = pvideo[num]; playnow = curvideo.rstrip()
def main():
monitor = xbmc.Monitor()
if monitor.waitForAbort(10):
return
while True:
xbmc.executebuiltin("xbmc.PlayMedia({0})".format(playnow))
xbmc.executebuiltin('xbmc.PlayerControl(playpause)')
xbmc.executebuiltin("Action(Fullscreen)")
if monitor.waitForAbort(300):
break
xbmc.executebuiltin('XBMC.ActivateWindow(weather)')
if monitor.waitForAbort(100):
break
xbmc.executebuiltin('XBMC.ActivateWindow(home)')
if monitor.waitForAbort(100):
break
def getVarFromFile(filename):
f = open(filename)
global data
data = imp.load_source('data', '', f)
f.close()
getVarFromFile('/home/effe/var.txt')
xbmc.executebuiltin("Skin.SetString(tempo, {0})".format(data.wait_time))
xbmc.executebuiltin('XBMC.ActivateWindow(1180)')
if monitor.waitForAbort(100):
break
xbmc.executebuiltin('XBMC.ActivateWindow(home)')
if monitor.waitForAbort(100):
break
if __name__ == '__main__':
main()