1 from Components.config import config, ConfigSubsection, ConfigInteger, ConfigSelection, getConfigListEntry
2 from Components.ConfigList import ConfigListScreen
3 from Components.ActionMap import NumberActionMap
4 from Components.Button import Button
5 from Components.Label import Label,MultiColorLabel
6 from Components.SystemInfo import SystemInfo
7 from enigma import eTimer
8 from Plugins.Plugin import PluginDescriptor
9 from Screens import Standby
10 from Screens.Screen import Screen
11 from __init__ import _
12 import NavigationInstance
14 config.plugins.AudioRestart = ConfigSubsection()
15 config.plugins.AudioRestart.restartSelection = ConfigSelection( default = "disabled", choices = [("disabled", _("disabled")), ("restart", _("after restart")), ("standby", _("after standby")), ("both", _("after restart/standby"))])
16 config.plugins.AudioRestart.restartDelay = ConfigInteger(default = 5, limits = (0,30))
18 PLUGIN_BASE = "AudioRestart"
19 PLUGIN_VERSION = "0.1"
23 self.activateTimer = eTimer()
24 self.activateTimer.callback.append(self.restartAudio)
25 if config.plugins.AudioRestart.restartSelection.value in ["standby", "both"]:
26 config.misc.standbyCounter.addNotifier(self.enterStandby, initial_call = False)
27 if config.plugins.AudioRestart.restartSelection.value in ["restart", "both"]:
30 def enterStandby(self,configElement):
31 Standby.inStandby.onClose.append(self.endStandby)
37 self.intDelay = config.plugins.AudioRestart.restartDelay.value*1000
38 print "[AudioSync] audio restart in ",self.intDelay
39 self.activateTimer.start(self.intDelay, True)
41 def restartAudio(self):
42 self.activateTimer.stop()
43 if self.audioIsAC3() and SystemInfo["CanDownmixAC3"] and (config.av.downmix_ac3.value == False):
44 config.av.downmix_ac3.value = True
45 config.av.downmix_ac3.save()
46 config.av.downmix_ac3.value = False
47 config.av.downmix_ac3.save()
48 print "[AudioSync] audio restarted"
51 service = NavigationInstance.instance.getCurrentService()
52 audioTracks = service and service.audioTracks()
54 if audioTracks is not None:
55 n = audioTracks and audioTracks.getNumberOfTracks() or 0
57 selectedAudioIndex = audioTracks.getCurrentTrack()
58 if selectedAudioIndex <= n:
59 trackInfo = audioTracks.getTrackInfo(selectedAudioIndex)
60 description = trackInfo.getDescription()
61 if (description.find("AC3") != -1 or description.find("AC-3") != -1) or description.find("DTS") != -1:
65 class AudioRestartSetup(ConfigListScreen, Screen):
67 <screen position="center,center" size="560,400" title="Audio Restart Setup">
68 <ePixmap pixmap="~/img/button-red.png" position="0,0" zPosition="0" size="140,40" transparent="1" alphatest="on" />
69 <ePixmap pixmap="~/img/button-green.png" position="140,0" zPosition="0" size="140,40" transparent="1" alphatest="on" />
70 <ePixmap pixmap="~/img/button-yellow.png" position="280,0" zPosition="0" size="140,40" transparent="1" alphatest="on" />
71 <ePixmap pixmap="~/img/button-blue.png" position="420,0" zPosition="0" size="140,40" transparent="1" alphatest="on" />
72 <widget name="key_red" position="0,0" zPosition="1" size="140,40"
73 font="Regular;20" valign="center" halign="center" backgroundColor="#9f1313" transparent="1"
74 shadowColor="#000000" shadowOffset="-1,-1" />
75 <widget name="key_green" position="140,0" zPosition="1" size="140,40"
76 font="Regular;20" valign="center" halign="center" backgroundColor="#1f771f" transparent="1"
77 shadowColor="#000000" shadowOffset="-1,-1" />
78 <widget name="key_yellow" position="280,0" zPosition="1" size="140,40"
79 font="Regular;20" valign="center" halign="center" backgroundColor="#a08500" transparent="1"
80 shadowColor="#000000" shadowOffset="-1,-1" />
81 <widget name="key_blue" position="420,0" zPosition="1" size="140,40"
82 font="Regular;20" valign="center" halign="center" backgroundColor="#18188b" transparent="1"
83 shadowColor="#000000" shadowOffset="-1,-1" />
84 <widget name="config" position="10,40" size="540,320" scrollbarMode="showOnDemand" />
85 <widget name="PluginInfo" position="10,370" size="540,20" zPosition="4" font="Regular;18" foregroundColor="#cccccc" />
88 def __init__(self, session, plugin_path):
89 Screen.__init__(self, session)
91 # Lets get a list of elements for the config list
93 getConfigListEntry(_("Restart audio"), config.plugins.AudioRestart.restartSelection),
94 getConfigListEntry(_("Restart audio delay (in sec)"), config.plugins.AudioRestart.restartDelay)
97 ConfigListScreen.__init__(self, self.list)
99 self["config"].list = self.list
101 self.skin_path = plugin_path
104 self["PluginInfo"] = Label(_("Plugin: %(plugin)s , Version: %(version)s") %dict(plugin=PLUGIN_BASE,version=PLUGIN_VERSION))
107 self["key_red"] = Button(_("Cancel"))
108 self["key_green"] = Button(_("Save"))
109 self["key_yellow"] = Button(_(" "))
110 self["key_blue"] = Button(" ")
112 self["setupActions"] = NumberActionMap(["SetupActions", "ColorActions"],
115 "cancel": self.cancel,
127 for x in self["config"].list:
131 def sessionstart(reason, **kwargs):
135 def setup(session, **kwargs):
137 session.open(AudioRestartSetup, plugin_path)
139 def Plugins(path,**kwargs):
142 pluginList = [ PluginDescriptor(name=_("Audio restart Setup"), description=_("Setup for the AudioRestart Plugin"), icon = "AudioRestart.png", where = PluginDescriptor.WHERE_PLUGINMENU, fnc=setup)]
143 if config.plugins.AudioRestart.restartSelection.value <> "disabled":
144 pluginAutoStart = PluginDescriptor(name="Audio restart", description = _("Restart audio"), where=PluginDescriptor.WHERE_SESSIONSTART, fnc = sessionstart)
145 pluginList.append(pluginAutoStart)