Ejemplo n.º 1
0
    private static void HandleWakeUpTvServer()
    {
      bool isWakeOnLanEnabled;
      bool isAutoMacAddressEnabled;
      int intTimeOut;
      String macAddress;
      byte[] hwAddress;

      using (Settings xmlreader = new MPSettings())
      {
        isWakeOnLanEnabled = xmlreader.GetValueAsBool("tvservice", "isWakeOnLanEnabled", false);
        isAutoMacAddressEnabled = xmlreader.GetValueAsBool("tvservice", "isAutoMacAddressEnabled", false);
        intTimeOut = xmlreader.GetValueAsInt("tvservice", "WOLTimeOut", 10);
      }

      if (isWakeOnLanEnabled)
      {
        if (!Network.IsSingleSeat())
        {
          WakeOnLanManager wakeOnLanManager = new WakeOnLanManager();

          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(RemoteControl.HostName, out ipAddress))
            {
              // Get IP address of the TV server
              try
              {
                IPAddress[] ips;

                ips = Dns.GetHostAddresses(RemoteControl.HostName);

                Log.Debug("TVHome: WOL - GetHostAddresses({0}) returns:", RemoteControl.HostName);

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

                // Use first valid IP address
                ipAddress = ips[0];
              }
              catch (Exception ex)
              {
                Log.Error("TVHome: 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))
              {
                Log.Debug("TVHome: 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("-", ":");

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

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

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

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

          try
          {
            hwAddress = wakeOnLanManager.GetHwAddrBytes(macAddress);

            // Finally, start up the TV server
            Log.Info("TVHome: WOL - Start the TV server");

            if (wakeOnLanManager.WakeupSystem(hwAddress, RemoteControl.HostName, intTimeOut))
            {
              Log.Info("TVHome: WOL - The TV server started successfully!");
            }
            else
            {
              Log.Error("TVHome: WOL - Failed to start the TV server");
            }
          }
          catch (Exception ex)
          {
            Log.Error("TVHome: WOL - Failed to start the TV server - {0}", ex.Message);
          }
        }
      }
    }
        public override bool Init()
        {
            CrossDomain.OnlineVideosAppDomain.UseSeperateDomain = true;

            bool result = Load(GUIGraphicsContext.Skin + @"\myonlinevideos.xml");

            GUIPropertyManager.SetProperty("#OnlineVideos.desc", " "); GUIPropertyManager.SetProperty("#OnlineVideos.desc", string.Empty);
            GUIPropertyManager.SetProperty("#OnlineVideos.length", " "); GUIPropertyManager.SetProperty("#OnlineVideos.length", string.Empty);
            GUIPropertyManager.SetProperty("#OnlineVideos.aired", " "); GUIPropertyManager.SetProperty("#OnlineVideos.aired", string.Empty);
            GUIPropertyManager.SetProperty("#OnlineVideos.filter", " "); GUIPropertyManager.SetProperty("#OnlineVideos.filter", string.Empty);
            GUIPropertyManager.SetProperty("#OnlineVideos.selectedSite", " "); GUIPropertyManager.SetProperty("#OnlineVideos.selectedSite", string.Empty);
            GUIPropertyManager.SetProperty("#OnlineVideos.selectedSiteUtil", " "); GUIPropertyManager.SetProperty("#OnlineVideos.selectedSiteUtil", string.Empty);
            GUIPropertyManager.SetProperty("#OnlineVideos.currentDownloads", "0");
            GUIPropertyManager.SetProperty("#OnlineVideos.HeaderLabel", "OnlineVideos");
			GUIPropertyManager.SetProperty("#OnlineVideos.HomeScreenName", "Online Videos");
            CurrentState = State.sites;
            ExtendedVideoInfo = false;
            // get last active module settings  
            using (MediaPortal.Profile.Settings settings = new MediaPortal.Profile.MPSettings())
            {
                bool lastActiveModuleSetting = settings.GetValueAsBool("general", "showlastactivemodule", false);
                int lastActiveModule = settings.GetValueAsInt("general", "lastactivemodule", -1);
                preventDialogOnLoad = (lastActiveModuleSetting && (lastActiveModule == GetID));
            }

            StartBackgroundInitialization();

            return result;
        }
Ejemplo n.º 3
0
    private void mpButton1_Click(object sender, EventArgs e)
    {
      String macAddress;
      byte[] hwAddress;
      string hostName = "";

      WakeOnLanManager wakeOnLanManager = new WakeOnLanManager();

      IPAddress ipAddress = null;
      string detectedFolderName = "";
      if (!Util.Utils.IsUNCNetwork(folderTextBox.Text))
      {
        // Check if letter drive is a network drive
        detectedFolderName = Util.Utils.FindUNCPaths(folderTextBox.Text);
      }
      if (Util.Utils.IsUNCNetwork(detectedFolderName))
      {
        hostName = Util.Utils.GetServerNameFromUNCPath(detectedFolderName);
      }
      else if (Util.Utils.IsUNCNetwork(folderTextBox.Text))
      {
        hostName = Util.Utils.GetServerNameFromUNCPath(folderTextBox.Text);
      }

      if (string.IsNullOrEmpty(hostName))
      {
        MessageBox.Show("Wrong unc path " + folderTextBox.Text,
          "MediaPortal Settings", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        Log.Debug("Wrong unc path {0}", folderTextBox.Text);
        return;
      }

      using (Profile.Settings xmlreader = new MPSettings())
      {
        macAddress = xmlreader.GetValueAsString("macAddress", hostName, null);
      }

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

          ips = Dns.GetHostAddresses(hostName);

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

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

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

              if (wakeOnLanManager.IsValidEthernetAddress(hwAddress))
              {
                Log.Debug("WakeUpServer: 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("-", ":");

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

                using (MediaPortal.Profile.Settings xmlwriter = new MediaPortal.Profile.MPSettings())
                {
                  xmlwriter.SetValue("macAddress", hostName, macAddress);
                }
                MessageBox.Show("Stored MAC address: " + macAddress, "MediaPortal Settings",
                  MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
              }
              else
              {
                MessageBox.Show("WakeUpServer: WOL - Not a valid IPv4 address: " + ipAddress, "MediaPortal Settings",
                  MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                Log.Debug("WakeUpServer: WOL - Not a valid IPv4 address: {0}", ipAddress);
              }
            }
          }
        }
        catch (Exception ex)
        {
          Log.Error("WakeUpServer: WOL - Failed GetHostAddress - {0}", ex.Message);
        }
      }
    }
Ejemplo n.º 4
0
    public static bool Play(string strFile, MediaType type, TextReader chapters, bool fromPictures)
    {
      try
      {
        if (string.IsNullOrEmpty(strFile))
        {
          Log.Error("g_Player.Play() called without file attribute");
          return false;
        }

        IsPicture = false;
        bool playingRemoteUrl = Util.Utils.IsRemoteUrl(strFile);
        string extension = Util.Utils.GetFileExtension(strFile).ToLower();
        bool isImageFile = !playingRemoteUrl && Util.VirtualDirectory.IsImageFile(extension);
        if (isImageFile)
        {
          if (!File.Exists(Util.DaemonTools.GetVirtualDrive() + @"\VIDEO_TS\VIDEO_TS.IFO"))
            if (!File.Exists(Util.DaemonTools.GetVirtualDrive() + @"\BDMV\index.bdmv"))
            {
              _currentFilePlaying = strFile;
              MediaPortal.Ripper.AutoPlay.ExamineCD(Util.DaemonTools.GetVirtualDrive(), true);
              return true;
            }
        }

        if (!playingRemoteUrl && Util.Utils.IsDVD(strFile))
        {
          ChangeDriveSpeed(strFile, DriveType.CD);
        }

        if (!playingRemoteUrl) // MediaInfo can only be used on files (local or SMB)
        {
          _mediaInfo = new MediaInfoWrapper(strFile);
        }

        if ((!playingRemoteUrl && Util.Utils.IsVideo(strFile)) || Util.Utils.IsLiveTv(strFile)) //local video, tv, rtsp
        {
          if (type == MediaType.Unknown)
          {
            Log.Debug("g_Player.Play - Mediatype Unknown, forcing detection as Video");
            type = MediaType.Video;
          }

          // Refreshrate change done here. Blu-ray player will handle the refresh rate changes by itself
          if (strFile.ToUpper().IndexOf(@"\BDMV\INDEX.BDMV") == -1)
          {
            RefreshRateChanger.AdaptRefreshRate(strFile, (RefreshRateChanger.MediaType)(int)type);
          }

          if (RefreshRateChanger.RefreshRateChangePending)
          {
            TimeSpan ts = DateTime.Now - RefreshRateChanger.RefreshRateChangeExecutionTime;
            if (ts.TotalSeconds > RefreshRateChanger.WAIT_FOR_REFRESHRATE_RESET_MAX)
            {
              Log.Info(
                "g_Player.Play - waited {0}s for refreshrate change, but it never took place (check your config). Proceeding with playback.",
                RefreshRateChanger.WAIT_FOR_REFRESHRATE_RESET_MAX);
              RefreshRateChanger.ResetRefreshRateState();
            }
            else
            {
              return true;
            }
          }
        }

        Starting = true;
        _currentStep = 0;
        _currentStepIndex = -1;
        _seekTimer = DateTime.MinValue;
        _isInitialized = true;
        _subs = null;

        if (_player != null)
        {
          GUIGraphicsContext.ShowBackground = true;
          OnChanged(strFile);
          OnStopped();
          bool doStop = true;
          if (type != MediaType.Video && Util.Utils.IsAudio(strFile))
          {
            if (type == MediaType.Unknown)
            {
              type = MediaType.Music;
            }
            if (BassMusicPlayer.IsDefaultMusicPlayer && BassMusicPlayer.Player.Playing)
            {
              doStop = !BassMusicPlayer.Player.CrossFadingEnabled;
            }
          }
          if (doStop)
          {
            if (_player != null)
            {
              _player.Stop();
            }
            CachePlayer();
            _player = null;
          }
        }

        Log.Info("g_Player.Play({0} {1})", strFile, type);
        if (!playingRemoteUrl && Util.Utils.IsVideo(strFile))
        {
          if (!Util.Utils.IsRTSP(strFile) && extension != ".ts") // do not play recorded tv with external player
          {
            using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.MPSettings())
            {
              bool bInternal = xmlreader.GetValueAsBool("movieplayer", "internal", true);
              bool bInternalDVD = xmlreader.GetValueAsBool("dvdplayer", "internal", true);
              
              // External player extension filter
              _externalPlayerExtensions = xmlreader.GetValueAsString("movieplayer", "extensions", "");
              if (!bInternal && !string.IsNullOrEmpty(_externalPlayerExtensions) && 
                  extension != ".ifo" && extension != ".vob" && !Util.Utils.IsDVDImage(strFile))
              {
                // Do not use external player if file ext is not in the extension list
                if (!CheckExtension(strFile))
                  bInternal = true;
              }
              
              if ((!bInternalDVD && !isImageFile && (extension == ".ifo" || extension == ".vob")) ||
                  (!bInternalDVD && isImageFile && Util.Utils.IsDVDImage(strFile)) ||
                  // No image and no DVD folder rips
                  (!bInternal && !isImageFile && extension != ".ifo" && extension != ".vob") ||
                  // BluRay image
                  (!bInternal && isImageFile && Util.Utils.IsBDImage(strFile))) // external player used
              {
                if (isImageFile)
                {
                  // Check for DVD ISO
                  strFile = Util.DaemonTools.GetVirtualDrive() + @"\VIDEO_TS\VIDEO_TS.IFO";
                  if (!File.Exists(strFile))
                  {
                    // Check for BluRayISO
                    strFile = Util.DaemonTools.GetVirtualDrive() + (@"\BDMV\index.bdmv");
                    if (!File.Exists(strFile))
                      return false;
                  }
                }
                if (Util.Utils.PlayMovie(strFile))
                {
                  return true;
                }
                else // external player error
                {
                  UnableToPlay(strFile, type);
                  return false;
                }
              }
            }
          }
        }
        // Still for BDISO strFile = ISO filename, convert it
        if (!playingRemoteUrl) Util.Utils.IsBDImage(strFile, ref strFile);

        _currentFileName = strFile;
        _player = _factory.Create(strFile, type);
        
        if (_player != null)
        {
          if (chapters != null)
          {
            LoadChapters(chapters);
          }
          else
          {
            if (!playingRemoteUrl) LoadChapters(strFile);
          }
          _player = CachePreviousPlayer(_player);
          bool bResult = _player.Play(strFile);
          if (!bResult)
          {
            Log.Info("g_Player: ended");
            _player.SafeDispose();
            _player = null;
            _subs = null;
            UnableToPlay(strFile, type);
          }
          else if (_player.Playing)
          {
            _isInitialized = false;
            _currentFilePlaying = _player.CurrentFile;
            //if (_chapters == null)
            //{
            //  _chapters = _player.Chapters;
            //}
            if (_chaptersname == null)
            {
              _chaptersname = _player.ChaptersName;
            }
            OnStarted();
          }

          // Set bool to know if video if played from MyPictures
          if (fromPictures)
          {
            IsPicture = true;
          }

          return bResult;
        }
      }
      finally
      {
        Starting = false;
      }
      UnableToPlay(strFile, type);
      return false;
    }
Ejemplo n.º 5
0
 protected override void SaveSettings()
 {
   base.SaveSettings();
   using (MediaPortal.Profile.Settings xmlwriter = new MediaPortal.Profile.MPSettings())
   {
     xmlwriter.SetValue(SerializeName, "layout", (int)currentLayout);
     xmlwriter.SetValueAsBool(SerializeName, "sortasc", m_bSortAscending);
   }
 }
Ejemplo n.º 6
0
    public static bool HandleWakeUpServer(string hostName, int wolTimeout)
    {
      String macAddress;
      byte[] hwAddress;

      WakeOnLanManager wakeOnLanManager = new WakeOnLanManager();

      IPAddress ipAddress = null;

      using (Settings xmlreader = new MPSettings())
      {
        macAddress = xmlreader.GetValueAsString("macAddress", hostName, null);
      }

      if (wakeOnLanManager.Ping(hostName, 100) && !string.IsNullOrEmpty(macAddress))
      {
        Log.Debug("WakeUpServer: The {0} server already started and mac address is learnt!", hostName);
        return true;
      }

      // Check if we already have a valid IP address stored,
      // otherwise try to resolve the IP address
      if (!IPAddress.TryParse(hostName, out ipAddress) && string.IsNullOrEmpty(macAddress))
      {
        // Get IP address of the server
        try
        {
          IPAddress[] ips;

          ips = Dns.GetHostAddresses(hostName);

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

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

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

              if (wakeOnLanManager.IsValidEthernetAddress(hwAddress))
              {
                Log.Debug("WakeUpServer: 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("-", ":");

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

                using (MediaPortal.Profile.Settings xmlwriter = new MediaPortal.Profile.MPSettings())
                {
                  xmlwriter.SetValue("macAddress", hostName, macAddress);
                }
              }
              else
              {
                Log.Debug("WakeUpServer: WOL - Not a valid IPv4 address: {0}", ipAddress);
              }
            }
          }
        }
        catch (Exception ex)
        {
          Log.Error("WakeUpServer: WOL - Failed GetHostAddress - {0}", ex.Message);
        }
      }

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

      try
      {
        hwAddress = wakeOnLanManager.GetHwAddrBytes(macAddress);

        // Finally, start up the server
        Log.Info("WakeUpServer: WOL - Start the {0} server", hostName);

        if (WakeupSystem(hwAddress, hostName, wolTimeout))
        {
          Log.Info("WakeUpServer: WOL - The {0} server started successfully!", hostName);
          return true;
        }
        else
        {
          Log.Error("WakeUpServer: WOL - Failed to start the {0} server", hostName);
        }
      }
      catch (Exception ex)
      {
        Log.Error("WakeUpServer: WOL - Failed to start the server - {0}", ex.Message);
      }
      return false;
    }
        public static void InitLogger(bool config = false)
        {
            var loggingConfiguration = LogManager.Configuration ?? new LoggingConfiguration();

            string logFile    = string.Format(LogFileName, (config ? "Config" : string.Empty));
            string logOldFile = string.Format(OldLogFileName, (config ? "Config" : string.Empty));

            try
            {
                var fileInfo = new FileInfo(Config.GetFile((Config.Dir) 1, logFile));
                if (fileInfo.Exists)
                {
                    if (File.Exists(Config.GetFile((Config.Dir) 1, logOldFile)))
                    {
                        File.Delete(Config.GetFile((Config.Dir) 1, logOldFile));
                    }
                    fileInfo.CopyTo(Config.GetFile((Config.Dir) 1, logOldFile));
                    fileInfo.Delete();
                }
            }
            catch { }

            var fileTarget = new FileTarget()
            {
                FileName = Config.GetFile((Config.Dir) 1, logFile),
                Encoding = "utf-8",
                Layout   = "${date:format=dd-MMM-yyyy HH\\:mm\\:ss} ${level:fixedLength=true:padding=5} [${logger:fixedLength=true:padding=20:shortName=true}]: ${message} ${exception:format=tostring}"
            };

            loggingConfiguration.AddTarget("spectrum-analyzer", fileTarget);

            LogLevel logLevel    = LogLevel.Debug;
            int      intLogLevel = 3;

            using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.MPSettings())
            {
                intLogLevel = xmlreader.GetValueAsInt("general", "loglevel", intLogLevel);
            }

            switch (intLogLevel)
            {
            case 0:
                logLevel = LogLevel.Error;
                break;

            case 1:
                logLevel = LogLevel.Warn;
                break;

            case 2:
                logLevel = LogLevel.Info;
                break;

            default:
                logLevel = LogLevel.Debug;
                break;
            }
      #if DEBUG
            logLevel = LogLevel.Debug;
      #endif

            var loggingRule = new LoggingRule("*", logLevel, fileTarget);
            loggingConfiguration.LoggingRules.Add(loggingRule);
            LogManager.Configuration = loggingConfiguration;
        }
Ejemplo n.º 8
0
        public static bool HandleWakeUpServer(string hostName, int wolTimeout)
        {
            String macAddress;

            byte[] hwAddress;

            WakeOnLanManager wakeOnLanManager = new WakeOnLanManager();

            IPAddress ipAddress = null;

            using (Settings xmlreader = new MPSettings())
            {
                macAddress = xmlreader.GetValueAsString("macAddress", hostName, null);
            }

            // Test is server is online
            if (wakeOnLanManager.Ping(hostName, 100))
            {
                Log.Debug("WakeUpServer: The {0} server already started and mac address is learnt!", hostName);
                return(true);
            }

            // Check if we already have a valid IP address stored,
            // otherwise try to resolve the IP address
            if (!IPAddress.TryParse(hostName, out ipAddress) && string.IsNullOrEmpty(macAddress))
            {
                // Get IP address of the server
                try
                {
                    IPAddress[] ips;

                    ips = Dns.GetHostAddresses(hostName);

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

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

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

                            if (wakeOnLanManager.IsValidEthernetAddress(hwAddress))
                            {
                                Log.Debug("WakeUpServer: 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("-", ":");

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

                                using (MediaPortal.Profile.Settings xmlwriter = new MediaPortal.Profile.MPSettings())
                                {
                                    xmlwriter.SetValue("macAddress", hostName, macAddress);
                                }
                            }
                            else
                            {
                                Log.Debug("WakeUpServer: WOL - Not a valid IPv4 address: {0}", ipAddress);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("WakeUpServer: WOL - Failed GetHostAddress - {0}", ex.Message);
                }
            }

            if (macAddress != null)
            {
                Log.Debug("WakeUpServer: WOL - Use stored MAC address: {0}", macAddress);

                try
                {
                    hwAddress = wakeOnLanManager.GetHwAddrBytes(macAddress);

                    // Finally, start up the server
                    Log.Info("WakeUpServer: WOL - Start the {0} server", hostName);

                    if (WakeupSystem(hwAddress, hostName, wolTimeout))
                    {
                        Log.Info("WakeUpServer: WOL - The {0} server started successfully!", hostName);
                        return(true);
                    }
                    Log.Error("WakeUpServer: WOL - Failed to start the {0} server", hostName);
                }
                catch (Exception ex)
                {
                    Log.Error("WakeUpServer: WOL - Failed to start the server - {0}", ex.Message);
                }
            }
            Log.Error("WakeUpServer: WOL - Failed to start the {0} server", hostName);
            return(false);
        }
Ejemplo n.º 9
0
    public static bool Play(string strFile, MediaType type, TextReader chapters, bool fromPictures, int title, bool forcePlay, bool fromExtTS)
    {
      try
      {
        if (string.IsNullOrEmpty(strFile))
        {
          Log.Error("g_Player.Play() called without file attribute");
          return false;
        }

        g_Player.SetResumeBDTitleState = title;

        IsPicture = false;
        IsExtTS = false;
        bool AskForRefresh = true;
        bool playingRemoteUrl = Util.Utils.IsRemoteUrl(strFile);
        string extension = Util.Utils.GetFileExtension(strFile).ToLowerInvariant();
        bool isImageFile = !playingRemoteUrl && Util.VirtualDirectory.IsImageFile(extension);
        if (isImageFile)
        {
          if (!File.Exists(Util.DaemonTools.GetVirtualDrive() + @"\VIDEO_TS\VIDEO_TS.IFO"))
            if (!File.Exists(Util.DaemonTools.GetVirtualDrive() + @"\BDMV\index.bdmv"))
            {
              _currentFilePlaying = strFile;
              MediaPortal.Ripper.AutoPlay.ExamineCD(Util.DaemonTools.GetVirtualDrive(), true);
              return true;
            }
        }

        if (!playingRemoteUrl) // MediaInfo can only be used on files (local or SMB)
        {
          if (currentMediaInfoFilePlaying != strFile)
          {
          _mediaInfo = new MediaInfoWrapper(strFile);
            currentMediaInfoFilePlaying = strFile;
        }
        }

        // back to previous Windows if we are only in video fullscreen to do a proper release when next item is music only
        if (((GUIWindow.Window) (Enum.Parse(typeof (GUIWindow.Window), GUIWindowManager.ActiveWindow.ToString())) ==
             GUIWindow.Window.WINDOW_FULLSCREEN_VIDEO) && !MediaInfo.hasVideo && type == MediaType.Music)
        {
          GUIWindowManager.ShowPreviousWindow();
        }

        Starting = true;
        _currentStep = 0;
        _currentStepIndex = -1;
        _seekTimer = DateTime.MinValue;
        _isInitialized = true;
        _subs = null;

        if (_player != null)
        {
          GUIGraphicsContext.ShowBackground = true;
          OnChanged(strFile);
          OnStopped();
          bool doStop = true;
          if (type != MediaType.Video && Util.Utils.IsAudio(strFile))
          {
            if (type == MediaType.Unknown)
            {
              type = MediaType.Music;
            }
            if (MediaInfo != null && MediaInfo.hasVideo && type == MediaType.Music)
            {
              type = MediaType.Video;
            }
            if (BassMusicPlayer.IsDefaultMusicPlayer && BassMusicPlayer.Player.Playing && type != MediaType.Video)
            {
              doStop = !BassMusicPlayer.Player.CrossFadingEnabled;
            }
          }

          // Set currentMedia needed for correct detection when BASS Engine is doing a Stop
          _currentMediaForBassEngine = type;

          if (doStop)
          {
            if (_player != null)
            {
              _player.Stop();
              
              if (BassMusicPlayer.IsDefaultMusicPlayer && type != MediaType.Music)
              {
                // This would be better to be handled in a new Stop() parameter, but it would break the interface compatibility
                BassMusicPlayer.Player.FreeBass();
              }
            }

            CachePlayer();
            _player = null;
          }
        }

        if (!playingRemoteUrl && Util.Utils.IsDVD(strFile))
        {
          ChangeDriveSpeed(strFile, DriveType.CD);
        }

        if (MediaInfo != null && MediaInfo.hasVideo && type == MediaType.Music)
        {
          type = MediaType.Video;
        }

        if ((!playingRemoteUrl && Util.Utils.IsVideo(strFile)) || Util.Utils.IsLiveTv(strFile) ||
            Util.Utils.IsRTSP(strFile)) //local video, tv, rtsp
        {
          if (type == MediaType.Unknown)
          {
            Log.Debug("g_Player.Play - Mediatype Unknown, forcing detection as Video");
            type = MediaType.Video;
          }
          if (type != MediaType.Music)
          {
            using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.MPSettings())
            {
              _BDInternalMenu = xmlreader.GetValueAsBool("bdplayer", "useInternalBDPlayer", true);
            }
            if (_BDInternalMenu && extension == ".bdmv")
            {
              AskForRefresh = false;
            }
            if (AskForRefresh)
            {
              // Refreshrate change done here. Blu-ray player will handle the refresh rate changes by itself
              // Identify if it's a video
              if (strFile.IndexOf(@"\BDMV\INDEX.BDMV") == -1 && type != MediaType.Radio)
              {
                // Make a double check on .ts because it can be recorded TV or Radio
                if (extension == ".ts")
                {
                  if (MediaInfo != null && MediaInfo.hasVideo)
                  {
                    RefreshRateChanger.AdaptRefreshRate(strFile, (RefreshRateChanger.MediaType)(int)type);
                  }
                }
                else
                {
                  RefreshRateChanger.AdaptRefreshRate(strFile, (RefreshRateChanger.MediaType)(int)type);
                }
              }
            }
          }

          if (RefreshRateChangePending())
          {
            return true;
          }

          // Set bool to know if we want to use video codec for .ts files
          if (fromExtTS)
          {
            IsExtTS = true;
          }
          // Set bool to know if video if we force play
          if (forcePlay)
          {
            ForcePlay = true;
          }
          else
          {
            ForcePlay = false;
          }
        }

        // Set currentMedia needed for correct detection when BASS Engine is doing a Stop
        _currentMediaForBassEngine = type;

        Log.Info("g_Player.Play({0} {1})", strFile, type);
        if (!playingRemoteUrl && Util.Utils.IsVideo(strFile) && type != MediaType.Music)
        {
          if (!Util.Utils.IsRTSP(strFile) && extension != ".ts") // do not play recorded tv with external player
          {
            using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.MPSettings())
            {
              bool bInternal = xmlreader.GetValueAsBool("movieplayer", "internal", true);
              bool bInternalDVD = xmlreader.GetValueAsBool("dvdplayer", "internal", true);

              // check if we are running from Images / Discs
              string pathRoot = Path.GetPathRoot(strFile);
              if (Util.Utils.getDriveType(pathRoot) == 5 && !bInternalDVD)
              {
                bInternalDVD = false;
              }
              else
              {
                bInternalDVD = true;
              }

              // External player extension filter
              _externalPlayerExtensions = xmlreader.GetValueAsString("movieplayer", "extensions", "");
              if (!bInternal && !string.IsNullOrEmpty(_externalPlayerExtensions) &&
                  extension != ".ifo" && extension != ".vob" && extension != ".bdmv" && !Util.Utils.IsDVDImage(strFile))
              {
                // Do not use external player if file ext is not in the extension list
                if (!CheckExtension(strFile))
                  bInternal = true;
              }

              if ((!bInternalDVD && !isImageFile && (extension == ".ifo" || extension == ".vob" || extension == ".bdmv")) ||
                  (!bInternalDVD && isImageFile && Util.Utils.IsDVDImage(strFile)) ||
                  // No image and no DVD folder rips
                  (!bInternal && !isImageFile && extension != ".ifo" && extension != ".vob" && extension != ".bdmv") ||
                  // BluRay image
                  (!bInternal && isImageFile && Util.Utils.IsBDImage(strFile))) // external player used
              {
                if (isImageFile)
                {
                  // Check for DVD ISO
                  strFile = Util.DaemonTools.GetVirtualDrive() + @"\VIDEO_TS\VIDEO_TS.IFO";
                  if (!File.Exists(strFile))
                  {
                    // Check for BluRayISO
                    strFile = Util.DaemonTools.GetVirtualDrive() + (@"\BDMV\index.bdmv");
                    if (!File.Exists(strFile))
                      return false;
                  }
                }
                // Do refresh rate
                RefreshRateChanger.AdaptRefreshRate(strFile, (RefreshRateChanger.MediaType)(int)type);

                if (RefreshRateChangePending())
                {
                  return true;
                }

                if (Util.Utils.PlayMovie(strFile))
                {
                  if (MediaInfo != null && MediaInfo.hasVideo)
                  {
                    RefreshRateChanger.AdaptRefreshRate();
                  }
                  return true;
                }
                else // external player error
                {
                  UnableToPlay(strFile, type);
                  return false;
                }
              }
            }
          }
        }
        // Still for BDISO strFile = ISO filename, convert it
        if (!playingRemoteUrl) Util.Utils.IsBDImage(strFile, ref strFile);

        _currentFileName = strFile;
        _player = _factory.Create(strFile, type);

        if (_player != null)
        {
          if (chapters != null)
          {
            LoadChapters(chapters);
          }
          else
          {
            if (!playingRemoteUrl) LoadChapters(strFile);
          }
          _player = CachePreviousPlayer(_player);
          bool bResult = _player.Play(strFile);
          if (!bResult)
          {
            Log.Info("g_Player: ended");
            _player.SafeDispose();
            _player = null;
            _subs = null;
            UnableToPlay(strFile, type);
          }
          else if (_player != null && _player.Playing)
          {
            _isInitialized = false;
            _currentFilePlaying = _player.CurrentFile;
            //if (_chapters == null)
            //{
            //  _chapters = _player.Chapters;
            //}
            if (_chaptersname == null)
            {
              _chaptersname = _player.ChaptersName;
            }
            OnStarted();
          }

          // Set bool to know if video if played from MyPictures
          if (fromPictures)
          {
            IsPicture = true;
          }

          // Set bool to know if video if we force play
          if (forcePlay)
          {
            ForcePlay = true;
          }
          else
          {
            ForcePlay = false;
          }
          return bResult;
        }
      }
      finally
      {
        _currentMediaForBassEngine = _currentMedia;
        currentMediaInfoFilePlaying = "";
        Starting = false;
      }
      UnableToPlay(strFile, type);
      return false;
    }
Ejemplo n.º 10
0
    public static bool Play(string strFile, MediaType type, TextReader chapters)
    {
      try
      {
        if (string.IsNullOrEmpty(strFile))
        {
          Log.Error("g_Player.Play() called without file attribute");
          return false;
        }

        string extension = Path.GetExtension(strFile).ToLower();
        bool isImageFile = Util.VirtualDirectory.IsImageFile(extension);
        if (isImageFile)
        {
          if (!File.Exists(Util.DaemonTools.GetVirtualDrive() + @"\VIDEO_TS\VIDEO_TS.IFO"))
          {
            _currentFilePlaying = strFile;
            MediaPortal.Ripper.AutoPlay.ExamineCD(Util.DaemonTools.GetVirtualDrive(), true);
            return true;
          }
        }

        if (Util.Utils.IsDVD(strFile))
        {
          ChangeDriveSpeed(strFile, DriveType.CD);
        }

        _mediaInfo = new MediaInfoWrapper(strFile);
        Starting = true;

        if (Util.Utils.IsVideo(strFile) || Util.Utils.IsLiveTv(strFile)) //video, tv, rtsp
        {
          if (type == MediaType.Unknown)
          {
            Log.Debug("g_Player.Play - Mediatype Unknown, forcing detection as Video");
            type = MediaType.Video;
          }
          // refreshrate change done here.
          RefreshRateChanger.AdaptRefreshRate(strFile, (RefreshRateChanger.MediaType)(int)type);

          if (RefreshRateChanger.RefreshRateChangePending)
          {
            TimeSpan ts = DateTime.Now - RefreshRateChanger.RefreshRateChangeExecutionTime;
            if (ts.TotalSeconds > RefreshRateChanger.WAIT_FOR_REFRESHRATE_RESET_MAX)
            {
              Log.Info(
                "g_Player.Play - waited {0}s for refreshrate change, but it never took place (check your config). Proceeding with playback.",
                RefreshRateChanger.WAIT_FOR_REFRESHRATE_RESET_MAX);
              RefreshRateChanger.ResetRefreshRateState();
            }
            else
            {
              return true;
            }
          }
        }

        _currentStep = 0;
        _currentStepIndex = -1;
        _seekTimer = DateTime.MinValue;
        _isInitialized = true;
        _subs = null;

        if (_player != null)
        {
          GUIGraphicsContext.ShowBackground = true;
          OnChanged(strFile);
          OnStopped();
          bool doStop = true;
          if (type != MediaType.Video && Util.Utils.IsAudio(strFile))
          {
            if (type == MediaType.Unknown)
            {
              type = MediaType.Music;
            }
            if (BassMusicPlayer.IsDefaultMusicPlayer && BassMusicPlayer.Player.Playing)
            {
              doStop = !BassMusicPlayer.Player.CrossFadingEnabled;
            }
          }
          if (doStop)
          {
            if (_player != null)
            {
              _player.Stop();
            }
            CachePlayer();
            _player = null;
          }
        }

        Log.Info("g_Player.Play({0} {1})", strFile, type);
        if (!Util.Utils.IsAVStream(strFile) && Util.Utils.IsVideo(strFile))
        {
          if (!Util.Utils.IsRTSP(strFile) && extension != ".ts") // do not play recorded tv with external player
          {
            using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.MPSettings())
            {
              bool bInternal = xmlreader.GetValueAsBool("movieplayer", "internal", true);
              bool bInternalDVD = xmlreader.GetValueAsBool("dvdplayer", "internal", true);

              if ((!bInternalDVD && (extension == ".ifo" || extension == ".vob" || isImageFile)) ||
                  (!bInternal && (extension != ".ifo" && extension != ".vob" && !isImageFile))) // external player used
              {
                if (isImageFile)
                {
                  strFile = Util.DaemonTools.GetVirtualDrive() + @"\VIDEO_TS\VIDEO_TS.IFO";
                }
                if (Util.Utils.PlayMovie(strFile))
                {
                  return true;
                }
                else // external player error
                {
                  UnableToPlay(strFile, type);
                  return false;
                }
              }
            }
          }
        }

        _player = _factory.Create(strFile, type);

        if (_player != null)
        {
          if (chapters != null)
          {
            LoadChapters(chapters);
          }
          else
          {
            LoadChapters(strFile);
          }
          _player = CachePreviousPlayer(_player);
          bool bResult = _player.Play(strFile);
          if (!bResult)
          {
            Log.Info("g_Player: ended");
            _player.SafeDispose();
            _player = null;
            _subs = null;
            UnableToPlay(strFile, type);
          }
          else if (_player.Playing)
          {
            _isInitialized = false;
            _currentFilePlaying = _player.CurrentFile;
            if (_chapters == null)
            {
              _chapters = _player.Chapters;
            }
            if (_chaptersname == null)
            {
              _chaptersname = _player.ChaptersName;
            }
            OnStarted();
          }
          return bResult;
        }
      }
      finally
      {
        Starting = false;
      }
      UnableToPlay(strFile, type);
      return false;
    }