4.2.0r3
[enigma2.git] / usr / lib / enigma2 / python / Plugins / Extensions / MediaCenter / MoviePlayer.py
1 # -*- coding: UTF-8 -*-
2 from Screens.Screen import Screen
3 from Screens.ChoiceBox import ChoiceBox
4 from Screens.InfoBarGenerics import InfoBarNotifications, InfoBarSeek, InfoBarShowHide, InfoBarAudioSelection, InfoBarCueSheetSupport, InfoBarSubtitleSupport
5
6 from Components.ActionMap import ActionMap
7
8 from Tools.Log import Log
9 from MediaPlayerLCDScreen import MediaPlayerLCDScreen
10
11 class MoviePlayer(Screen, InfoBarNotifications, InfoBarSeek, InfoBarShowHide, InfoBarAudioSelection, InfoBarCueSheetSupport, InfoBarSubtitleSupport):
12         ENABLE_RESUME_SUPPORT = True
13         ALLOW_SUSPEND = True
14
15         def __init__(self, session, service, infoCallback=None, getNextService=None, getPrevService=None, stopCallback=None):
16                 Screen.__init__(self, session)
17                 InfoBarNotifications.__init__(self)
18                 InfoBarSeek.__init__(self)
19                 InfoBarShowHide.__init__(self)
20                 InfoBarAudioSelection.__init__(self)
21                 InfoBarSubtitleSupport.__init__(self)
22                 InfoBarCueSheetSupport.__init__(self)
23                 #TODO FIX THIS HACK
24                 # currently we just want to be able to resume playback (if supported by e2),
25                 # for now we don't care about cutting or jumpmarks or anything like that...
26                 del self["CueSheetActions"]
27
28                 self.session = session
29                 self.service = service
30                 self.infoCallback = infoCallback
31                 self.getNextServiceCB = getNextService
32                 self.getPrevServiceCB = getPrevService
33                 self.stopCB = stopCallback
34                 self.callback = None
35                 self.screen_timeout = 5000
36                 self.nextservice = None
37                 self.is_closing = False
38
39                 self["actions"] = ActionMap(["MediaCenterActions"],
40                 {
41                                 "cancel": self.leavePlayer,
42                                 "stop": self.leavePlayer,
43                                 "playpauseService": self.playpauseService,
44                                 "previous":  self.playPrev,
45                                 "next": self.playNext,
46 #                               "showentInfo": self.showVideoInfo,
47                         }, -2)
48
49                 self.returning = False
50
51
52                 self.onShown.append(self.play)
53                 self.onClose.append(self.__onClose)
54
55         def __onClose(self):
56                 if self.stopCB != None:
57                                 self.stopCB()
58                 self.session.nav.stopService()
59
60         def createSummary(self):
61                 return MediaPlayerLCDScreen
62
63         def playNext(self):
64                 if self.getNextServiceCB != None:
65                         newservice = self.getNextServiceCB()
66                         Log.i("newservice is %s" % newservice)
67                         if newservice:
68                                 self.playService(newservice)
69                                 return
70
71                 self.leavePlayerConfirmed([True, "quit"])
72
73         def playPrev(self):
74                 if self.getPrevServiceCB != None:
75                         newservice = self.getPrevServiceCB()
76                         Log.i("newservice is %s" % newservice)
77                         if newservice:
78                                 self.playService(newservice)
79
80                 self.leavePlayerConfirmed([True, "quit"])
81
82         def playAgain(self):
83                 print "playAgain"
84                 if self.state != self.STATE_IDLE:
85                         self.stopCurrent()
86                 self.play()
87
88         def playService(self, newservice):
89                 self.stopCurrent()
90                 self.service = newservice
91                 self.play()
92
93         def play(self):
94                 text = self.service.getPath()
95                 text = text.split('/')[-1]
96                 Log.i("text=%s" % text)
97                 self.summaries.setText(text, 3)
98
99                 self.session.nav.playService(self.service)
100                 if self.shown:
101                         self.checkSkipShowHideLock()
102
103         def stopCurrent(self):
104                 print "stopCurrent"
105                 self.session.nav.stopService()
106
107         def showVideoInfo(self):
108                 if self.infoCallback != None:
109                         self.infoCallback(self.service)
110
111         def handleLeave(self, ask=True, error=False, title=_("Choose an action")):
112                 self.is_closing = True
113                 if ask:
114                         list = [(_("Close the player"), "quit"),
115                                         (_("Play this video again"), "playAgain")]
116
117                         if self.getNextServiceCB != None:
118                                 list.append((_("Play the next video"), "playnext"))
119                         if self.getPrevServiceCB != None:
120                                 list.append((_("Play the previous video"), "playprev"))
121
122                         if error is False:
123                                 self.session.openWithCallback(self.leavePlayerConfirmed, ChoiceBox, title=title, list=list)
124                         else:
125                                 self.session.openWithCallback(self.leavePlayerConfirmed, ChoiceBox, title=_("This video cannot be played! Choose an action"), list=list)
126                 else:
127                         self.leavePlayerConfirmed([True, "quit"])
128
129         def leavePlayer(self):
130                 self.handleLeave()
131
132         def leavePlayerConfirmed(self, answer):
133                 answer = answer and answer[1]
134                 if answer == "quit":
135                         self.close()
136
137                 elif answer == "playnext":
138                         self.playNext()
139
140                 elif answer == "playprev":
141                         self.playPrev()
142
143                 elif answer == "playAgain":
144                         self.playAgain()
145
146         def doEofInternal(self, playing):
147                 if not self.execing:
148                         return
149                 if not playing :
150                         return
151                 self.handleLeave(title=_("End of video. Close the Player?"))