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;
        }
Example #2
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;
    }
Example #3
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;
    }
Example #4
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;
    }