Esempio n. 1
0
        static void PlayTrailer(string url, PlayerFactory factory, bool?preparedPlayerResult)
        {
            if (preparedPlayerResult != null)
            {
                (factory.PreparedPlayer as OVSPLayer).GoFullscreen = true;

                var savedFactory = g_Player.Factory;
                g_Player.Factory = factory;

                try
                {
                    g_Player.Play(factory.PreparedUrl, g_Player.MediaType.Video);
                }
                catch (Exception e)
                {
                    TraktLogger.Warning("Exception while playing trailer: {0}", e.Message);
                }
                g_Player.Factory = savedFactory;
            }
            else
            {
                factory.PreparedPlayer.Dispose();
                GUIUtils.ShowNotifyDialog(GUI.Translation.Error, GUI.Translation.UnableToPlayTrailer);
            }
        }
Esempio n. 2
0
        static void PlayTrailer(string url, PlayerFactory factory, bool?preparedPlayerResult)
        {
            if (preparedPlayerResult != null)
            {
                (factory.PreparedPlayer as OVSPLayer).GoFullscreen = true;

                var savedFactory = g_Player.Factory;
                g_Player.Factory = factory;

                try
                {
                    CurrentFileName = factory.PreparedUrl;
                    g_Player.Play(factory.PreparedUrl, g_Player.MediaType.Video);

                    // make the OSD pretty with poster, title etc
                    GUIUtils.SetPlayProperties(CurrentMedia, true);
                }
                catch (Exception e)
                {
                    FileLog.Warning("Exception while playing trailer, Reason = '{0}'", e.Message);
                }

                g_Player.Factory = savedFactory;
            }
            else
            {
                factory.PreparedPlayer.Dispose();
                GUIUtils.ShowNotifyDialog(Localisation.Translation.Error, Localisation.Translation.UnableToPlayTrailer);
            }
        }
Esempio n. 3
0
        static void BufferTrailer(string url)
        {
            // stop player if currently playing some other video
            if (g_Player.Playing)
            {
                g_Player.Stop();
            }

            // prepare graph must be done on the MP main thread
            FileLog.Debug("Preparing graph for playback, URL = '{0}'.", url);
            var  factory       = new PlayerFactory(PlayerType.Internal, url);
            bool?prepareResult = ((OnlineVideosPlayer)factory.PreparedPlayer).PrepareGraph();

            FileLog.Debug("Graph is now prepared.");

            switch (prepareResult)
            {
            case true:
                GUIBackgroundTask.Instance.ExecuteInBackgroundAndCallback(() =>
                {
                    FileLog.Info("OnlineVideo pre-buffering started.");

                    if (((OnlineVideosPlayer)factory.PreparedPlayer).BufferFile(OnlineVideosHandler.YouTubeSiteUtil))
                    {
                        FileLog.Info("OnlineVideo pre-buffering complete.");
                        return(true);
                    }
                    else
                    {
                        FileLog.Error("Error pre-buffering trailer.");
                        return(null);
                    }
                },
                                                                          delegate(bool success, object result)
                {
                    PlayTrailer(url, factory, result as bool?);
                },
                                                                          Localisation.Translation.BufferingTrailer, false);
                break;

            case false:
                // play without buffering
                PlayTrailer(url, factory, prepareResult);
                break;

            default:
                FileLog.Error("Failed to create player graph.");
                GUIUtils.ShowNotifyDialog(Localisation.Translation.Error, Localisation.Translation.UnableToPlayTrailer);
                break;
            }
        }
Esempio n. 4
0
        static void BufferTrailer(string url)
        {
            // stop player if currently playing some other video
            if (g_Player.Playing) g_Player.Stop();

            // prepare graph must be done on the MP main thread
            FileLog.Debug("Preparing graph for playback, URL = '{0}'.", url);
            var factory = new PlayerFactory(PlayerType.Internal, url);
            bool? prepareResult = ((OnlineVideosPlayer)factory.PreparedPlayer).PrepareGraph();
            FileLog.Debug("Graph is now prepared.");

            switch (prepareResult)
            {
                case true:
                    GUIBackgroundTask.Instance.ExecuteInBackgroundAndCallback(() =>
                    {
                        FileLog.Info("OnlineVideo pre-buffering started.");

                        if (((OnlineVideosPlayer)factory.PreparedPlayer).BufferFile(OnlineVideosHandler.YouTubeSiteUtil))
                        {
                            FileLog.Info("OnlineVideo pre-buffering complete.");
                            return true;
                        }
                        else
                        {
                            FileLog.Error("Error pre-buffering trailer.");
                            return null;
                        }
                    },
                    delegate(bool success, object result)
                    {
                        PlayTrailer(url, factory, result as bool?);
                    },
                    Localisation.Translation.BufferingTrailer, false);
                    break;

                case false:
                    // play without buffering
                    PlayTrailer(url, factory, prepareResult);
                    break;

                default:
                    FileLog.Error("Failed to create player graph.");
                    GUIUtils.ShowNotifyDialog(Localisation.Translation.Error, Localisation.Translation.UnableToPlayTrailer);
                    break;
            }
        }
        void Play_Step4(PlayListItem playItem, string lsUrl, bool goFullScreen)
        {

            OnlineVideos.MediaPortal1.Player.PlayerFactory factory = new OnlineVideos.MediaPortal1.Player.PlayerFactory(playItem.ForcedPlayer != null ? playItem.ForcedPlayer.Value : playItem.Util.Settings.Player, lsUrl);

            // check for valid url and cut off additional parameter
            if ((String.IsNullOrEmpty(lsUrl) ||
                !Helpers.UriUtils.IsValidUri((lsUrl.IndexOf(MPUrlSourceFilter.SimpleUrl.ParameterSeparator) > 0) ? lsUrl.Substring(0, lsUrl.IndexOf(MPUrlSourceFilter.SimpleUrl.ParameterSeparator)) : lsUrl))
                &&
                factory.PreparedPlayerType != PlayerType.Browser)
            {
                GUIDialogNotify dlg = (GUIDialogNotify)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_NOTIFY);
                if (dlg != null)
                {
                    dlg.Reset();
                    dlg.SetImage(SiteImageExistenceCache.GetImageForSite("OnlineVideos", type: "Icon"));
                    dlg.SetHeading(Translation.Instance.Error);
                    dlg.SetText(Translation.Instance.UnableToPlayVideo);
                    dlg.DoModal(GUIWindowManager.ActiveWindow);
                }
                return;
            }

            // stop player if currently playing some other video
            if (g_Player.Playing) g_Player.Stop();

            currentPlayingItem = null;

            if (factory.PreparedPlayerType != PlayerType.Internal)
            {
                // Websites will just go to play
                if (factory.PreparedPlayerType == PlayerType.Browser)
                {
                    (factory.PreparedPlayer as WebBrowserVideoPlayer).Initialise(playItem.Util);
                    factory.PreparedPlayer.Play(lsUrl);
                    return;
                }

                // external players can only be created on the main thread
                Play_Step5(playItem, lsUrl, goFullScreen, factory, true, true);
            }
            else
            {
                Log.Instance.Info("Preparing graph for playback of '{0}'", lsUrl);
                bool? prepareResult = ((OnlineVideosPlayer)factory.PreparedPlayer).PrepareGraph();
                switch (prepareResult)
                {
                    case true:// buffer in background
                        Gui2UtilConnector.Instance.ExecuteInBackgroundAndCallback(delegate()
                        {
                            try
                            {
                                Log.Instance.Info("Start prebuffering ...");
                                BufferingPlayerFactory = factory;
                                if (((OnlineVideosPlayer)factory.PreparedPlayer).BufferFile(playItem.Util))
                                {
                                    Log.Instance.Info("Prebuffering finished.");
                                    return true;
                                }
                                else
                                {
                                    Log.Instance.Info("Prebuffering failed.");
                                    return null;
                                }
                            }
                            finally
                            {
                                BufferingPlayerFactory = null;
                            }
                        },
                        delegate(bool success, object result)
                        {
                            // success false means BufferFile threw an exception that was shown to the user - pass it as showMessage
                            Play_Step5(playItem, lsUrl, goFullScreen, factory, result as bool?, success);
                        },
                        Translation.Instance.StartingPlayback, false);
                        break;
                    case false:// play without buffering in background
                        Play_Step5(playItem, lsUrl, goFullScreen, factory, prepareResult, true);
                        break;
                    default: // error building graph
                        GUIDialogNotify dlg = (GUIDialogNotify)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_NOTIFY);
                        if (dlg != null)
                        {
                            dlg.Reset();
                            dlg.SetImage(SiteImageExistenceCache.GetImageForSite("OnlineVideos", type: "Icon"));
                            dlg.SetHeading(Translation.Instance.Error);
                            dlg.SetText(Translation.Instance.UnableToPlayVideo);
                            dlg.DoModal(GUIWindowManager.ActiveWindow);
                        }
                        break;
                }
            }
        }
        static void PlayTrailer(string url, PlayerFactory factory, bool? preparedPlayerResult)
        {
            if (preparedPlayerResult != null)
            {
                (factory.PreparedPlayer as OVSPLayer).GoFullscreen = true;

                var savedFactory = g_Player.Factory;
                g_Player.Factory = factory;

                try
                {
                    g_Player.Play(factory.PreparedUrl, g_Player.MediaType.Video);
                }
                catch (Exception e)
                {
                    TraktLogger.Warning("Exception while playing trailer: {0}", e.Message);
                }
                g_Player.Factory = savedFactory;
            }
            else
            {
                factory.PreparedPlayer.Dispose();
                GUIUtils.ShowNotifyDialog(GUI.Translation.Error, GUI.Translation.UnableToPlayTrailer);
            }
        }
Esempio n. 7
0
        static void PlayTrailer(string url, PlayerFactory factory, bool? preparedPlayerResult)
        {
            if (preparedPlayerResult != null)
            {
                (factory.PreparedPlayer as OVSPLayer).GoFullscreen = true;

                var savedFactory = g_Player.Factory;
                g_Player.Factory = factory;

                try
                {
                    CurrentFileName = factory.PreparedUrl;
                    g_Player.Play(factory.PreparedUrl, g_Player.MediaType.Video);

                    // make the OSD pretty with poster, title etc
                    GUIUtils.SetPlayProperties(CurrentMedia, true);
                }
                catch (Exception e)
                {
                    FileLog.Warning("Exception while playing trailer, Reason = '{0}'", e.Message);
                }

                g_Player.Factory = savedFactory;
            }
            else
            {
                factory.PreparedPlayer.Dispose();
                GUIUtils.ShowNotifyDialog(Localisation.Translation.Error, Localisation.Translation.UnableToPlayTrailer);
            }
        }