Exemplo n.º 1
0
 public PlayerFactory()
 {
     _original = new MediaPortal.Player.PlayerFactory();
 }
Exemplo n.º 2
0
    public static bool Play(string stream, bool showPlaybackQualitySelectionDialog, GUIAnimation searchanimation)
    {
      if (string.IsNullOrEmpty(stream)) return false;

      // use onlinevideo youtube siteutils to get playback urls as myfilms only gives us the html page
      if (stream.Contains("youtube.com"))
      {
        // get playback url from streamURL
        LogMyFilms.Info("Getting playback url from page '{0}'", stream);

        try
        {
          bool interactiveSuccessful = false;
          if (showPlaybackQualitySelectionDialog)
          {
            Dictionary<string, string> availableTrailerFiles = GetYoutubeDownloadUrls(stream);
            List<string> choiceView = new List<string>();

            //GUIWindowManager.SendThreadCallbackAndWait((p1, p2, o) =>
            //{
            //  {
                
            //  }
            //  return 0;
            //}, 0, 0, null);
            
            GUIDialogMenu dlg = (MediaPortal.Dialogs.GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
            if (dlg == null) return false;
            dlg.Reset();
            dlg.SetHeading(GUILocalizeStrings.Get(10798994)); // Select quality ...
            foreach (KeyValuePair<string, string> availableTrailerFile in availableTrailerFiles)
            {
              dlg.Add(availableTrailerFile.Key);
              choiceView.Add(availableTrailerFile.Value); // this is the download URL
            }
            dlg.DoModal(GUIWindowManager.ActiveWindow);
            if (dlg.SelectedLabel == -1) return false;
            stream = choiceView[dlg.SelectedLabel];
            interactiveSuccessful = true;
          }

          if (!interactiveSuccessful)
          {
            // OnlineVideosHosterProxy ovHosterProxy = ExternalPlugins::OnlineVideos.CrossDomain.OnlineVideosAppDomain.Domain.CreateInstanceAndUnwrap(typeof(OnlineVideosHosterProxy).Assembly.FullName, typeof(OnlineVideosHosterProxy).FullName) as OnlineVideosHosterProxy;
            // stream = ovHosterProxy.GetVideoUrls(stream);
            stream = ExternalPlugins::OnlineVideos.Hoster.HosterFactory.GetHoster("Youtube").GetVideoUrl(stream);
          }
        }
        catch (Exception ex)
        {
          LogMyFilms.Debug("playback url exception: '{0}'", ex.Message);
          return false;
        }

        if (string.IsNullOrEmpty(stream))
        {
          LogMyFilms.Info("Unable to find playback url from stream!", stream);
          return false;
        }
        LogMyFilms.Info("Found playback url: '{0}'", stream);
      }

      LogMyFilms.Info("Preparing graph for playback of '{0}'", stream);

      PlayerFactory factory = new PlayerFactory(PlayerType.Internal, stream);
      bool? prepareResult = ((OnlineVideosPlayer)factory.PreparedPlayer).PrepareGraph();

      if (prepareResult != true)
      {
        LogMyFilms.Info("Failed to create Player graph.");
        return false;
      }

      GUIBackgroundTask.Instance.ExecuteInBackgroundAndCallback(() =>
      {
        LogMyFilms.Info("OnlineVideo Pre-Buffering Started");
        if (((OnlineVideosPlayer)factory.PreparedPlayer).BufferFile(YouTubeSiteUtil))
        {
          LogMyFilms.Info("OnlineVideo Pre-Buffering Complete");
          return true;
        }
        else
        {
          return null;
        }

      },
      delegate(bool success, object result)
      {
        if (result is bool?)
        {
          (factory.PreparedPlayer as OVSPLayer).GoFullscreen = true;

          IPlayerFactory savedFactory = g_Player.Factory;
          g_Player.Factory = factory;
          try
          {
            g_Player.Play(stream, g_Player.MediaType.Video);
          }
          catch (Exception e)
          {
            LogMyFilms.Warn("Exception while playing stream: {0}", e.Message);
          }
          g_Player.Factory = savedFactory;
        }
        else
        {
          LogMyFilms.Error("Failed to Buffer stream.");
          factory.PreparedPlayer.Dispose();
        }
      },
      "PlayTrailerStream", false, searchanimation);

      return true;
    }
Exemplo n.º 3
0
 public PlayerFactory()
 {
     _original = new MediaPortal.Player.PlayerFactory();
 }