Added remote control - audio and subtitle streams

Fix the index of streams to properly reflect the correct ones.
This commit is contained in:
angelblue05 2015-08-05 23:30:33 -05:00
parent c7c35fd442
commit abe60aa3b8
4 changed files with 50 additions and 13 deletions

View file

@ -21,8 +21,7 @@ class DownloadUtils():
clientInfo = ClientInformation()
addonName = clientInfo.getAddonName()
addonId = clientInfo.getAddonId()
addon = xbmcaddon.Addon(id=addonId)
addon = xbmcaddon.Addon()
WINDOW = xbmcgui.Window(10000)
# Requests session
@ -79,6 +78,7 @@ class DownloadUtils():
"GoHome,PageUp,NextLetter,GoToSearch,"
"GoToSettings,PageDown,PreviousLetter,TakeScreenshot,"
"VolumeUp,VolumeDown,ToggleMute,SendString,DisplayMessage,"
"SetAudioStreamIndex,SetSubtitleStreamIndex,"
"Mute,Unmute,SetVolume,"
"Play,Playstate,PlayNext"
@ -183,7 +183,6 @@ class DownloadUtils():
# Replace for the real values and append api_key
url = url.replace("{server}", self.server, 1)
url = url.replace("{UserId}", self.userId, 1)
#url = "%s&api_key=%s" % (url, self.token)
self.logMsg("URL: %s" % url, 2)
# Prepare request
@ -293,7 +292,7 @@ class DownloadUtils():
if r.headers['X-Application-Error-Code'] == "ParentalControl":
# Parental control - access restricted
WINDOW.setProperty("Server_status", "restricted")
xbmcgui.Dialog().notification("Emby server", "Access restricted.", xbmcgui.NOTIFICATION_ERROR, time=5000)
xbmcgui.Dialog().notification("Emby server", "Access restricted.", xbmcgui.NOTIFICATION_ERROR, icon="special://home/addons/plugin.video.emby/icon.png", time=5000)
return False
if (status == "401") or (status == "Auth"):
@ -303,7 +302,7 @@ class DownloadUtils():
# Tell UserClient token has been revoked.
WINDOW.setProperty("Server_status", "401")
self.logMsg("HTTP Error: %s" % e, 0)
xbmcgui.Dialog().notification("Error connecting", "Unauthorized.", xbmcgui.NOTIFICATION_ERROR)
xbmcgui.Dialog().notification("Error connecting", "Unauthorized.", xbmcgui.NOTIFICATION_ERROR, icon="special://home/addons/plugin.video.emby/icon.png")
return 401
elif (r.status_code == 301) or (r.status_code == 302):

View file

@ -147,7 +147,7 @@ class PlaybackUtils():
WINDOW.setProperty(playurl+"type", result.get("Type"))
WINDOW.setProperty(playurl+"item_id", id)
mediaSources = result.get("MediaSources")
'''mediaSources = result.get("MediaSources")
if(mediaSources != None):
mediaStream = mediaSources[0].get('MediaStreams')
defaultsubs = ""
@ -161,7 +161,7 @@ class PlaybackUtils():
if mediaSources[0].get('DefaultAudioStreamIndex') != None:
WINDOW.setProperty(playurl+"AudioStreamIndex", str(mediaSources[0].get('DefaultAudioStreamIndex')))
if mediaSources[0].get('DefaultSubtitleStreamIndex') != None:
WINDOW.setProperty(playurl+"SubtitleStreamIndex", str(mediaSources[0].get('DefaultSubtitleStreamIndex')))
WINDOW.setProperty(playurl+"SubtitleStreamIndex", str(mediaSources[0].get('DefaultSubtitleStreamIndex')))'''
#launch the playback - only set the listitem props if we're not using the setresolvedurl approach
if setup == "service":

View file

@ -176,6 +176,18 @@ class Player( xbmc.Player ):
volume = result.get(u'result').get(u'volume')
muted = result.get(u'result').get(u'muted')
# Get current audio and subtitles track
track_query = '{"jsonrpc": "2.0", "method": "Player.GetProperties", "params": {"playerid":1,"properties": ["currentsubtitle","currentaudiostream"]} , "id": 1}'
result = xbmc.executeJSONRPC(track_query)
result = json.loads(result)
indexAudio = result['result']['currentaudiostream']['index']
indexSubs = result['result']['currentsubtitle']['index']
# Convert back into an Emby index
audioTracks = len(xbmc.Player().getAvailableAudioStreams())
indexAudio = indexAudio + 1
indexSubs = indexSubs + audioTracks + 1
postdata = {
'QueueableMediaTypes': "Video",
'CanSeek': True,
@ -190,11 +202,17 @@ class Player( xbmc.Player ):
if playTime:
postdata['PositionTicks'] = int(playTime * 10000000)
if audioindex:
if audioindex == indexAudio:
postdata['AudioStreamIndex'] = audioindex
else:
postdata['AudioStreamIndex'] = indexAudio
data['AudioStreamIndex'] = indexAudio
if subtitleindex:
if subtitleindex == indexSubs:
postdata['SubtitleStreamIndex'] = subtitleindex
else:
postdata['SubtitleStreamIndex'] = indexSubs
data['SubtitleStreamIndex'] = indexSubs
postdata = json.dumps(postdata)
self.logMsg("Report: %s" % postdata, 2)
@ -267,6 +285,13 @@ class Player( xbmc.Player ):
volume = result.get(u'result').get(u'volume')
muted = result.get(u'result').get(u'muted')
# Get the current audio track and subtitles
track_query = '{"jsonrpc": "2.0", "method": "Player.GetProperties", "params": {"playerid":1,"properties": ["currentsubtitle","currentaudiostream"]} , "id": 1}'
result = xbmc.executeJSONRPC(track_query)
result = json.loads(result)
indexAudio = result['result']['currentaudiostream']['index']
indexSubs = result['result']['currentsubtitle']['index']
seekTime = xbmc.Player().getTime()
url = "{server}/mediabrowser/Sessions/Playing"
@ -283,9 +308,14 @@ class Player( xbmc.Player ):
if audioindex:
postdata['AudioStreamIndex'] = audioindex
else:
postdata['AudioStreamIndex'] = indexAudio + 1
if subtitleindex:
postdata['SubtitleStreamIndex'] = subtitleindex
else:
audioTracks = len(xbmc.Player().getAvailableAudioStreams())
postdata['SubtitleStreamIndex'] = indexSubs + audioTracks + 1
# Post playback to server
self.logMsg("Sending POST play started.", 1)
@ -297,8 +327,8 @@ class Player( xbmc.Player ):
'item_id': item_id,
'refresh_id': refresh_id,
'currentfile': currentFile,
'AudioStreamIndex': audioindex,
'SubtitleStreamIndex': subtitleindex,
'AudioStreamIndex': postdata['AudioStreamIndex'],
'SubtitleStreamIndex': postdata['SubtitleStreamIndex'],
'playmethod': playMethod,
'Type': itemType,
'currentPosition': int(seekTime)

View file

@ -96,7 +96,7 @@ class WebSocketThread(threading.Thread):
xbmc.executebuiltin("Dialog.Close(all,true)")
xbmc.executebuiltin("XBMC.Notification(Playlist: Added %s items to Playlist,)" % len(itemIds))
PlaybackUtils().PLAYAllItems(itemIds, startPositionTicks)
# Don't think this is being used.
elif "PlayNext" in playCommand:
xbmc.executebuiltin("XBMC.Notification(Playlist: Added %s items to Playlist,)" % len(itemIds))
playlist = PlaybackUtils().AddToPlaylist(itemIds)
@ -155,7 +155,7 @@ class WebSocketThread(threading.Thread):
command = data['Name']
arguments = data.get("Arguments")
if command in ('Mute', 'Unmute', 'SetVolume'):
if command in ('Mute', 'Unmute', 'SetVolume', 'SetSubtitleStreamIndex', 'SetAudioStreamIndex'):
# These commands need to be reported back
if command == "Mute":
xbmc.executebuiltin('Mute')
@ -164,6 +164,14 @@ class WebSocketThread(threading.Thread):
elif command == "SetVolume":
volume = arguments['Volume']
xbmc.executebuiltin('SetVolume(%s[,showvolumebar])' % volume)
elif command == "SetSubtitleStreamIndex":
# Emby merges audio and subtitle index together
audioTracks = len(xbmc.Player().getAvailableAudioStreams())
index = int(arguments['Index']) - audioTracks
xbmc.Player().setSubtitleStream(index - 1)
elif command == "SetAudioStreamIndex":
index = int(arguments['Index'])
xbmc.Player().setAudioStream(index - 1)
# Report playback
WINDOW.setProperty('commandUpdate', "true")