Rework OSD message types and splitting code

This commit is contained in:
Etoh 2017-08-12 18:39:50 +01:00
parent 8415c93b04
commit 671f40a737
7 changed files with 207 additions and 94 deletions

View File

@ -36,14 +36,24 @@ function clear_chat()
chat_log = {} chat_log = {}
end end
local secondary_osd = "" local alert_osd = ""
local last_secondary_osd_time = nil local last_alert_osd_time = nil
local secondary_osd_mood = MOOD_NEUTRAL local alert_osd_mood = MOOD_NEUTRAL
function set_secondary_osd(osd_message, mood) local notification_osd = ""
secondary_osd = osd_message local last_notification_osd_time = nil
last_secondary_osd_time = mp.get_time() local notification_osd_mood = MOOD_NEUTRAL
secondary_osd_mood = mood
function set_alert_osd(osd_message, mood)
alert_osd = osd_message
last_alert_osd_time = mp.get_time()
alert_osd_mood = mood
end
function set_notification_osd(osd_message, mood)
notification_osd = osd_message
last_notification_osd_time = mp.get_time()
notification_osd_mood = mood
end end
function add_chat(chat_message, mood) function add_chat(chat_message, mood)
@ -68,32 +78,28 @@ end
function chat_update() function chat_update()
ass = assdraw.ass_new() ass = assdraw.ass_new()
local chat_ass = '' local chat_ass = ''
if opts['chatOutputMode'] == CHAT_MODE_CHATROOM then local rowsAdded = 0
local to_add = ''
local incrementRow = 0
if opts['chatOutputMode'] == CHAT_MODE_CHATROOM and chat_log ~= {} then
local timedelta = mp.get_time() - last_chat_time local timedelta = mp.get_time() - last_chat_time
if timedelta >= 7 then if timedelta >= opts['chatTimeout'] then
clear_chat() clear_chat()
end end
end end
if secondary_osd ~= "" then rowsAdded,to_add = process_alert_osd()
if mp.get_time() - last_secondary_osd_time < 5 and last_secondary_osd_time ~= nil then if to_add ~= nil and to_add ~= "" then
local xpos = opts['chatLeftMargin'] chat_ass = to_add
local ypos = opts['chatTopMargin']+(0*opts['chatOutputFontSize'])
local messageString = '('..secondary_osd..')'
local messageColour
if secondary_osd_mood == MOOD_NEUTRAL then
messageColour = "{\\1c&HFFFFFF}"
elseif secondary_osd_mood == MOOD_BAD then
messageColour = "{\\1c&H0000FF}"
elseif secondary_osd_mood == MOOD_GOOD then
messageColour = "{\\1c&H00FF00}"
end
messageString = messageColour..messageString
chat_ass = format_chatroom(xpos,ypos,messageString)
end
end end
incrementRow,to_add = process_notification_osd(rowsAdded)
rowsAdded = rowsAdded + incrementRow
if to_add ~= nil and to_add ~= "" then
chat_ass = chat_ass .. to_add
end
if #chat_log > 0 then if #chat_log > 0 then
for i = 1, #chat_log do for i = 1, #chat_log do
local to_add = process_chat_item(i) local to_add = process_chat_item(i,rowsAdded)
if to_add ~= nil and to_add ~= "" then if to_add ~= nil and to_add ~= "" then
chat_ass = chat_ass .. to_add chat_ass = chat_ass .. to_add
end end
@ -111,11 +117,69 @@ function chat_update()
mp.set_osd_ass(CANVAS_WIDTH,CANVAS_HEIGHT, ass.text) mp.set_osd_ass(CANVAS_WIDTH,CANVAS_HEIGHT, ass.text)
end end
function process_chat_item(i) function process_alert_osd()
local rowsCreated = 0
local stringToAdd = ""
if alert_osd ~= "" and mp.get_time() - last_alert_osd_time < opts['alertTimeout'] and last_alert_osd_time ~= nil then
local xpos = opts['chatLeftMargin']
local ypos
local messageColour
if alert_osd_mood == MOOD_NEUTRAL then
messageColour = "{\\1c&HFFFFFF}"
elseif alert_osd_mood == MOOD_BAD then
messageColour = "{\\1c&H0000FF}"
elseif alert_osd_mood == MOOD_GOOD then
messageColour = "{\\1c&H00FF00}"
end
local messageString
local startRow = 0
local stringLeftToProccess = alert_osd
while stringLeftToProccess ~= '' and stringLeftToProccess ~= nil do
local toDisplay
ypos = opts['chatTopMargin'] + ((startRow+rowsCreated)*opts['chatOutputFontSize'])
toDisplay, stringLeftToProccess = trim_string(stringLeftToProccess,opts['chatSplitMessageAt'])
rowsCreated = rowsCreated + 1
messageString = messageColour..toDisplay
if stringToAdd ~= "" then
stringToAdd = stringToAdd .. format_chatroom(xpos,ypos,messageString)
else
stringToAdd = format_chatroom(xpos,ypos,messageString)
end
end
end
return rowsCreated, stringToAdd
end
function process_notification_osd(startRow)
local rowsCreated = 0
local stringToAdd = ""
if notification_osd ~= "" and mp.get_time() - last_notification_osd_time < opts['alertTimeout'] and last_notification_osd_time ~= nil then
local xpos = opts['chatLeftMargin']
local messageColour
messageColour = "{\\1c&HFFFF00}"
local messageString
local startRow = startRow
local stringLeftToProccess = notification_osd
while stringLeftToProccess ~= '' and stringLeftToProccess ~= nil do
local toDisplay
local ypos = opts['chatTopMargin'] + ((startRow+rowsCreated)*opts['chatOutputFontSize'])
toDisplay, stringLeftToProccess = trim_string(stringLeftToProccess,opts['chatSplitMessageAt'])
rowsCreated = rowsCreated + 1
messageString = messageColour..toDisplay
if stringToAdd ~= "" then
stringToAdd = stringToAdd .. format_chatroom(xpos,ypos,messageString)
else
stringToAdd =format_chatroom(xpos,ypos,messageString)
end
end
end
return rowsCreated, stringToAdd
end
function process_chat_item(i, rowsAdded)
if opts['chatOutputMode'] == CHAT_MODE_CHATROOM then if opts['chatOutputMode'] == CHAT_MODE_CHATROOM then
return process_chat_item_chatroom(i) return process_chat_item_chatroom(i, rowsAdded)
elseif opts['chatOutputMode'] == CHAT_MODE_CHATROOM then
return process_chat_item_subtitle(i)
elseif opts['chatOutputMode'] == CHAT_MODE_SCROLLING then elseif opts['chatOutputMode'] == CHAT_MODE_SCROLLING then
return process_chat_item_scrolling(i) return process_chat_item_scrolling(i)
end end
@ -129,7 +193,7 @@ function process_chat_item_scrolling(i)
if text ~= '' then if text ~= '' then
local roughlen = string.len(text) * opts['chatOutputFontSize'] * 1.5 local roughlen = string.len(text) * opts['chatOutputFontSize'] * 1.5
if xpos > (-1*roughlen) then if xpos > (-1*roughlen) then
local row = chat_log[i].row local row = chat_log[i].row-1+opts['scrollingFirstRowOffset']
local ypos = opts['chatTopMargin']+(row * opts['chatOutputFontSize']) local ypos = opts['chatTopMargin']+(row * opts['chatOutputFontSize'])
return format_scrolling(xpos,ypos,text) return format_scrolling(xpos,ypos,text)
else else
@ -138,11 +202,12 @@ function process_chat_item_scrolling(i)
end end
end end
function process_chat_item_chatroom(i) function process_chat_item_chatroom(i, startRow)
local text = chat_log[i].text local text = chat_log[i].text
if text ~= '' then if text ~= '' then
xpos = opts['chatLeftMargin'] local xpos = opts['chatLeftMargin']
ypos = opts['chatTopMargin']+(i*opts['chatOutputFontSize']) local rowNumber = i+startRow-1
local ypos = opts['chatTopMargin']+(rowNumber*opts['chatOutputFontSize'])
local timecreated = chat_log[i].timecreated local timecreated = chat_log[i].timecreated
local timedelta = 200 * (mp.get_time() - timecreated) local timedelta = 200 * (mp.get_time() - timecreated)
@ -178,30 +243,50 @@ mp.register_script_message('chat', function(e)
add_chat(e) add_chat(e)
end) end)
mp.register_script_message('primary-osd-neutral', function(e) -- Chat OSD
mp.register_script_message('chat-osd-neutral', function(e)
add_chat(e,MOOD_NEUTRAL) add_chat(e,MOOD_NEUTRAL)
end) end)
mp.register_script_message('primary-osd-bad', function(e) mp.register_script_message('chat-osd-bad', function(e)
add_chat(e,MOOD_BAD) add_chat(e,MOOD_BAD)
end) end)
mp.register_script_message('primary-osd-good', function(e) mp.register_script_message('chat-osd-good', function(e)
add_chat(e,MOOD_GOOD) add_chat(e,MOOD_GOOD)
end) end)
mp.register_script_message('secondary-osd-neutral', function(e) -- Alert OSD
set_secondary_osd(e,MOOD_NEUTRAL)
mp.register_script_message('alert-osd-neutral', function(e)
set_alert_osd(e,MOOD_NEUTRAL)
end) end)
mp.register_script_message('secondary-osd-bad', function(e) mp.register_script_message('alert-osd-bad', function(e)
set_secondary_osd(e,MOOD_BAD) set_alert_osd(e,MOOD_BAD)
end) end)
mp.register_script_message('secondary-osd-good', function(e) mp.register_script_message('alert-osd-good', function(e)
set_secondary_osd(e,MOOD_GOOD) set_alert_osd(e,MOOD_GOOD)
end) end)
-- Notification OSD
mp.register_script_message('notification-osd-neutral', function(e)
set_notification_osd(e,MOOD_NEUTRAL)
end)
mp.register_script_message('notification-osd-bad', function(e)
set_notification_osd(e,MOOD_BAD)
end)
mp.register_script_message('notification-osd-good', function(e)
set_notification_osd(e,MOOD_GOOD)
end)
--
mp.register_script_message('set_syncplayintf_options', function(e) mp.register_script_message('set_syncplayintf_options', function(e)
set_syncplayintf_options(e) set_syncplayintf_options(e)
end) end)
@ -240,18 +325,24 @@ opts = {
['chatInputFontColor'] = "#000000", ['chatInputFontColor'] = "#000000",
['chatInputPosition'] = "Top", ['chatInputPosition'] = "Top",
['MaxChatMessageLength'] = 50, ['MaxChatMessageLength'] = 50,
['chatSplitMessageAt'] = 70,
['chatOutputFontFamily'] = 'sans serif', ['chatOutputFontFamily'] = 'sans serif',
['chatOutputFontSize'] = 50, ['chatOutputFontSize'] = 50,
['chatOutputFontWeight'] = 1, ['chatOutputFontWeight'] = 1,
['chatOutputFontUnderline'] = false, ['chatOutputFontUnderline'] = false,
['chatOutputFontColor'] = "#FFFFFF", ['chatOutputFontColor'] = "#FFFFFF",
['chatOutputMode'] = "Chatroom", ['chatOutputMode'] = "Chatroom",
['scrollingFirstRowOffset'] = 3,
-- Can be "Chatroom", "Subtitle" or "Scrolling" style -- Can be "Chatroom", "Subtitle" or "Scrolling" style
['chatMaxLines'] = 7, ['chatMaxLines'] = 7,
['chatTopMargin'] = 25, ['chatTopMargin'] = 25,
['chatLeftMargin'] = 20, ['chatLeftMargin'] = 20,
['chatBottomMargin'] = 30, ['chatBottomMargin'] = 30,
['chatDirectInput'] = true ['chatDirectInput'] = true,
--
['notificationTimeout'] = 3,
['alertTimeout'] = 5,
['chatTimeout'] = 7,
} }
function detect_platform() function detect_platform()
@ -439,9 +530,31 @@ function prev_utf8(str, pos)
return pos return pos
end end
function trim_input() function trim_string(line,maxCharacters)
-- Naive helper function to find the next UTF-8 character in 'str' after 'pos' -- Naive helper function to find the next UTF-8 character in 'str' after 'pos'
-- by skipping continuation bytes. Assumes 'str' contains valid UTF-8. -- by skipping continuation bytes. Assumes 'str' contains valid UTF-8.
local str = line
if str == nil or str == "" or str:len() <= maxCharacters then
return str, ""
end
local pos = 0
local oldPos = -1
local chars = 0
repeat
oldPos = pos
pos = next_utf8(str, pos)
chars = chars + 1
until pos == oldPos or chars > maxCharacters
return str:sub(1,pos-1), str:sub(pos)
end
function trim_input()
-- Naive helper function to find the next UTF-8 character in 'str' after 'pos'
-- by skipping continuation bytes. Assumes 'str' contains valid UTF-8.
local str = line local str = line
if str == nil or str == "" or str:len() <= opts['MaxChatMessageLength'] then if str == nil or str == "" or str:len() <= opts['MaxChatMessageLength'] then
return return

View File

@ -143,8 +143,8 @@ class SyncplayClient(object):
def initPlayer(self, player): def initPlayer(self, player):
self._player = player self._player = player
if not self._player.secondaryOSDSupported: if not self._player.alertOSDSupported:
constants.OSD_WARNING_MESSAGE_DURATION = constants.NO_SECONDARY_OSD_WARNING_DURATION constants.OSD_WARNING_MESSAGE_DURATION = constants.NO_ALERT_OSD_WARNING_DURATION
self.scheduleAskPlayer() self.scheduleAskPlayer()
self.__playerReady.callback(player) self.__playerReady.callback(player)
@ -790,7 +790,7 @@ class SyncplayClient(object):
allReadyMessage = getMessage("all-users-ready").format(self.userlist.readyUserCount()) allReadyMessage = getMessage("all-users-ready").format(self.userlist.readyUserCount())
autoplayingMessage = getMessage("autoplaying-notification").format(int(self.autoplayTimeLeft)) autoplayingMessage = getMessage("autoplaying-notification").format(int(self.autoplayTimeLeft))
countdownMessage = u"{}{}{}".format(allReadyMessage,self._player.osdMessageSeparator, autoplayingMessage) countdownMessage = u"{}{}{}".format(allReadyMessage,self._player.osdMessageSeparator, autoplayingMessage)
self.ui.showOSDMessage(countdownMessage, 1, secondaryOSD=True, mood=constants.MESSAGE_GOODNEWS) self.ui.showOSDMessage(countdownMessage, 1, OSDType=constants.OSD_ALERT, mood=constants.MESSAGE_GOODNEWS)
if self.autoplayTimeLeft <= 0: if self.autoplayTimeLeft <= 0:
self.setPaused(False) self.setPaused(False)
self.stopAutoplayCountdown() self.stopAutoplayCountdown()
@ -939,7 +939,7 @@ class SyncplayClient(object):
def _checkIfYouReAloneInTheRoom(self, OSDOnly): def _checkIfYouReAloneInTheRoom(self, OSDOnly):
if self._userlist.areYouAloneInRoom(): if self._userlist.areYouAloneInRoom():
self._ui.showOSDMessage(getMessage("alone-in-the-room"), constants.WARNING_OSD_MESSAGES_LOOP_INTERVAL, secondaryOSD=True, mood=constants.MESSAGE_BADNEWS) self._ui.showOSDMessage(getMessage("alone-in-the-room"), constants.WARNING_OSD_MESSAGES_LOOP_INTERVAL, OSDType=constants.OSD_ALERT, mood=constants.MESSAGE_BADNEWS)
if not OSDOnly: if not OSDOnly:
self._ui.showMessage(getMessage("alone-in-the-room"), True) self._ui.showMessage(getMessage("alone-in-the-room"), True)
if constants.SHOW_OSD_WARNINGS and not self._warnings["alone-in-the-room"]['timer'].running: if constants.SHOW_OSD_WARNINGS and not self._warnings["alone-in-the-room"]['timer'].running:
@ -990,7 +990,7 @@ class SyncplayClient(object):
messageMood = constants.MESSAGE_BADNEWS messageMood = constants.MESSAGE_BADNEWS
osdMessage = getMessage("not-all-ready").format(self._userlist.usersInRoomNotReady()) osdMessage = getMessage("not-all-ready").format(self._userlist.usersInRoomNotReady())
if osdMessage: if osdMessage:
self._ui.showOSDMessage(osdMessage, constants.WARNING_OSD_MESSAGES_LOOP_INTERVAL, secondaryOSD=True, mood=messageMood) self._ui.showOSDMessage(osdMessage, constants.WARNING_OSD_MESSAGES_LOOP_INTERVAL, OSDType=constants.OSD_ALERT, mood=messageMood)
def __displayMessageOnOSD(self, warningName, warningFunction): def __displayMessageOnOSD(self, warningName, warningFunction):
if constants.OSD_WARNING_MESSAGE_DURATION > self._warnings[warningName]["displayedFor"]: if constants.OSD_WARNING_MESSAGE_DURATION > self._warnings[warningName]["displayedFor"]:
@ -1361,10 +1361,10 @@ class UiManager(object):
def __init__(self, client, ui): def __init__(self, client, ui):
self._client = client self._client = client
self.__ui = ui self.__ui = ui
self.lastPrimaryOSDMessage = None self.lastNotificatinOSDMessage = None
self.lastPrimaryOSDEndTime = None self.lastNotificationOSDEndTime = None
self.lastSecondaryOSDMessage = None self.lastAlertOSDMessage = None
self.lastSecondaryOSDEndTime = None self.lastAlertOSDEndTime = None
self.lastError = "" self.lastError = ""
def setPlaylist(self, newPlaylist, newIndexFilename=None): def setPlaylist(self, newPlaylist, newIndexFilename=None):
@ -1385,14 +1385,14 @@ class UiManager(object):
def showChatMessage(self, username, userMessage): def showChatMessage(self, username, userMessage):
messageString = u"<{}> {}".format(username, userMessage) messageString = u"<{}> {}".format(username, userMessage)
if self._client._player.chatOSDSupported: if self._client._player.alertOSDSupported:
self._client._player.displayChatMessage(username,userMessage) self._client._player.displayChatMessage(username,userMessage)
else: else:
self.showOSDMessage(messageString, duration=constants.OSD_DURATION) self.showOSDMessage(messageString, duration=constants.OSD_DURATION)
self.__ui.showMessage(messageString) self.__ui.showMessage(messageString)
def showMessage(self, message, noPlayer=False, noTimestamp=False, secondaryOSD=False,mood=constants.MESSAGE_NEUTRAL): def showMessage(self, message, noPlayer=False, noTimestamp=False, OSDType=constants.OSD_NOTIFICATION,mood=constants.MESSAGE_NEUTRAL):
if not noPlayer: self.showOSDMessage(message, duration=constants.OSD_DURATION, secondaryOSD=secondaryOSD, mood=mood) if not noPlayer: self.showOSDMessage(message, duration=constants.OSD_DURATION, OSDType=OSDType, mood=mood)
self.__ui.showMessage(message, noTimestamp) self.__ui.showMessage(message, noTimestamp)
def updateAutoPlayState(self, newState): def updateAutoPlayState(self, newState):
@ -1401,28 +1401,28 @@ class UiManager(object):
def showUserList(self, currentUser, rooms): def showUserList(self, currentUser, rooms):
self.__ui.showUserList(currentUser, rooms) self.__ui.showUserList(currentUser, rooms)
def showOSDMessage(self, message, duration=constants.OSD_DURATION, secondaryOSD=False, mood=constants.MESSAGE_NEUTRAL): def showOSDMessage(self, message, duration=constants.OSD_DURATION, OSDType=constants.OSD_NOTIFICATION, mood=constants.MESSAGE_NEUTRAL):
autoplayConditionsMet = self._client.autoplayConditionsMet() autoplayConditionsMet = self._client.autoplayConditionsMet()
if secondaryOSD and not constants.SHOW_OSD_WARNINGS and not self._client.autoplayTimerIsRunning(): if OSDType == constants.OSD_ALERT and not constants.SHOW_OSD_WARNINGS and not self._client.autoplayTimerIsRunning():
return return
if not self._client._player: if not self._client._player:
return return
if constants.SHOW_OSD and self._client and self._client._player: if constants.SHOW_OSD and self._client and self._client._player:
if not self._client._player.secondaryOSDSupported: if not self._client._player.alertOSDSupported:
if secondaryOSD: if OSDType == constants.OSD_ALERT:
self.lastSecondaryOSDMessage = message self.lastAlertOSDMessage = message
if autoplayConditionsMet: if autoplayConditionsMet:
self.lastSecondaryOSDEndTime = time.time() + 1.0 self.lastAlertOSDEndTime = time.time() + 1.0
else: else:
self.lastSecondaryOSDEndTime = time.time() + constants.NO_SECONDARY_OSD_WARNING_DURATION self.lastAlertOSDEndTime = time.time() + constants.NO_ALERT_OSD_WARNING_DURATION
if self.lastPrimaryOSDEndTime and time.time() < self.lastPrimaryOSDEndTime: if self.lastNotificationOSDEndTime and time.time() < self.lastNotificationOSDEndTime:
message = u"{}{}{}".format(message, self._client._player.osdMessageSeparator, self.lastPrimaryOSDMessage) message = u"{}{}{}".format(message, self._client._player.osdMessageSeparator, self.lastNotificatinOSDMessage)
else: else:
self.lastPrimaryOSDMessage = message self.lastNotificatinOSDMessage = message
self.lastPrimaryOSDEndTime = time.time() + constants.OSD_DURATION self.lastNotificationOSDEndTime = time.time() + constants.OSD_DURATION
if self.lastSecondaryOSDEndTime and time.time() < self.lastSecondaryOSDEndTime: if self.lastAlertOSDEndTime and time.time() < self.lastAlertOSDEndTime:
message = u"{}{}{}".format(self.lastSecondaryOSDMessage, self._client._player.osdMessageSeparator, message) message = u"{}{}{}".format(self.lastAlertOSDMessage, self._client._player.osdMessageSeparator, message)
self._client._player.displayMessage(message, int(duration * 1000), secondaryOSD, mood) self._client._player.displayMessage(message, int(duration * 1000), OSDType, mood)
def setControllerStatus(self, username, isController): def setControllerStatus(self, username, isController):
self.__ui.setControllerStatus(username, isController) self.__ui.setControllerStatus(username, isController)

View File

@ -2,7 +2,7 @@
DEFAULT_PORT = 8999 DEFAULT_PORT = 8999
OSD_DURATION = 3.0 OSD_DURATION = 3.0
OSD_WARNING_MESSAGE_DURATION = 5.0 OSD_WARNING_MESSAGE_DURATION = 5.0
NO_SECONDARY_OSD_WARNING_DURATION = 13.0 NO_ALERT_OSD_WARNING_DURATION = 13.0
MPC_OSD_POSITION = 1 #Right corner, 1 for left MPC_OSD_POSITION = 1 #Right corner, 1 for left
MPLAYER_OSD_LEVEL = 1 MPLAYER_OSD_LEVEL = 1
UI_TIME_FORMAT = "[%X] " UI_TIME_FORMAT = "[%X] "
@ -216,10 +216,13 @@ FILEITEM_SWITCH_FILE_SWITCH = 1
FILEITEM_SWITCH_STREAM_SWITCH = 2 FILEITEM_SWITCH_STREAM_SWITCH = 2
PLAYLISTITEM_CURRENTLYPLAYING_ROLE = 3 PLAYLISTITEM_CURRENTLYPLAYING_ROLE = 3
MESSAGE_NEUTRAL = 0 MESSAGE_NEUTRAL = "neutral"
MESSAGE_BADNEWS = 1 MESSAGE_BADNEWS = "bad"
MESSAGE_GOODNEWS = 2 MESSAGE_GOODNEWS = "good"
MOOD_LIST = ["neutral","bad","good"]
OSD_NOTIFICATION = "notification" # Also known as PrimaryOSD
OSD_ALERT = "alert" # Also known as SecondaryOSD
OSD_CHAT = "chat"
SYNCPLAY_UPDATE_URL = u"http://syncplay.pl/checkforupdate?{}" # Params SYNCPLAY_UPDATE_URL = u"http://syncplay.pl/checkforupdate?{}" # Params
SYNCPLAY_DOWNLOAD_URL = "http://syncplay.pl/download/" SYNCPLAY_DOWNLOAD_URL = "http://syncplay.pl/download/"

View File

@ -306,7 +306,7 @@ class MpcHcApi:
class MPCHCAPIPlayer(BasePlayer): class MPCHCAPIPlayer(BasePlayer):
speedSupported = False speedSupported = False
secondaryOSDSupported = False alertOSDSupported = False
customOpenDialog = False customOpenDialog = False
chatOSDSupported = False chatOSDSupported = False
osdMessageSeparator = "; " osdMessageSeparator = "; "
@ -396,7 +396,7 @@ class MPCHCAPIPlayer(BasePlayer):
def openFile(self, filePath, resetPosition=False): def openFile(self, filePath, resetPosition=False):
self._mpcApi.openFile(filePath) self._mpcApi.openFile(filePath)
def displayMessage(self, message, duration = (constants.OSD_DURATION*1000), secondaryOSD=False, mood=constants.MESSAGE_NEUTRAL): def displayMessage(self, message, duration = (constants.OSD_DURATION*1000), OSDType=constants.OSD_NOTIFICATION, mood=constants.MESSAGE_NEUTRAL):
self._mpcApi.sendOsd(message, constants.MPC_OSD_POSITION, duration) self._mpcApi.sendOsd(message, constants.MPC_OSD_POSITION, duration)
@retry(MpcHcApi.PlayerNotReadyException, constants.MPC_MAX_RETRIES, constants.MPC_RETRY_WAIT_TIME, 1) @retry(MpcHcApi.PlayerNotReadyException, constants.MPC_MAX_RETRIES, constants.MPC_RETRY_WAIT_TIME, 1)

View File

@ -10,8 +10,8 @@ import os, sys
class MplayerPlayer(BasePlayer): class MplayerPlayer(BasePlayer):
speedSupported = True speedSupported = True
customOpenDialog = False customOpenDialog = False
#secondaryOSDSupported = False # TODO: Make conditional #chatOSDSupported = False # TODO: Make conditional
secondaryOSDSupported = True aletOSDSupported = True
chatOSDSupported = False chatOSDSupported = False
osdMessageSeparator = "; " osdMessageSeparator = "; "
@ -89,18 +89,14 @@ class MplayerPlayer(BasePlayer):
def _getProperty(self, property_): def _getProperty(self, property_):
self._listener.sendLine("get_property {}".format(property_)) self._listener.sendLine("get_property {}".format(property_))
def displayMessage(self, message, duration=(constants.OSD_DURATION * 1000), secondaryOSD=False, mood=constants.MESSAGE_NEUTRAL): def displayMessage(self, message, duration=(constants.OSD_DURATION * 1000), OSDType=constants.OSD_NOTIFICATION, mood=constants.MESSAGE_NEUTRAL):
moodString = constants.MOOD_LIST[mood] messageString = self._sanitizeText(message.replace("\\n", "<NEWLINE>")).replace("<NEWLINE>", "\\n")
self._listener.sendLine(
u'script-message-to syncplayintf {}-osd-{} "{}"'.format(OSDType,mood, messageString))
if not secondaryOSD and self._client.chatIsEnabled(): # TODO: Add check to ensure it is in 'chatroom' mode return
max_message_length = 3+constants.MAX_USERNAME_LENGTH+constants.MAX_CHAT_MESSAGE_LENGTH
messageStrings = utils.splitText(message,max_message_length) # TODO: Support legacy displayMessage for versiosn that don't support syncplayintf.lua
for messageString in messageStrings:
self._listener.sendLine(u'script-message-to syncplayintf primary-osd-{} "{}"'.format(moodString,messageString))
return
if secondaryOSD:
messageString = self._sanitizeText(message.replace("\\n", "<NEWLINE>")).replace("<NEWLINE>", "\\n")
self._listener.sendLine(u'script-message-to syncplayintf secondary-osd-{} "{}"'.format(moodString,messageString))
message = self._sanitizeText(message.replace("\\n","<NEWLINE>")).replace("<NEWLINE>","\\n") message = self._sanitizeText(message.replace("\\n","<NEWLINE>")).replace("<NEWLINE>","\\n")
#self._listener.sendLine(u'{} "{!s}" {} {}'.format(self.OSD_QUERY, message, duration, constants.MPLAYER_OSD_LEVEL).encode('utf-8')) #self._listener.sendLine(u'{} "{!s}" {} {}'.format(self.OSD_QUERY, message, duration, constants.MPLAYER_OSD_LEVEL).encode('utf-8'))

View File

@ -110,6 +110,7 @@ class OldMpvPlayer(MpvPlayer):
class NewMpvPlayer(OldMpvPlayer): class NewMpvPlayer(OldMpvPlayer):
lastResetTime = None lastResetTime = None
lastMPVPositionUpdate = None lastMPVPositionUpdate = None
alertOSDSupported = True
chatOSDSupported = True chatOSDSupported = True
def setPaused(self, value): def setPaused(self, value):

View File

@ -15,8 +15,8 @@ from syncplay.messages import getMessage
class VlcPlayer(BasePlayer): class VlcPlayer(BasePlayer):
speedSupported = True speedSupported = True
customOpenDialog = False customOpenDialog = False
secondaryOSDSupported = True chatOSDSupported = True
chatOSDSupported = False alertOSDSupported = False
osdMessageSeparator = "; " osdMessageSeparator = "; "
RE_ANSWER = re.compile(constants.VLC_ANSWER_REGEX) RE_ANSWER = re.compile(constants.VLC_ANSWER_REGEX)