Ejemplo n.º 1
0
    public static void Launch_Movie(int select_item, int GetID, GUIAnimation m_SearchAnimation, PlayerOption playeroption)
    //-------------------------------------------------------------------------------------------
    // Play Movie
    //-------------------------------------------------------------------------------------------
    {
      LogMyFilms.Debug("Launch_Movie() select_item = '" + select_item + "' - GetID = '" + GetID + "' - m_SearchAnimation = '" + m_SearchAnimation + "', playeroption = '" + Enum.GetName(typeof(PlayerOption), playeroption) + "'");
      //enableNativeAutoplay(); // in case, other plugin disabled it - removed, as we now do start external player ourselves ...

      #region Version Select Dialog
      string filestorage = MyFilms.r[select_item][MyFilms.conf.StrStorage].ToString();
      if (Helper.FieldIsSet(MyFilms.conf.StrStorage))
      {
        Regex filmver = new Regex(@"\[\[([^\#]*)##([^\]]*)\]\]");
        MatchCollection filmverMatches = filmver.Matches(filestorage);
        if (filmverMatches.Count > 0)
        {
          GUIDialogMenu versionmenu =
            (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
          versionmenu.Reset();
          versionmenu.SetHeading("Select Version");
          List<string> filestr = new List<string>();
          for (int i = 0; i < filmverMatches.Count; i++)
          {
            versionmenu.Add(filmverMatches[i].Groups[2].Value);
            filestr.Add(filmverMatches[i].Groups[1].Value);
          }
          versionmenu.DoModal(GetID);
          if (versionmenu.SelectedLabel == -1) return;
          filestorage = filestr[versionmenu.SelectedLabel];
        }
      }

      #endregion

      #region handle WOL
      // Guzzi: Added WOL to start remote host before playing the files
      // Wake up the TV server, if required
      // HandleWakeUpNas();
      // LogMyFilms.Info("Launched HandleWakeUpNas() to start movie'" + MyFilms.r[select_item][MyFilms.conf.StrSTitle.ToString()] + "'");

      if (MyFilms.conf.StrCheckWOLenable)
      {
        WakeOnLanManager wakeOnLanManager = new WakeOnLanManager();
        int wTimeout = MyFilms.conf.StrWOLtimeout;
        bool isActive;
        string UNCpath = filestorage;
        string NasServerName;
        string NasMACAddress;

        if (UNCpath.StartsWith("\\\\")) UNCpath = (UNCpath.Substring(2, UNCpath.Substring(2).IndexOf("\\") + 0)).ToLower();
        if ((UNCpath.Equals(MyFilms.conf.StrNasName1, StringComparison.InvariantCultureIgnoreCase)) ||
            (UNCpath.Equals(MyFilms.conf.StrNasName2, StringComparison.InvariantCultureIgnoreCase)) ||
            (UNCpath.Equals(MyFilms.conf.StrNasName3, StringComparison.InvariantCultureIgnoreCase)))
        {
          isActive = WakeOnLanManager.Ping(UNCpath, wTimeout);

          if (!isActive) // Only if NAS server is not yet already rzunning !
          {
            if (MyFilms.conf.StrCheckWOLuserdialog)
            {
              if (!(GUIUtils.ShowYesNoDialog(GUILocalizeStrings.Get(107986), "Film    : '" + MyFilms.r[select_item][MyFilms.conf.StrSTitle.ToString()] + "'" + "\n" + "Server  : '" + UNCpath + "'" + "\n" + "Status  : '" + GUILocalizeStrings.Get(10798742)))) // srv name + " - (offline) - start ?"
                return;
            }

            // Search the NAS where movie is located:
            if ((UNCpath.Equals(MyFilms.conf.StrNasName1, StringComparison.InvariantCultureIgnoreCase)) &&
                (MyFilms.conf.StrNasMAC1.Length > 1))
            {
              NasServerName = MyFilms.conf.StrNasName1;
              NasMACAddress = MyFilms.conf.StrNasMAC1;
            }
            else if ((UNCpath.Equals(MyFilms.conf.StrNasName2, StringComparison.InvariantCultureIgnoreCase)) &&
                     (MyFilms.conf.StrNasMAC2.Length > 1))
            {
              NasServerName = MyFilms.conf.StrNasName2;
              NasMACAddress = MyFilms.conf.StrNasMAC2;
            }
            else if ((UNCpath.Equals(MyFilms.conf.StrNasName3, StringComparison.InvariantCultureIgnoreCase)) &&
                     (MyFilms.conf.StrNasMAC3.Length > 1))
            {
              NasServerName = MyFilms.conf.StrNasName3;
              NasMACAddress = MyFilms.conf.StrNasMAC3;
            }
            else
            {
              NasServerName = String.Empty;
              NasMACAddress = String.Empty;
            }

            // Start NAS Server

            bool SuccessFulStart = wakeOnLanManager.WakeupSystem(wakeOnLanManager.GetHwAddrBytes(NasMACAddress), NasServerName, wTimeout);

            if (MyFilms.conf.StrCheckWOLuserdialog)
            {
              if (SuccessFulStart)
                GUIUtils.ShowNotifyDialog("'" + NasServerName + "' " + GUILocalizeStrings.Get(10798743)); //successfully started 
              else
                GUIUtils.ShowOKDialog("'" + NasServerName + "' " + GUILocalizeStrings.Get(10798744)); // could not be started 
            }
          }
        }
        else
        {
          GUIUtils.ShowOKDialog("", ("Server '" + UNCpath + "' " + GUILocalizeStrings.Get(10798746)), GUILocalizeStrings.Get(10798747), ""); // Automatic NAS start not possible ... 
          return;
        }
      }

      #endregion

      SetProcessAnimationStatus(true, m_SearchAnimation);
      #region Run externaly Program before Playing if defined in setup
      if (Helper.FieldIsSet(MyFilms.conf.CmdPar))
        RunProgram(MyFilms.conf.CmdExe, MyFilms.r[MyFilms.conf.StrIndex][MyFilms.conf.CmdPar].ToString());
      #endregion

      if (g_Player.Playing) g_Player.Stop();

      // search all files
      var newItems = new ArrayList();
      bool noResumeMovie = true;
      int movieIndex = 0;

      SearchAllFiles(MyFilms.r[select_item], false, ref noResumeMovie, ref newItems, ref movieIndex, false, filestorage);
      
      //  ToDo: add code to call population of trailers array and insert num of configured trailers into playlist
      // newItems.Insert(0, <trailers>);
      
      if (newItems.Count > 20) // Maximum 20 entries (limitation for MP dialogFileStacking)
      {
        GUIUtils.ShowOKDialog(MyFilms.r[select_item][MyFilms.conf.StrSTitle].ToString(), "maximum 20 entries for the playlist", "", "");
        LogMyFilms.Info("Too many entries found for movie '" + MyFilms.r[select_item][MyFilms.conf.StrSTitle] + "', number of entries found = " + newItems.Count);
        return;
      }
      SetProcessAnimationStatus(false, m_SearchAnimation);

      #region optional part selection dialog
      if (newItems.Count > 1)
      {
        if (noResumeMovie)
        {
          var dlg = (GUIDialogFileStacking)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_FILESTACKING);
          if (null != dlg)
          {
            dlg.SetNumberOfFiles(newItems.Count);
            dlg.DoModal(GUIWindowManager.ActiveWindow);
            int selectedFileIndex = dlg.SelectedFile;
            if (selectedFileIndex < 1) return;
            movieIndex = selectedFileIndex++;
          }
        }
      }
      #endregion

      if (newItems.Count > 0)
      {
        // Check, if the content returned is a BR playlist to supress internal player and dialogs
        bool isBRcontent = false;
        string mediapath = filestorage;
        if (newItems[0].ToString().ToLower().EndsWith("bdmv")) isBRcontent = true;
        bool isMpVideo = Utils.IsVideo(newItems[0].ToString());
        LogMyFilms.Info("Launch_Movie() - starting playback: isBRcontent = '" + isBRcontent + "', isMpVideo = '" + isMpVideo + "', #items = '" + newItems.Count + "', first item = '" + newItems[0] + "'), filestorage = '" + filestorage + "'");

        switch (playeroption)
        {
          case PlayerOption.External:
            try
            {
              LogMyFilms.Info("Launch_Movie() - start external player - path = '" + MyFilms.conf.ExternalPlayerPath + "', argument (filestorage) = '" + filestorage + "'");
              LaunchExternalPlayer(filestorage);
            } catch (Exception ex) { LogMyFilms.Info("Launch_Movie() - calling external player ended with exception: " + ex); }
            break;
          case PlayerOption.BluRayPlayerLauncher:
            LogMyFilms.Info("Launch_Movie() - activate blurayplayer plugin");
            GUIWindowManager.ActivateWindow((int)MyFilms.ExternalPluginWindows.BluRayPlayerLauncher);
            break;
          case PlayerOption.Internal:
            bool externalplayerextensiondetected = MyFilms.conf.ExternalPlayerExtensions.Split(new Char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Any(s => filestorage.ToLower().Contains(s.ToLower()));
            if (externalplayerextensiondetected && MyFilms.conf.ExternalPlayerPath.Length > 0) // check, if this is configured to use external player via extensions in setup
            {
              #region external player playback (myfilms)
              LogMyFilms.Info("Launch_Movie() - extension for external player detected! - start external player - path = '" + MyFilms.conf.ExternalPlayerPath + "', argument (filestorage) = '" + filestorage + "'");
              try
              {
                LaunchExternalPlayer(filestorage);
              } catch (Exception ex) { LogMyFilms.Info("Launch_Movie() - calling external player ended with exception: " + ex); }
              #endregion
            }
            else if (isMpVideo || (isBRcontent && Helper.IsBdHandlerAvailableAndEnabled)) // use internal playback, if suppoerted or BD handler is installed
            {
              #region internal playback
              LogMyFilms.Info("Launch_Movie() - start internal playback");
              playlistPlayer.Reset();
              playlistPlayer.CurrentPlaylistType = PlayListType.PLAYLIST_VIDEO_TEMP;
              PlayList playlist = playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_VIDEO_TEMP);
              playlist.Clear();

              foreach (object t in newItems)
              {
                var movieFileName = (string)t;
                // ToDo: Check, if that is necessary - from MP1.3.x to get e.g. Mediainfo registered AddFileToDatabase(movieFileName);
                var newitem = new PlayListItem();
                newitem.FileName = movieFileName;
                newitem.Type = PlayListItem.PlayListItemType.Video;
                playlist.Add(newitem);
              }
              // ask for start movie Index

              MyFilms.conf.MyFilmsPlaybackActive = true; // Set Playbackhandler to active
              PlayMovieFromPlayList(noResumeMovie, movieIndex - 1); // play movie...
              #endregion
            }
            else if (isBRcontent && Helper.IsBluRayPlayerLauncherAvailableAndEnabled) // use BRplayerLauncher fir BR content, if installed
            {
              #region  BluRayPlayerLauncher playback
              LogMyFilms.Info("Launch_Movie() - activate blurayplayer plugin");
              GUIWindowManager.ActivateWindow((int)MyFilms.ExternalPluginWindows.BluRayPlayerLauncher);
              #endregion
            }
            else // playback not successful - notify user!
            {
              #region no playback option successful - notify user
              LogMyFilms.Info("Launch_Movie() - Internal Playback not successful - playback not started!");
              GUIUtils.ShowOKDialog("No playback possible, please check your setup. \nInstall BR Player Launcher, BDhandler or external player for unsupported media.");
              #endregion
            }
            break;
        }
      }
      else
      {
        //if (first)
        //// ask for mounting file first time
        //{
        var dlgYesNo = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);
        dlgYesNo.SetHeading(GUILocalizeStrings.Get(107986)); //my films
        dlgYesNo.SetLine(1, GUILocalizeStrings.Get(219)); //no disc
        if (Helper.FieldIsSet(MyFilms.conf.StrIdentItem))
          if (MyFilms.conf.StrIdentLabel.Length > 0)
            dlgYesNo.SetLine(2, MyFilms.conf.StrIdentLabel + " = " + MyFilms.r[select_item][MyFilms.conf.StrIdentItem]); //Label Identification for Media
          else
            dlgYesNo.SetLine(2, "'" + MyFilms.conf.StrIdentItem + "' = " + MyFilms.r[select_item][MyFilms.conf.StrIdentItem]); //ANT Item Identification for Media
        else
          dlgYesNo.SetLine(2, "' disc n° = " + MyFilms.r[select_item]["Number"]); //ANT Number for Identification Media 
        dlgYesNo.DoModal(GetID);
        if (dlgYesNo.IsConfirmed) 
          Launch_Movie(select_item, GetID, m_SearchAnimation, playeroption);
        //}
        else
        {
          GUIUtils.ShowOKDialog("", GUILocalizeStrings.Get(1036), MyFilms.r[select_item][MyFilms.conf.StrSTitle].ToString(), ""); //no video found
          LogMyFilms.Info("File not found for movie '" + MyFilms.r[select_item][MyFilms.conf.StrSTitle] + "'");
        }
      }
    }
Ejemplo n.º 2
0
    private static void HandleWakeUpNas()
    {
      string hostName;
      bool isWakeOnLanEnabled;
      bool isAutoMacAddressEnabled;
      int intTimeOut;

      //Get settings from MediaPortal.xml
      using (MediaPortal.Profile.Settings xmlreader = new MPSettings())
      //using (Settings xmlreader = new MediaPortal.Profile.MPSettings())
      {
        hostName = xmlreader.GetValueAsString("nas", "hostname", "");
        isWakeOnLanEnabled = xmlreader.GetValueAsBool("nas", "isWakeOnLanEnabled", false);
        isAutoMacAddressEnabled = xmlreader.GetValueAsBool("nas", "isAutoMacAddressEnabled", false);
        intTimeOut = xmlreader.GetValueAsInt("nas", "WOLTimeOut", 10);
      }

      //isWakeOnlanEnabled
      if (isWakeOnLanEnabled)
      {
        //Check for multi-seat installation
        //if (!IsSingleSeat())
        if (true)
        {
          var wakeOnLanManager = new WakeOnLanManager();

          //isAutoMacAddressEnabled
          byte[] hwAddress;
          String macAddress;
          if (isAutoMacAddressEnabled)
          {
            IPAddress ipAddress = null;

            //Check if we already have a valid IP address stored in RemoteControl.HostName,
            //otherwise try to resolve the IP address
            if (!IPAddress.TryParse(hostName, out ipAddress))
            {
              //Get IP address of the NAS server
              try
              {
                IPAddress[] ips = Dns.GetHostAddresses(hostName);

                LogMyFilms.Debug("(HandleWakeUpNas) : WOL - GetHostAddresses({0}) returns:", hostName);

                foreach (IPAddress ip in ips)
                {
                  LogMyFilms.Debug("    {0}", ip);
                }

                //Use first valid IP address
                ipAddress = ips[0];
              }
              catch (Exception ex)
              {
                LogMyFilms.Error("(HandleWakeUpNas) : WOL - Failed GetHostAddress - {0}", ex.Message);
              }
            }

            //Check for valid IP address
            if (ipAddress != null)
            {
              //Update the MAC address if possible
              hwAddress = wakeOnLanManager.GetHardwareAddress(ipAddress);

              if (wakeOnLanManager.IsValidEthernetAddress(hwAddress))
              {
                LogMyFilms.Debug("(HandleWakeUpNas) : WOL - Valid auto MAC address: {0:x}:{1:x}:{2:x}:{3:x}:{4:x}:{5:x}"
                          , hwAddress[0], hwAddress[1], hwAddress[2], hwAddress[3], hwAddress[4], hwAddress[5]);

                //Store MAC address
                macAddress = BitConverter.ToString(hwAddress).Replace("-", ":");

                LogMyFilms.Debug("(HandleWakeUpNas) : WOL - Store MAC address: {0}", macAddress);

                using (
                  MediaPortal.Profile.Settings xmlwriter =
                    new MediaPortal.Profile.MPSettings())
                {
                  xmlwriter.SetValue("nas", "macAddress", macAddress);
                }
              }
            }
          }

          //Use stored MAC address
          using (MediaPortal.Profile.Settings xmlreader = new MPSettings())
          {
            macAddress = xmlreader.GetValueAsString("nas", "macAddress", null);
          }

          LogMyFilms.Debug("(HandleWakeUpNas) : WOL - Use stored MAC address: {0}", macAddress);

          try
          {
            hwAddress = wakeOnLanManager.GetHwAddrBytes(macAddress);

            //Finally, start up the TV server
            LogMyFilms.Info("(HandleWakeUpNas) : WOL - Start the NAS server");

            if (wakeOnLanManager.WakeupSystem(hwAddress, hostName, intTimeOut))
            {
              LogMyFilms.Info("(HandleWakeUpNas) : WOL - The NAS server started successfully!");
            }
            else
            {
              LogMyFilms.Error("(HandleWakeUpNas) : WOL - Failed to start the NAS server");
            }
          }
          catch (Exception ex)
          {
            LogMyFilms.Error("(HandleWakeUpNas) : WOL - Failed to start the NAS server - {0}", ex.Message);
          }
        }
      }
    }