private void OnSocketMsgReceived(string str)
        {
            try
            {
                var res = ISCPHelper.Parse(str);
                switch (res[0])
                {
                case CmdHelper.Input.Com:
                    cmdInputState = new CmdHelper.Input(res[1]);
                    if (cmdInputState?.Parameter == "2E")
                    {
                        SendCommand(CmdHelper.NetTitleName.Request);
                        SendCommand(CmdHelper.NetArtistName.Request);
                        SendCommand(CmdHelper.NetAlbumName.Request);
                    }
                    break;

                case CmdHelper.Power.Com:
                    cmdPowerStatus = new CmdHelper.Power(res[1]);
                    break;

                case CmdHelper.NetStatus.Com:
                    netStatus = new CmdHelper.NetStatus(res[1]);
                    if (netStatus.StatusPlay != CmdHelper.NetStatus.Status.STOP)
                    {
                        SendCommand(CmdHelper.NetTitleName.Request);
                        SendCommand(CmdHelper.NetArtistName.Request);
                        SendCommand(CmdHelper.NetAlbumName.Request);
                        //ShowNowPlayingNotification(true);
                    }
                    else if (cmdInputState?.Parameter == "2E")
                    {
                    }
                    else
                    {
                        ShowNowPlayingNotification(false);
                        netArt.Clear();
                    }
                    break;

                case CmdHelper.NetTitleName.Com:
                    netTitleName = new CmdHelper.NetTitleName(res[1]);
                    if ((netStatus.StatusPlay == CmdHelper.NetStatus.Status.STOP ||
                         string.IsNullOrEmpty(netTitleName.TitleName)) &&
                        cmdInputState.Parameter != "2E")
                    {
                        ShowNowPlayingNotification(false);
                    }
                    else
                    {
                        ShowNowPlayingNotification(true);
                        UpdateNowPlayingNotification();
                    }
                    break;

                case CmdHelper.NetArtistName.Com:
                    netArtistName = new CmdHelper.NetArtistName(res[1]);
                    UpdateNowPlayingNotification();
                    break;

                case CmdHelper.NetAlbumName.Com:
                    netAlbumName = new CmdHelper.NetAlbumName(res[1]);
                    UpdateNowPlayingNotification();
                    break;

                case CmdHelper.NetArt.Com:
                    netArt.OnArtMsgReceived(res[1]);
                    break;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            var dsr = new DeviceServiceResult
            {
                id    = SERVICE_STAT_MSG,
                extra = str
            };

            SendServiceBc(dsr);
        }
        protected override void OnServiceMsg(string deviceId, string msg)
        {
            Log.Debug("OnServiceMsg: ", msg);
            var res = ISCPHelper.Parse(msg);

            switch (res[0])
            {
            case CmdHelper.SleepTimer.Com:
                try
                {
                    var slp = new CmdHelper.SleepTimer(res[1]);
                    if (slp.Active)
                    {
                        tvSLP.Text = $"{slp.TimeLeft} {(slp.TimeLeft == 1 ? "minute" : "minutes")} left";
                    }
                    else
                    {
                        throw new Exception("Sleep timer not active");
                    }
                    llChildSlp.Visibility = ViewStates.Visible;
                }
                catch (Exception e)
                {
                    llChildSlp.Visibility = ViewStates.Gone;
                }
                break;

            case CmdHelper.NetTitleName.Com:
                var netTitle = new CmdHelper.NetTitleName(res[1]);
                if (tvNetTitle1.Text != netTitle.TitleName)
                {
                    tvNetTitle1.Visibility = ViewStates.Gone;
                }
                tvNetTitle1.Text       = netTitle.TitleName;
                tvNetTitle1.Visibility = ViewStates.Visible;
                break;

            case CmdHelper.NetArtistName.Com:
                var netArtist = new CmdHelper.NetArtistName(res[1]);
                if (tvNetTitle2.Text != netArtist.ArtistName)
                {
                    tvNetTitle2.Visibility = ViewStates.Gone;
                }
                tvNetTitle2.Text       = netArtist.ArtistName;
                tvNetTitle2.Visibility = ViewStates.Visible;
                break;

            case CmdHelper.NetAlbumName.Com:
                var netAlbum = new CmdHelper.NetAlbumName(res[1]);
                if (tvNetTitle3.Text != netAlbum.AlbumName)
                {
                    tvNetTitle3.Visibility = ViewStates.Gone;
                }
                tvNetTitle3.Text       = netAlbum.AlbumName;
                tvNetTitle3.Visibility = ViewStates.Visible;
                break;

            case CmdHelper.NetStatus.Com:
                try
                {
                    var netStatus = new CmdHelper.NetStatus(res[1]);
                    if (netStatus.StatusPlay == CmdHelper.NetStatus.Status.STOP)
                    {
                        throw new Exception();
                    }
                    llChildNet.Visibility = ViewStates.Visible;
                }
                catch (Exception e)
                {
                    llChildNet.Visibility = ViewStates.Gone;
                }
                break;

            case CmdHelper.NetTime.Com:
                /*
                 * try
                 * {
                 *  var netTime = new CmdHelper.NetTime(res[1]);
                 *  if (netTime.tsProg == null || netTime.tsAll == null)
                 *  {
                 *      pbNetProg.Indeterminate = true;
                 *  }
                 *  else
                 *  {
                 *      pbNetProg.Max = Convert.ToInt32(netTime.tsAll.Value.TotalSeconds);
                 *      pbNetProg.Progress = Convert.ToInt32(netTime.tsProg.Value.TotalSeconds);
                 *      pbNetProg.Indeterminate = false;
                 *  }
                 *  pbNetProg.Visibility = ViewStates.Visible;
                 * }
                 * catch (Exception e)
                 * {
                 *  pbNetProg.Visibility = ViewStates.Gone;
                 * }*/
                break;

            case CmdHelper.Volume.Com:
                try
                {
                    int vol = CmdHelper.Volume.Converter(res[1]);
                    //sbVol.Progress = vol;
                    tvVolVal.Text = vol.ToString();

                    Animate(sbVol, "progress", vol * 10);
                }
                catch (Exception)
                {
                    // ignored
                }
                llChildVol.Visibility = ViewStates.Visible;
                break;

            case CmdHelper.Power.Com:
                bool isPwOn = CmdHelper.Power.Converter(res[1]);
                swPower.Checked = isPwOn;

                ViewHelper.AnimateVisibility(!isPwOn, flBlock);
                //flBlock.Visibility = isPwOn ? ViewStates.Gone : ViewStates.Visible;
                break;

            case CmdHelper.Mute.Com:
                bool isMuted = CmdHelper.Mute.Converter(res[1]);

                fbMute.SetImageResource(isMuted
                        ? Resource.Drawable.mute_off_100_white
                        : Resource.Drawable.mute_on_100_white);
                break;

            case CmdHelper.Input.Com:
                try
                {
                    tvInpVal.Text = CmdHelper.Input.Converter(res[1]);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    tvInpVal.Text = $"N/A ({res[1]})";
                }
                llChildInp.Visibility = ViewStates.Visible;
                DeviceService.SendCommand(CmdHelper.AudioInformation.Request);
                DeviceService.SendCommand(CmdHelper.VideoInformation.Request);
                break;

            case CmdHelper.ListeningMode.Com:
                try
                {
                    tvSouVal.Text = CmdHelper.ListeningMode.Converter(res[1]);
                }
                catch (Exception e)
                {
                    tvSouVal.Text = $"N/A ({res[1]})";
                    Console.WriteLine(e);
                }
                llChildSou.Visibility = ViewStates.Visible;
                DeviceService.SendCommand(CmdHelper.AudioInformation.Request);
                DeviceService.SendCommand(CmdHelper.VideoInformation.Request);
                break;

            case CmdHelper.CenterSpeaker.Com:
                try
                {
                    int vol = CmdHelper.CenterSpeaker.Converter(res[1]);
                    tvCTL.Text = vol.ToString();

                    Animate(sbCTL, "progress", (vol + 12) * 10);
                    llChildCTL.Visibility = ViewStates.Visible;
                }
                catch (Exception ex)
                {
                    // ignored
                    llChildCTL.Visibility = ViewStates.Gone;
                }
                break;

            case CmdHelper.ToneFront.Com:
                try
                {
                    var tfRes = CmdHelper.ToneFront.Converter(res[1]);

                    if (tfRes.Bass)
                    {
                        tvBass.Text = tfRes.BassVal.ToString();

                        Animate(sbBass, "progress", (tfRes.BassVal + 10) * 10);
                        llChildBass.Visibility = ViewStates.Visible;
                    }
                    if (tfRes.Treble)
                    {
                        tvTreble.Text = tfRes.TrebleVal.ToString();

                        Animate(sbTreble, "progress", (tfRes.TrebleVal + 10) * 10);
                        llChildTreble.Visibility = ViewStates.Visible;
                    }
                }
                catch (Exception ex)
                {
                    // ignored
                    llChildBass.Visibility   = ViewStates.Gone;
                    llChildTreble.Visibility = ViewStates.Gone;
                }
                return;

            case CmdHelper.AudioInformation.Com:
                try
                {
                    var    resIFA    = CmdHelper.AudioInformation.Converter(res[1]);
                    int    formatRes = Resource.Drawable.na_100_black;
                    string f         = resIFA.format.ToLower();
                    if (f.Contains("dolby"))
                    {
                        if (f.Contains("true"))
                        {
                            formatRes = Resource.Drawable.dolby_true_hd;
                        }
                        else
                        {
                            formatRes = Resource.Drawable.dolby_100_black;
                        }
                    }
                    else if (f.Contains("dts"))
                    {
                        if (f.Contains("hd"))
                        {
                            formatRes = Resource.Drawable.dts_hd;
                        }
                        else
                        {
                            formatRes = Resource.Drawable.dts_100_black;
                        }
                    }
                    else if (f.Contains("pcm"))
                    {
                        formatRes = Resource.Drawable.pcm_100_black;
                    }

                    ivIFAFormat.SetImageResource(formatRes);
                    tvIFAFreq.Text  = $"{resIFA.freq}";
                    tvIFAChIn.Text  = $"{resIFA.channelIn}";
                    tvIFAChOut.Text = $"{resIFA.channelOut}";

                    llChildAudio.Visibility = ViewStates.Visible;
                }
                catch (Exception e)
                {
                    llChildAudio.Visibility = ViewStates.Gone;
                }
                return;

            case CmdHelper.VideoInformation.Com:
                try
                {
                    var    resIFV       = CmdHelper.VideoInformation.Converter(res[1]);
                    int    iconResInRes = Resource.Drawable.no_video_100_black;
                    string freqIn       = null;
                    if (resIFV.resIn.Contains("x"))
                    {
                        if (resIFV.resIn.Contains("1080"))
                        {
                            iconResInRes = Resource.Drawable.res_hd_1080p_100;
                        }
                        else if (resIFV.resIn.Contains("720"))
                        {
                            iconResInRes = Resource.Drawable.res_hd_720p_100;
                        }
                        else if (resIFV.resIn.Contains("2160"))
                        {
                            iconResInRes = Resource.Drawable.res_4k_100_black;
                        }
                        if (resIFV.resIn.Contains("Hz"))
                        {
                            freqIn = resIFV.resIn.Substring(resIFV.resIn.IndexOf("Hz") - 3, 2) + "\nHz";
                        }
                    }

                    tvIFVFpsIn.Text = freqIn ?? "N/A";
                    ivIFVResIn.SetImageResource(iconResInRes);


                    int    iconResOutRes = Resource.Drawable.no_video_100_black;
                    string freqOut       = null;
                    if (resIFV.resOut.Contains("x"))
                    {
                        if (resIFV.resOut.Contains("1080"))
                        {
                            iconResOutRes = Resource.Drawable.res_hd_1080p_100;
                        }
                        else if (resIFV.resOut.Contains("720"))
                        {
                            iconResOutRes = Resource.Drawable.res_hd_720p_100;
                        }
                        else if (resIFV.resOut.Contains("2160"))
                        {
                            iconResOutRes = Resource.Drawable.res_4k_100_black;
                        }
                        if (resIFV.resOut.Contains("Hz"))
                        {
                            freqOut = resIFV.resOut.Substring(resIFV.resOut.IndexOf("Hz") - 3, 2) + "\nHz";
                        }
                    }

                    tvIFVFpsOut.Text = freqOut ?? "N/A";
                    ivIFVResOut.SetImageResource(iconResOutRes);

                    llChildVideo.Visibility = ViewStates.Visible;
                }
                catch (Exception e)
                {
                    llChildVideo.Visibility = ViewStates.Gone;
                }
                return;
            }
        }
Пример #3
0
        protected override void OnServiceMsg(string deviceId, string msg)
        {
            var res = ISCPHelper.Parse(msg);

            switch (res[0])
            {
            case CmdHelper.NetTime.Com:
                try
                {
                    var netTime = new CmdHelper.NetTime(res[1]);
                    tvTime1.Text    = netTime.tsProg.Value.ToString(@"mm\:ss");
                    tvTime2.Text    = netTime.tsAll.Value.ToString(@"mm\:ss");
                    sbTime.Progress = (int)netTime.tsProg.Value.TotalSeconds;
                    sbTime.Max      = (int)netTime.tsAll.Value.TotalSeconds;
                }
                catch (Exception e)
                {
                    sbTime.Enabled = false;
                    tvTime1.Text   = "00:00";
                    tvTime2.Text   = "00:00";
                }
                break;

            case CmdHelper.NetPopup.Com:
                var netPopup = new CmdHelper.NetPopup(res[1]);
                break;

            case CmdHelper.NetListInfo.Com:
                var netList = new CmdHelper.NetListInfo(res[1]);
                break;

            case CmdHelper.NetStatus.Com:
                var netStatus = new CmdHelper.NetStatus(res[1]);
                ibPlayerPause.SetImageResource(
                    netStatus.StatusPlay == CmdHelper.NetStatus.Status.PLAY
                            ? Resource.Drawable.pause_100_black
                            : Resource.Drawable.play_100_black
                    );
                if (netStatus.StatusPlay != CmdHelper.NetStatus.Status.STOP)
                {
                    DeviceService.SendCommand(CmdHelper.NetTitleName.Request);
                    DeviceService.SendCommand(CmdHelper.NetArtistName.Request);
                }
                ShowBottonSheet(netStatus.StatusPlay != CmdHelper.NetStatus.Status.STOP);
                break;

            case CmdHelper.NetTitleName.Com:
                try
                {
                    var netTitleName = new CmdHelper.NetTitleName(res[1]);
                    if (netTitleName.TitleName != tvPlayerTitle1.Text)
                    {
                        tvPlayerTitle1.Visibility = ViewStates.Gone;
                        tvPlayerTitle1.Text       = netTitleName.TitleName;
                    }
                    tvPlayerTitle1.Visibility = ViewStates.Visible;
                }
                catch (Exception e)
                {
                    tvPlayerTitle1.Visibility = ViewStates.Gone;
                }
                break;

            case CmdHelper.NetArtistName.Com:
                try
                {
                    var netArtistName = new CmdHelper.NetArtistName(res[1]);
                    if (netArtistName.ArtistName != tvPlayerTitle2.Text)
                    {
                        tvPlayerTitle2.Visibility = ViewStates.Gone;
                        tvPlayerTitle2.Text       = netArtistName.ArtistName;
                    }
                    tvPlayerTitle2.Visibility = ViewStates.Visible;
                }
                catch (Exception e)
                {
                    tvPlayerTitle2.Visibility = ViewStates.Gone;
                }
                break;
            }
        }