/* Messages from master to slave to ask for action or information */ private void OnMessageFromMaster(MediaPlayerMessage msg) { IMediaPlayerContainer container; IUiManager uiManager; IAudioManager _audio; switch (msg.Action) { case "subtitles-on": try { result?.SetSubtitles(true); } catch { if (_core.TryGetUiManager(out uiManager)) { uiManager.Toast(new Translator("ScreenCast").Translate("Subtitles not found for this media")); } } break; case "subtitles-off": try { result?.SetSubtitles(false); } catch { if (_core.TryGetUiManager(out uiManager)) { uiManager.Toast(translator.Translate("Subtitles not found for this media")); } } break; case "play": if (_core.TryGetMediaPlayerContainer(out container)) { if (!string.IsNullOrEmpty(msg.Mrl)) { result = container.Play(new MediaRequest(new IptvMedia() { URL = msg.Mrl + " " + msg.Extras }) { FullscreenMode = FullscreenMode.FullscreenOnly }); AttachToMediaResponse(result); } else { result.Play(); } } break; case "pause": if (_core.TryGetMediaPlayerContainer(out container)) { result.Pause(); } break; case "stop": if (_core.TryGetMediaPlayerContainer(out container)) { result.Stop(); } break; case "previous": if (_core.TryGetMediaPlayerContainer(out container)) { result.Previous(); } break; case "next": if (_core.TryGetMediaPlayerContainer(out container)) { result.Next(); } break; case "volume": if (_core.TryGetMediaPlayerContainer(out container)) { if (_core.TryGetAudioManager(out _audio)) { _audio.SpeakersVolume = (int)Math.Round(msg.Volume * 100f); } } break; case "getvolume": if (_core.TryGetMediaPlayerContainer(out container)) { if (_core.TryGetAudioManager(out _audio)) { Task.Run(() => BoundTerminal.Send("mediaplayer", new MediaPlayerMessage { Action = "getvolume", Volume = _audio.SpeakersVolume / 100f })); } } break; default: break; } }
/* Messages sent from slave to master to inform about the current state */ private void OnMessageFromSlave(MediaPlayerMessage msg) { switch (msg.Action) { case "playing": Playing?.Invoke(this, null); break; case "stopped": Stopped?.Invoke(this, null); break; case "error": Error?.Invoke(this, null); break; case "ended": Ended?.Invoke(this, null); break; case "now-playing": NowPlaying?.Invoke(this, msg.Mrl); break; case "position": PositionChanged?.Invoke(this, msg.Position); break; case "paused": Paused?.Invoke(this, null); break; case "opening": Opening?.Invoke(this, null); break; case "seekable-changed": //TODO: Need to be able to send bool break; case "pausable-changed": //TODO: Need to be able to send bool break; case "volume": case "getvolume": Volume = (int)Math.Round(msg.Volume * 100f); VolumeChanged?.Invoke(this, null); break; case "has-subtitles-changed": //TODO: Need to be able to send bool break; case "has-next-changed": //TODO: Need to be able to send bool break; case "duration-changed": //TODO: Need to be able to send bool break; default: break; } }