diff --git a/resources/lib/playlist_func.py b/resources/lib/playlist_func.py index c548dea0..3d2068fd 100644 --- a/resources/lib/playlist_func.py +++ b/resources/lib/playlist_func.py @@ -376,6 +376,27 @@ class PlaylistItem(object): and kodi_sub_stream != self.current_kodi_sub_stream)): self.on_kodi_subtitle_stream_change(kodi_sub_stream, sub_enabled) + def on_plex_stream_change(self, plex_data): + """ + Call this method if Plex Companion wants to change streams + """ + if 'audioStreamID' in plex_data: + plex_index = int(plex_data['audioStreamID']) + kodi_index = self.kodi_stream_index(plex_index, 'audio') + app.APP.player.setAudioStream(kodi_index) + self.current_kodi_audio_stream = kodi_index + if 'subtitleStreamID' in plex_data: + plex_index = int(plex_data['subtitleStreamID']) + if plex_index == 0: + app.APP.player.showSubtitles(False) + kodi_index = False + else: + kodi_index = self.kodi_stream_index(plex_index, 'subtitle') + if kodi_index: + app.APP.player.setSubtitleStream(kodi_index) + app.APP.player.showSubtitles(True) + self.current_kodi_sub_stream = kodi_index + def playlist_item_from_kodi(kodi_item): """ diff --git a/resources/lib/plex_companion.py b/resources/lib/plex_companion.py index fb55a637..e6400dd8 100644 --- a/resources/lib/plex_companion.py +++ b/resources/lib/plex_companion.py @@ -191,19 +191,7 @@ class PlexCompanion(backgroundthread.KillableThread): playqueue = PQ.get_playqueue_from_type( v.KODI_PLAYLIST_TYPE_FROM_PLEX_TYPE[data['type']]) pos = js.get_position(playqueue.playlistid) - if 'audioStreamID' in data: - index = playqueue.items[pos].kodi_stream_index( - data['audioStreamID'], 'audio') - app.APP.player.setAudioStream(index) - elif 'subtitleStreamID' in data: - if data['subtitleStreamID'] == '0': - app.APP.player.showSubtitles(False) - else: - index = playqueue.items[pos].kodi_stream_index( - data['subtitleStreamID'], 'subtitle') - app.APP.player.setSubtitleStream(index) - else: - LOG.error('Unknown setStreams command: %s', data) + playqueue.items[pos].on_plex_stream_change(data) @staticmethod def _process_refresh(data):