Ejemplo n.º 1
0
        private static Channel EnsureChannelForDvbEpg(SchedulerServiceAgent tvSchedulerAgent, TvDatabase.Channel mpChannel,
                                                      bool epgSyncAutoCreateChannels, bool epgSyncAutoCreateChannelsWithGroup)
        {
            ChannelLink channelLink = ChannelLinks.GetChannelLinkForMediaPortalChannel(mpChannel);
            ChannelType channelType = mpChannel.IsTv ? ChannelType.Television : ChannelType.Radio;
            Channel     channel     = null;

            if (channelLink != null)
            {
                channel = tvSchedulerAgent.GetChannelById(channelLink.ChannelId);
                if (channel == null)
                {
                    channel = tvSchedulerAgent.GetChannelByDisplayName(channelType, channelLink.ChannelName);
                }
            }
            if (channel == null)
            {
                channel = tvSchedulerAgent.GetChannelByDisplayName(channelType, mpChannel.DisplayName);
            }
            if (channel == null &&
                (epgSyncAutoCreateChannels || epgSyncAutoCreateChannelsWithGroup))
            {
                string groupName = "DVB-EPG";
                if (epgSyncAutoCreateChannelsWithGroup)
                {
                    IList <TvDatabase.GroupMap> groupMaps = mpChannel.ReferringGroupMap();
                    foreach (TvDatabase.GroupMap groupMap in groupMaps)
                    {
                        TvDatabase.ChannelGroup channelGroup = TvDatabase.ChannelGroup.Retrieve(groupMap.IdGroup);
                        if (channelGroup != null)
                        {
                            groupName = channelGroup.GroupName;
                            break;
                        }
                    }
                }

                Guid channelId = tvSchedulerAgent.EnsureChannel(channelType, mpChannel.DisplayName, groupName);
                channel = tvSchedulerAgent.GetChannelById(channelId);

                if (!channel.LogicalChannelNumber.HasValue &&
                    mpChannel.ChannelNumber > 0)
                {
                    channel.LogicalChannelNumber = mpChannel.ChannelNumber;
                    tvSchedulerAgent.SaveChannel(channel);
                }
            }
            return(channel);
        }
Ejemplo n.º 2
0
        private static Channel EnsureChannelForDvbEpg(SchedulerServiceAgent tvSchedulerAgent, TvDatabase.Channel mpChannel,
            bool epgSyncAutoCreateChannels, bool epgSyncAutoCreateChannelsWithGroup)
        {
            ChannelLink channelLink = ChannelLinks.GetChannelLinkForMediaPortalChannel(mpChannel);
            ChannelType channelType = mpChannel.IsTv ? ChannelType.Television : ChannelType.Radio;
            Channel channel = null;
            if (channelLink != null)
            {
                channel = tvSchedulerAgent.GetChannelById(channelLink.ChannelId);
                if (channel == null)
                {
                    channel = tvSchedulerAgent.GetChannelByDisplayName(channelType, channelLink.ChannelName);
                }
            }
            if (channel == null)
            {
                channel = tvSchedulerAgent.GetChannelByDisplayName(channelType, mpChannel.DisplayName);
            }
            if (channel == null
                && (epgSyncAutoCreateChannels || epgSyncAutoCreateChannelsWithGroup))
            {
                string groupName = "DVB-EPG";
                if (epgSyncAutoCreateChannelsWithGroup)
                {
                    IList<TvDatabase.GroupMap> groupMaps = mpChannel.ReferringGroupMap();
                    foreach (TvDatabase.GroupMap groupMap in groupMaps)
                    {
                        TvDatabase.ChannelGroup channelGroup = TvDatabase.ChannelGroup.Retrieve(groupMap.IdGroup);
                        if (channelGroup != null)
                        {
                            groupName = channelGroup.GroupName;
                            break;
                        }
                    }
                }

                Guid channelId = tvSchedulerAgent.EnsureChannel(channelType, mpChannel.DisplayName, groupName);
                channel = tvSchedulerAgent.GetChannelById(channelId);

                if (!channel.LogicalChannelNumber.HasValue
                    && mpChannel.ChannelNumber > 0)
                {
                    channel.LogicalChannelNumber = mpChannel.ChannelNumber;
                    tvSchedulerAgent.SaveChannel(channel);
                }
            }
            return channel;
        }
Ejemplo n.º 3
0
        public static void OnGlobalMessage(GUIMessage message)
        {
            switch (message.Message)
            {
            /// <summary>
            /// We need to stop the player if our livestream ends unexpectedly.
            /// If the stream stopped for a recording, we show it in a message.
            /// Without this mediaportal can hang,crash (c++ error in tsreader).
            /// </summary>
            case GUIMessage.MessageType.GUI_MSG_STOP_SERVER_TIMESHIFTING:
            {
                Log.Debug("TvHome: GUI_MSG_STOP_SERVER_TIMESHIFTING, param1 = {0}", message.Param1);
                if (PluginMain.Navigator.IsLiveStreamOn)
                {
                    if (message.Param1 == 4321)        //fired by eventlistener
                    {
                        LiveStream liveStream          = message.Object as LiveStream;
                        LiveStream navigatorLiveStream = PluginMain.Navigator.LiveStream;
                        Channel    channel             = PluginMain.Navigator.CurrentChannel;

                        if (liveStream != null && channel != null &&
                            navigatorLiveStream.TimeshiftFile == liveStream.TimeshiftFile &&
                            liveStream.StreamStartedTime == navigatorLiveStream.StreamStartedTime)
                        {
                            if (g_Player.Playing && (g_Player.IsTV || g_Player.IsRadio))
                            {
                                g_Player.Stop();
                                Log.Info("TvHome: our live stream seems to be aborted, stop the playback now");
                            }

                            string text = GUILocalizeStrings.Get(1516);
                            if (message.Label == LiveStreamAbortReason.RecordingStartedOnCard.ToString())
                            {
                                text = GUILocalizeStrings.Get(1513);
                            }
                            text = text.Replace("\\r", " ");

                            string heading = string.Empty;
                            string tvlogo  = string.Empty;
                            using (SchedulerServiceAgent SchedulerAgent = new SchedulerServiceAgent())
                            {
                                if (channel.ChannelType == ChannelType.Television)
                                {
                                    heading = GUILocalizeStrings.Get(605) + " - " + channel.DisplayName;         //my tv
                                }
                                else
                                {
                                    heading = GUILocalizeStrings.Get(665) + " - " + channel.DisplayName;         //my radio
                                }
                                tvlogo = Utility.GetLogoImage(channel, SchedulerAgent);
                            }

                            GUIDialogNotify pDlgNotify = (GUIDialogNotify)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_NOTIFY);
                            if (pDlgNotify != null)
                            {
                                pDlgNotify.Reset();
                                pDlgNotify.ClearAll();
                                pDlgNotify.SetHeading(heading);
                                if (!string.IsNullOrEmpty(text))
                                {
                                    pDlgNotify.SetText(text);
                                }
                                pDlgNotify.SetImage(tvlogo);
                                pDlgNotify.TimeOut = 5;
                                Utils.PlaySound("notify.wav", false, true);
                                pDlgNotify.DoModal(GUIWindowManager.ActiveWindow);
                            }
                        }
                    }
                    else        //fired by mp player
                    {
                        PluginMain.Navigator.AsyncStopLiveStream();
                    }
                }
            }
            break;

            case GUIMessage.MessageType.GUI_MSG_NOTIFY_REC:
            {
                if (_enableRecNotification)
                {
                    Log.Debug("TvHome: GUI_MSG_NOTIFY_REC");
                    string    head      = string.Empty;
                    string    logo      = string.Empty;
                    Recording recording = message.Object as Recording;

                    if (message.Param1 == 1)
                    {
                        head = GUILocalizeStrings.Get(1446);
                    }
                    else
                    {
                        head = GUILocalizeStrings.Get(1447);
                    }

                    using (SchedulerServiceAgent SchedulerAgent = new SchedulerServiceAgent())
                    {
                        Channel chan = SchedulerAgent.GetChannelById(recording.ChannelId);
                        logo = Utility.GetLogoImage(chan, SchedulerAgent);
                    }

                    string _text = String.Format("{0} {1}-{2}",
                                                 recording.Title,
                                                 recording.StartTime.ToString("t", CultureInfo.CurrentCulture.DateTimeFormat),
                                                 recording.StopTime.ToString("t", CultureInfo.CurrentCulture.DateTimeFormat));

                    GUIDialogNotify DlgNotify = (GUIDialogNotify)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_NOTIFY);
                    if (DlgNotify != null)
                    {
                        DlgNotify.Reset();
                        DlgNotify.ClearAll();
                        DlgNotify.SetHeading(head);
                        if (!string.IsNullOrEmpty(_text))
                        {
                            DlgNotify.SetText(_text);
                        }
                        DlgNotify.SetImage(logo);
                        DlgNotify.TimeOut = 5;
                        if (_playNotifyBeep)
                        {
                            Utils.PlaySound("notify.wav", false, true);
                        }
                        DlgNotify.DoModal(GUIWindowManager.ActiveWindow);
                    }
                }
            }
            break;

            case GUIMessage.MessageType.GUI_MSG_NOTIFY_TV_PROGRAM:
            {
                Log.Debug("TvHome: GUI_MSG_NOTIFY_TV_PROGRAM");
                TVNotifyYesNoDialog tvNotifyDlg = (TVNotifyYesNoDialog)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_TVNOTIFYYESNO);
                UpcomingProgram     prog        = message.Object as UpcomingProgram;
                if (tvNotifyDlg == null || prog == null)
                {
                    return;
                }

                tvNotifyDlg.Reset();
                if (prog.StartTime > DateTime.Now)
                {
                    int minUntilStart = (prog.StartTime - DateTime.Now).Minutes;
                    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 - prog.StartTime).Minutes.ToString()));
                }

                string description = GUILocalizeStrings.Get(736);
                using (GuideServiceAgent tvGuideAgent = new GuideServiceAgent())
                {
                    try
                    {
                        if (prog.GuideProgramId.HasValue)
                        {
                            GuideProgram Program = tvGuideAgent.GetProgramById(prog.GuideProgramId.Value);
                            description = Program.CreateCombinedDescription(false);
                        }
                    }
                    catch { }
                }

                tvNotifyDlg.SetLine(1, prog.Title);
                tvNotifyDlg.SetLine(2, description);
                tvNotifyDlg.SetLine(4, String.Format(GUILocalizeStrings.Get(1207), prog.Channel.DisplayName));
                string strLogo = string.Empty;
                using (SchedulerServiceAgent SchedulerAgent = new SchedulerServiceAgent())
                {
                    strLogo = Utility.GetLogoImage(prog.Channel, SchedulerAgent);
                }

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

                if (tvNotifyDlg.IsConfirmed)
                {
                    try
                    {
                        if (prog.Channel.ChannelType == ChannelType.Television)
                        {
                            if (g_Player.Playing && g_Player.IsTV && PluginMain.Navigator.IsLiveStreamOn)
                            {
                                GUIWindowManager.ActivateWindow((int)GUIWindow.Window.WINDOW_TVFULLSCREEN);
                            }
                            else
                            {
                                GUIWindowManager.ActivateWindow((int)GUIWindow.Window.WINDOW_TV);
                            }

                            PluginMain.Navigator.ZapToChannel(prog.Channel, false);
                            if (PluginMain.Navigator.CheckChannelChange())
                            {
                                TvHome.UpdateProgressPercentageBar(true);
                                if (!PluginMain.Navigator.LastChannelChangeFailed)
                                {
                                    g_Player.ShowFullScreenWindow();
                                }
                            }
                        }
                        else
                        {
                            PluginMain.Navigator.ZapToChannel(prog.Channel, false);
                            GUIWindowManager.ActivateWindow((int)GUIWindow.Window.WINDOW_RADIO);
                        }
                    }
                    catch (Exception e)
                    {
                        Log.Error("TVHome: TVNotification: Error on starting channel {0} after notification: {1} {2} {3}", prog.Channel.DisplayName, e.Message, e.Source, e.StackTrace);
                    }
                }
            }
            break;

            //this (GUI_MSG_RECORDER_VIEW_CHANNEL) event is used to let other plugins play a recording,
            //lastMediaHandler does this (with param1 = 5577 for indentification).
            case GUIMessage.MessageType.GUI_MSG_RECORDER_VIEW_CHANNEL:
            {
                if (message.Param1 == 5577)
                {
                    try
                    {
                        Recording rec = message.Object as Recording;
                        RecordedBase.PlayRecording(rec, message.Param2);
                    }
                    catch { Log.Error("TVHome: GUI_MSG_RECORDER_VIEW_CHANNEL error"); }
                }
            }
            break;
            }
        }
Ejemplo n.º 4
0
        public static void OnGlobalMessage(GUIMessage message)
        {
            switch (message.Message)
            {
                /// <summary>
                /// We need to stop the player if our livestream ends unexpectedly.
                /// If the stream stopped for a recording, we show it in a message.
                /// Without this mediaportal can hang,crash (c++ error in tsreader).
                /// </summary>
                case GUIMessage.MessageType.GUI_MSG_STOP_SERVER_TIMESHIFTING:
                    {
                        Log.Debug("TvHome: GUI_MSG_STOP_SERVER_TIMESHIFTING, param1 = {0}",message.Param1);
                        if (PluginMain.Navigator.IsLiveStreamOn)
                        {
                            if (message.Param1 == 4321)//fired by eventlistener
                            {
                                LiveStream liveStream = message.Object as LiveStream;
                                LiveStream navigatorLiveStream = PluginMain.Navigator.LiveStream;
                                Channel channel = PluginMain.Navigator.CurrentChannel;

                                if (liveStream != null && channel != null
                                    && navigatorLiveStream.TimeshiftFile == liveStream.TimeshiftFile
                                    && liveStream.StreamStartedTime == navigatorLiveStream.StreamStartedTime)
                                {
                                    if (g_Player.Playing && (g_Player.IsTV || g_Player.IsRadio))
                                    {
                                        g_Player.Stop();
                                        Log.Info("TvHome: our live stream seems to be aborted, stop the playback now");
                                    }

                                    string text = GUILocalizeStrings.Get(1516);
                                    if (message.Label == LiveStreamAbortReason.RecordingStartedOnCard.ToString())
                                    {
                                        text = GUILocalizeStrings.Get(1513);
                                    }
                                    text = text.Replace("\\r", " ");

                                    string heading = string.Empty;
                                    string tvlogo = string.Empty;
                                    using (SchedulerServiceAgent SchedulerAgent = new SchedulerServiceAgent())
                                    {
                                        if (channel.ChannelType == ChannelType.Television)
                                            heading = GUILocalizeStrings.Get(605) + " - " + channel.DisplayName; //my tv
                                        else
                                            heading = GUILocalizeStrings.Get(665) + " - " + channel.DisplayName; //my radio

                                        tvlogo = Utility.GetLogoImage(channel, SchedulerAgent);
                                    }

                                    GUIDialogNotify pDlgNotify = (GUIDialogNotify)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_NOTIFY);
                                    if (pDlgNotify != null)
                                    {
                                        pDlgNotify.Reset();
                                        pDlgNotify.ClearAll();
                                        pDlgNotify.SetHeading(heading);
                                        if (!string.IsNullOrEmpty(text))
                                        {
                                            pDlgNotify.SetText(text);
                                        }
                                        pDlgNotify.SetImage(tvlogo);
                                        pDlgNotify.TimeOut = 5;
                                        Utils.PlaySound("notify.wav", false, true);
                                        pDlgNotify.DoModal(GUIWindowManager.ActiveWindow);
                                    }
                                }
                            }
                            else//fired by mp player
                            {
                                PluginMain.Navigator.AsyncStopLiveStream();
                            }
                        }
                    }
                    break;

                case GUIMessage.MessageType.GUI_MSG_NOTIFY_REC:
                    {
                        if (_enableRecNotification)
                        {
                            Log.Debug("TvHome: GUI_MSG_NOTIFY_REC");
                            string head = string.Empty;
                            string logo = string.Empty;
                            Recording recording = message.Object as Recording;

                            if (message.Param1 == 1)
                                head = GUILocalizeStrings.Get(1446);
                            else
                                head = GUILocalizeStrings.Get(1447);

                            using (SchedulerServiceAgent SchedulerAgent = new SchedulerServiceAgent())
                            {
                                Channel chan = SchedulerAgent.GetChannelById(recording.ChannelId);
                                logo = Utility.GetLogoImage(chan, SchedulerAgent);
                            }

                            string _text = String.Format("{0} {1}-{2}",
                                                  recording.Title,
                                                  recording.StartTime.ToString("t", CultureInfo.CurrentCulture.DateTimeFormat),
                                                  recording.StopTime.ToString("t", CultureInfo.CurrentCulture.DateTimeFormat));

                            GUIDialogNotify DlgNotify = (GUIDialogNotify)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_NOTIFY);
                            if (DlgNotify != null)
                            {
                                DlgNotify.Reset();
                                DlgNotify.ClearAll();
                                DlgNotify.SetHeading(head);
                                if (!string.IsNullOrEmpty(_text))
                                {
                                    DlgNotify.SetText(_text);
                                }
                                DlgNotify.SetImage(logo);
                                DlgNotify.TimeOut = 5;
                                if (_playNotifyBeep)
                                {
                                    Utils.PlaySound("notify.wav", false, true);
                                }
                                DlgNotify.DoModal(GUIWindowManager.ActiveWindow);
                            }
                        }
                    }
                    break;

                case GUIMessage.MessageType.GUI_MSG_NOTIFY_TV_PROGRAM:
                    {
                        Log.Debug("TvHome: GUI_MSG_NOTIFY_TV_PROGRAM");
                        TVNotifyYesNoDialog tvNotifyDlg = (TVNotifyYesNoDialog)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_TVNOTIFYYESNO);
                        UpcomingProgram prog = message.Object as UpcomingProgram;
                        if (tvNotifyDlg == null || prog == null)
                        {
                            return;
                        }

                        tvNotifyDlg.Reset();
                        if (prog.StartTime > DateTime.Now)
                        {
                            int minUntilStart = (prog.StartTime - DateTime.Now).Minutes;
                            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 - prog.StartTime).Minutes.ToString()));
                        }

                        string description = GUILocalizeStrings.Get(736);
                        using (GuideServiceAgent tvGuideAgent = new GuideServiceAgent())
                        {
                            try
                            {
                                if (prog.GuideProgramId.HasValue)
                                {
                                    GuideProgram Program = tvGuideAgent.GetProgramById(prog.GuideProgramId.Value);
                                    description = Program.CreateCombinedDescription(false);
                                }
                            }
                            catch { }
                        }

                        tvNotifyDlg.SetLine(1, prog.Title);
                        tvNotifyDlg.SetLine(2, description);
                        tvNotifyDlg.SetLine(4, String.Format(GUILocalizeStrings.Get(1207), prog.Channel.DisplayName));
                        string strLogo = string.Empty;
                        using (SchedulerServiceAgent SchedulerAgent = new SchedulerServiceAgent())
                        {
                            strLogo = Utility.GetLogoImage(prog.Channel, SchedulerAgent);
                        }

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

                        if (tvNotifyDlg.IsConfirmed)
                        {
                            try
                            {
                                if (prog.Channel.ChannelType == ChannelType.Television)
                                {
                                    if (g_Player.Playing && g_Player.IsTV && PluginMain.Navigator.IsLiveStreamOn)
                                        GUIWindowManager.ActivateWindow((int)GUIWindow.Window.WINDOW_TVFULLSCREEN);
                                    else
                                        GUIWindowManager.ActivateWindow((int)GUIWindow.Window.WINDOW_TV);

                                    PluginMain.Navigator.ZapToChannel(prog.Channel, false);
                                    if (PluginMain.Navigator.CheckChannelChange())
                                    {
                                        TvHome.UpdateProgressPercentageBar(true);
                                        if (!PluginMain.Navigator.LastChannelChangeFailed)
                                        {
                                            g_Player.ShowFullScreenWindow();
                                        }
                                    }
                                }
                                else
                                {
                                    PluginMain.Navigator.ZapToChannel(prog.Channel, false);
                                    GUIWindowManager.ActivateWindow((int)GUIWindow.Window.WINDOW_RADIO);
                                }
                            }
                            catch (Exception e)
                            {
                                Log.Error("TVHome: TVNotification: Error on starting channel {0} after notification: {1} {2} {3}", prog.Channel.DisplayName, e.Message, e.Source, e.StackTrace);
                            }
                        }
                    }
                    break;

                //this (GUI_MSG_RECORDER_VIEW_CHANNEL) event is used to let other plugins play a recording,
                //lastMediaHandler does this (with param1 = 5577 for indentification).
                case GUIMessage.MessageType.GUI_MSG_RECORDER_VIEW_CHANNEL:
                    {
                        if (message.Param1 == 5577)
                        {
                            try
                            {
                                Recording rec = message.Object as Recording;
                                RecordedBase.PlayRecording(rec, message.Param2);
                            }
                            catch { Log.Error("TVHome: GUI_MSG_RECORDER_VIEW_CHANNEL error"); }
                        }
                    }
                    break;
            }
        }