/* Slave attaches to media response's events and communicates every change to it's bound master.
  */
 void AttachToMediaResponse(IMediaResponse result)
 {
     result.Playing             += Result_Playing;
     result.Ended               += Result_Ended;
     result.Stopped             += Result_Stopped;
     result.Error               += Result_Error;
     result.NowPlaying          += Result_NowPlaying;
     result.PositionChanged     += Result_PositionChanged;
     result.Paused              += Result_Paused;
     result.Opening             += Result_Opening;
     result.IsSeekableChanged   += Result_IsSeekableChanged;
     result.IsPausableChanged   += Result_IsPausableChanged;
     result.HasSubtitlesChanged += Result_HasSubtitlesChanged;
     result.HasPreviousChanged  += Result_HasPreviousChanged;
     result.HasNextChanged      += Result_HasNextChanged;
     result.DurationChanged     += Result_DurationChanged;
 }
        /* 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;
            }
        }