[TV] 4994: Automatically Change Channel on Program Reminder (4 Viewers)

vapourEyes

Portal Pro
July 31, 2013
165
58
Home Country
United Kingdom United Kingdom
Good news. The buffer is now preserved on Channel Change.
Now I just need to maintain pause in case a Programme is Paused on change.

Progress is ours :)
 

vapourEyes

Portal Pro
July 31, 2013
165
58
Home Country
United Kingdom United Kingdom
I'm very sorry I have not done a GIT Merge etc. I'm posting the code that now works here, for my reference too.

Code Vector: TvHome.cs:1835.

C#:
        case GUIMessage.MessageType.GUI_MSG_NOTIFY_TV_PROGRAM:
          {
                  bool isPaused = g_Player.Paused;
            
            TVNotifyYesNoDialog tvNotifyDlg = (TVNotifyYesNoDialog)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_TVNOTIFYYESNO);

            TVProgramDescription notify = message.Object as TVProgramDescription;
            if (tvNotifyDlg == null || notify == null)
            {
              return;
            }
            int minUntilStart = _preNotifyConfig / 60;
            if (notify.StartTime > DateTime.Now)
            {
              if (minUntilStart > 1)
              {
                tvNotifyDlg.SetHeading(String.Format(GUILocalizeStrings.Get(1018), minUntilStart));
              }
              else
              {
                tvNotifyDlg.SetHeading(1019); // Program is about to begin
              }
            }
            else
            {
              tvNotifyDlg.SetHeading(String.Format(GUILocalizeStrings.Get(1206), (DateTime.Now - notify.StartTime).Minutes.ToString()));
            }
            tvNotifyDlg.SetLine(1, notify.Title);
            tvNotifyDlg.SetLine(2, notify.Description);
            tvNotifyDlg.SetLine(4, String.Format(GUILocalizeStrings.Get(1207), notify.Channel.DisplayName));
            Channel c = notify.Channel;
            string strLogo = string.Empty;
            if (c.IsTv)
            {
              strLogo = MediaPortal.Util.Utils.GetCoverArt(Thumbs.TVChannel, c.DisplayName);
            }
            else if (c.IsRadio)
            {
              strLogo = MediaPortal.Util.Utils.GetCoverArt(Thumbs.Radio, c.DisplayName);
            }

            tvNotifyDlg.SetImage(strLogo);
            tvNotifyDlg.TimeOut = _notifyTVTimeout;
            if (_playNotifyBeep)
            {
              MediaPortal.Util.Utils.PlaySound("notify.wav", false, true);
            }
            tvNotifyDlg.SetDefaultToYes(_changeChannelOnNotifyTimeout);
            tvNotifyDlg.DoModal(GUIWindowManager.ActiveWindow);

            if (tvNotifyDlg.IsConfirmed)
            {
              try
              {
                //MediaPortal.Player.g_Player.Stop();

                if (c.IsTv)
                {
                  MediaPortal.GUI.Library.GUIWindowManager.ActivateWindow((int)MediaPortal.GUI.Library.GUIWindow.Window.WINDOW_TV);
                  g_Player.ShowFullScreenWindow();
                  TVHome.ViewChannelAndCheck(c);
                  //if (TVHome.Card.IsTimeShifting && TVHome.Card.IdChannel == c.IdChannel)
                  //{
                  //}
                }
                else if (c.IsRadio)
                {
                  MediaPortal.GUI.Library.GUIWindowManager.ActivateWindow((int)MediaPortal.GUI.Library.GUIWindow.Window.WINDOW_RADIO);
                  Radio.CurrentChannel = c;
                  Radio.Play();
                }

                if (isPaused)
                {
                  Thread.Sleep(5000);
                  g_Player.Pause();
                }
              }

              catch (Exception e)
              {
                Log.Error("TVHome: TVNotification: Error on starting channel {0} after notification: {1} {2} {3}", notify.Channel.DisplayName, e.Message, e.Source, e.StackTrace);
              }

            }
            break;
          }
      }
    }
 

vapourEyes

Portal Pro
July 31, 2013
165
58
Home Country
United Kingdom United Kingdom
The 5 second Sleep() is deliberate to give the user an audible 'snapshot' of the Channel Change in case the user is grabbing a coffee. :)

But, now I note the buffer gets reset. I'm losing hair at a rate here. o_O
 

vapourEyes

Portal Pro
July 31, 2013
165
58
Home Country
United Kingdom United Kingdom
I found, eventually its best to introduce a Thread to handle the Pause and enable VideoBuffer to stay intact.

Its much more reliable and tested working here. Apologies again for not completing a PR and Merging that way.

The new thread code is below, within TvHome.cs:

C#:
    static void afterChannelChangePause()
    {
      Thread.Sleep(10000);
      g_Player.Pause();
    }




This is the code for the Notify() handler, within TvHome.cs

C#:
        case GUIMessage.MessageType.GUI_MSG_NOTIFY_TV_PROGRAM:
          {
            bool wasPaused = g_Player.Paused;
            
            TVNotifyYesNoDialog tvNotifyDlg = (TVNotifyYesNoDialog)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_TVNOTIFYYESNO);

            TVProgramDescription notify = message.Object as TVProgramDescription;
            if (tvNotifyDlg == null || notify == null)
            {
              return;
            }
            int minUntilStart = _preNotifyConfig / 60;
            if (notify.StartTime > DateTime.Now)
            {
              if (minUntilStart > 1)
              {
                tvNotifyDlg.SetHeading(String.Format(GUILocalizeStrings.Get(1018), minUntilStart));
              }
              else
              {
                tvNotifyDlg.SetHeading(1019); // Program is about to begin
              }
            }
            else
            {
              tvNotifyDlg.SetHeading(String.Format(GUILocalizeStrings.Get(1206), (DateTime.Now - notify.StartTime).Minutes.ToString()));
            }
            tvNotifyDlg.SetLine(1, notify.Title);
            tvNotifyDlg.SetLine(2, notify.Description);
            tvNotifyDlg.SetLine(4, String.Format(GUILocalizeStrings.Get(1207), notify.Channel.DisplayName));
            Channel c = notify.Channel;
            string strLogo = string.Empty;
            if (c.IsTv)
            {
              strLogo = MediaPortal.Util.Utils.GetCoverArt(Thumbs.TVChannel, c.DisplayName);
            }
            else if (c.IsRadio)
            {
              strLogo = MediaPortal.Util.Utils.GetCoverArt(Thumbs.Radio, c.DisplayName);
            }

            tvNotifyDlg.SetImage(strLogo);
            tvNotifyDlg.TimeOut = _notifyTVTimeout;
            if (_playNotifyBeep)
            {
              MediaPortal.Util.Utils.PlaySound("notify.wav", false, true);
            }
            tvNotifyDlg.SetDefaultToYes(_changeChannelOnNotifyTimeout);
            tvNotifyDlg.DoModal(GUIWindowManager.ActiveWindow);

            if (tvNotifyDlg.IsConfirmed)
            {
              try
              {
                //MediaPortal.Player.g_Player.Stop();

                if (c.IsTv)
                {
                  MediaPortal.GUI.Library.GUIWindowManager.ActivateWindow((int)MediaPortal.GUI.Library.GUIWindow.Window.WINDOW_TV);
                  g_Player.ShowFullScreenWindow();
                  TVHome.ViewChannelAndCheck(c);
                  //if (TVHome.Card.IsTimeShifting && TVHome.Card.IdChannel == c.IdChannel)
                  //{
                  //  g_Player.ShowFullScreenWindow();
                  //}
                }
                else if (c.IsRadio)
                {
                  MediaPortal.GUI.Library.GUIWindowManager.ActivateWindow((int)MediaPortal.GUI.Library.GUIWindow.Window.WINDOW_RADIO);
                  Radio.CurrentChannel = c;
                  Radio.Play();
                }

                if (wasPaused)
                {
                  Thread afterChannelChangePauseThread = new Thread(afterChannelChangePause);
                  afterChannelChangePauseThread.Start();
                }
              }

              catch (Exception e)
              {
                Log.Error("TVHome: TVNotification: Error on starting channel {0} after notification: {1} {2} {3}", notify.Channel.DisplayName, e.Message, e.Source, e.StackTrace);
              }

            }
            break;
          }
      }
 

Users who are viewing this thread

Top Bottom