-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcustom_player.py
116 lines (89 loc) · 3.68 KB
/
custom_player.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# -*- coding: utf-8 -*-
#------------------------------------------------------------
# pelisalacarta 4
# Copyright 2015 [email protected]
#
# Distributed under the terms of GNU General Public License v3 (GPLv3)
# http://www.gnu.org/licenses/gpl-3.0.html
#------------------------------------------------------------
# This file is part of pelisalacarta 4.
#
# pelisalacarta 4 is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# pelisalacarta 4 is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with pelisalacarta 4. If not, see <http://www.gnu.org/licenses/>.
#------------------------------------------------------------
import os
import sys
import re
import urlparse
import urllib
import urllib2
import time
import xbmc
import xbmcgui
import plugintools
class CustomPlayer(xbmc.Player):
def __init__( self, *args, **kwargs ):
plugintools.log("CustomPlayer.__init__")
xbmc.Player.__init__( self )
self.current_time = 0
self.total_time = 0
self.listener = None
self.seek_pos = 0
def play_stream(self, url):
plugintools.log("CustomPlayer.play_stream url="+url)
self.play(url)
def play_item(self, item, pos=0):
plugintools.log("CustomPlayer.play_item pos="+repr(pos)+", item="+item.tostring())
xbmc_listitem = xbmcgui.ListItem( label=item.title, iconImage=item.thumbnail, thumbnailImage=item.thumbnail, path=item.url)
xbmc_listitem.setInfo( "video", { "Title": item.title , "Plot": item.plot } )
xbmc_listitem.setProperty('fanart_image',item.fanart)
self.seek_pos = pos
self.play(item.url,xbmc_listitem)
def set_listener(self, listener):
plugintools.log("CustomPlayer.set_listener")
self.listener = listener
def onPlayBackStarted(self):
plugintools.log("CustomPlayer.onPlayBackStarted")
if self.seek_pos>0:
self.seekTime(self.seek_pos)
while self.isPlaying():
self.current_time = self.getTime()
self.total_time = self.getTotalTime()
#plugintools.log("CustomPlayer.play_item current_time="+str(self.current_time)+" totaltime="+str(self.total_time))
xbmc.sleep(2000)
def onPlayBackEnded(self):
plugintools.log("CustomPlayer.onPlayBackEnded")
def onPlayBackStopped(self):
plugintools.log("CustomPlayer.onPlayBackStopped")
if self.listener is not None:
self.listener.on_playback_stopped()
def onPlayBackPaused(self):
plugintools.log("CustomPlayer.onPlayBackPaused")
def onPlayBackResumed(self):
plugintools.log("CustomPlayer.onPlayBackResumed")
def onPlayBackSeek(self,time,seekOffset):
plugintools.log("CustomPlayer.onPlayBackSeek")
def onPlayBackSeekChapter(self,seekChaper):
plugintools.log("CustomPlayer.onPlayBackSeekChapter")
def onPlayBackSpeedChanged(self,speed):
plugintools.log("CustomPlayer.onPlayBackSpeedChanged")
def onQueueNextItem(self):
plugintools.log("CustomPlayer.onQueueNextItem")
def get_current_time(self):
return self.current_time
def get_total_time(self):
return self.total_time
def play(url):
plugintools.log("custom_play ["+url+"]")
player = CustomPlayer()
player.PlayStream( url )