def autoPlay(): removeOldVideosFromPlaylist() if videos: if not engine.isPlaying(): playNextVideo() else: svideo = currentVideo() if svideo: position = engine.getPosition() if position: svideo.data["position"] = position duration = engine.getDuration() if duration: svideo.data["duration"] = duration for nvideo in videos[:3]: prepareVideo(nvideo) threading.Timer(1, autoPlay).start()
def playVideo(videoId): svideo = findVideoInPlaylist(videoId) if svideo: print 'Requested video ' + videoId if svideo == currentVideo(): engine.setPosition(0) else: svideo.played = True removeOldVideosFromPlaylist() if svideo != videos[0]: videos.remove(svideo) videos.insert(0, svideo) if not svideo.url: prepareVideo(svideo) try: engine.play(svideo) except RuntimeError: print 'Error playing video ' + videoId removeVideo(svideo.vid)