public void SetPlayer(IMediaPlaybackControl p)
 {
     lock (_syncObj)
     {
         _subtitles.Clear();
         _clearOnNextRender = true;
         _player            = p;
     }
 }
        public void SkipToEnd()
        {
            IMediaPlaybackControl player = GetCurrentPlayer() as IMediaPlaybackControl;

            if (player == null)
            {
                return;
            }

            player.CurrentTime = player.Duration;
        }
        public void SkipToStart()
        {
            IMediaPlaybackControl player = GetCurrentPlayer() as IMediaPlaybackControl;

            if (player == null)
            {
                return;
            }

            player.CurrentTime = TimeSpan.FromSeconds(0);
        }
        public void SkipRelative(TimeSpan skipDuration)
        {
            IMediaPlaybackControl player = GetCurrentPlayer() as IMediaPlaybackControl;

            if (player == null)
            {
                return;
            }

            TimeSpan targetPosition = player.CurrentTime.Add(skipDuration);

            player.CurrentTime = targetPosition;
        }
Exemple #5
0
        public void OnMessageReceived(AsynchronousMessageQueue queue, SystemMessage message)
        {
            if (message.ChannelName == PlayerManagerMessaging.CHANNEL)
            {
                // React to player changes
                PlayerManagerMessaging.MessageType messageType = (PlayerManagerMessaging.MessageType)message.MessageType;
                IPlayerSlotController psc;
                switch (messageType)
                {
                case PlayerManagerMessaging.MessageType.PlayerResumeState:
                    Logger.Debug("Player Resume");
                    //Resume();
                    break;

                case PlayerManagerMessaging.MessageType.PlaybackStateChanged:
                    Logger.Debug("Player PlaybackStateChanged");
                    psc = (IPlayerSlotController)message.MessageData[PlayerManagerMessaging.PLAYER_SLOT_CONTROLLER];
                    IMediaPlaybackControl mpc = psc.CurrentPlayer as IMediaPlaybackControl;

                    if (mpc != null && mpc.IsPaused)
                    {
                        Pause();
                    }
                    else
                    {
                        Resume();
                    }

                    break;

                case PlayerManagerMessaging.MessageType.PlayerError:
                    Logger.Error("Player Error");
                    break;

                case PlayerManagerMessaging.MessageType.PlayerEnded:
                case PlayerManagerMessaging.MessageType.PlayerStopped:
                    Logger.Debug("Player Stopped or Ended");
                    Stop();
                    break;

                case PlayerManagerMessaging.MessageType.PlayerStarted:
                    Logger.Debug("Player Started");
                    break;

                case PlayerManagerMessaging.MessageType.VolumeChanged:
                    Logger.Debug("Volume changed");
                    VolumeChanged();
                    break;
                }
            }
        }
Exemple #6
0
        /// <summary>
        /// Updates the local state corresponding to the current video player, given in parameter <paramref name="videoPlayer"/>.
        /// This method will check if the given player is suspended (i.e. it is paused). It will also update the thread state so that the system
        /// won't shut down while playing a video.
        /// </summary>
        /// <param name="videoPlayer">Player to check.</param>
        private void UpdateVideoPlayerState(IVideoPlayer videoPlayer)
        {
            IMediaPlaybackControl player = videoPlayer as IMediaPlaybackControl;

            _videoPlayerSuspended = player == null || player.IsPaused;
            if (videoPlayer != null)
            {
                PlayerSuspendLevel = _videoPlayerSuspended ? SuspendLevel.None : SuspendLevel.DisplayRequired;
            }
            else
            {
                HandleNonVideoPlayers();
            }
        }
        public bool CanSkipRelative(TimeSpan skipDuration)
        {
            IMediaPlaybackControl player = GetCurrentPlayer() as IMediaPlaybackControl;

            if (player == null)
            {
                return(false);
            }

            TimeSpan currentPosition = player.CurrentTime;
            TimeSpan duration        = player.Duration;
            TimeSpan targetPosition  = currentPosition.Add(skipDuration);

            return(targetPosition.TotalSeconds > 0 && targetPosition <= duration);
        }
Exemple #8
0
        private void OnApplicationIdle(object sender, EventArgs e)
        {
            try
            {
                // Screen saver
                IInputManager inputManager = ServiceRegistration.Get <IInputManager>();
                // Remember old state, calls to IScreenManager are only required on state changes
                bool wasScreenSaverActive = _isScreenSaverActive;
                if (_isScreenSaverEnabled)
                {
                    IPlayerManager        playerManager        = ServiceRegistration.Get <IPlayerManager>();
                    IPlayerContextManager playerContextManager = ServiceRegistration.Get <IPlayerContextManager>();
                    IPlayer primaryPlayer     = playerManager[PlayerManagerConsts.PRIMARY_SLOT];
                    IMediaPlaybackControl mbc = primaryPlayer as IMediaPlaybackControl;
                    bool preventScreenSaver   = ((primaryPlayer is IVideoPlayer || primaryPlayer is IImagePlayer) && (mbc == null || !mbc.IsPaused)) ||
                                                playerContextManager.IsFullscreenContentWorkflowStateActive;

                    _isScreenSaverActive = !preventScreenSaver &&
                                           SkinContext.FrameRenderingStartTime - inputManager.LastMouseUsageTime > _screenSaverTimeOut &&
                                           SkinContext.FrameRenderingStartTime - inputManager.LastInputTime > _screenSaverTimeOut;

                    if (_screenSaverController != null)
                    {
                        bool?activeOverride = _screenSaverController.IsScreenSaverActiveOverride;
                        if (activeOverride.HasValue)
                        {
                            _isScreenSaverActive = activeOverride.Value;
                        }
                    }
                }
                else
                {
                    _isScreenSaverActive = false;
                }
                if (wasScreenSaverActive != _isScreenSaverActive)
                {
                    IScreenManager superLayerManager = ServiceRegistration.Get <IScreenManager>();
                    superLayerManager.SetSuperLayer(_isScreenSaverActive ? SCREEN_SAVER_SCREEN : null);
                }

                // If we are in fullscreen mode, we may control the mouse cursor, else reset it to visible state, if state was switched
                ShowMouseCursor(!IsFullScreen || inputManager.IsMouseUsed);
            }
            catch (Exception ex)
            {
                ServiceRegistration.Get <ILogger>().Error("SkinEngine MainForm: Error occured in Idle handler", ex);
            }
        }
        public void Restart()
        {
            IPlayer player = GetCurrentPlayer();

            if (player == null)
            {
                NextItem();
                return;
            }
            IMediaPlaybackControl mpc = player as IMediaPlaybackControl;

            if (mpc != null)
            {
                mpc.Restart();
            }
        }
Exemple #10
0
        private void StartScrobble(SystemMessage message)
        {
            try
            {
                IPlayerSlotController psc = (IPlayerSlotController)message.MessageData[PlayerManagerMessaging.PLAYER_SLOT_CONTROLLER];
                IPlayerContext        pc  = _mediaPortalServices.GetPlayerContext(psc);
                if (pc?.CurrentMediaItem == null)
                {
                    throw new ArgumentNullException(nameof(pc.CurrentMediaItem));
                }

                IMediaPlaybackControl pmc = pc.CurrentPlayer as IMediaPlaybackControl;
                if (pmc == null)
                {
                    throw new ArgumentNullException(nameof(pmc));
                }

                if (IsSeries(pc.CurrentMediaItem))
                {
                    HandleEpisodeScrobbleStart(pc, pmc);
                }
                else if (IsMovie(pc.CurrentMediaItem))
                {
                    HandleMovieScrobbleStart(pc, pmc);
                }
            }
            catch (ArgumentNullException ex)
            {
                _mediaPortalServices.GetLogger().Error("Trakt: exception occurred while starting scrobble: " + ex);
            }
            catch (Exception ex)
            {
                bool startNotificationsEnabled          = _mediaPortalServices.GetTraktSettingsWatcher().TraktSettings.ShowScrobbleStartedNotifications;
                bool startNotificationsOnFailureEnabled = _mediaPortalServices.GetTraktSettingsWatcher().TraktSettings.ShowScrobbleStartedNotificationsOnFailure;
                if (startNotificationsEnabled || startNotificationsOnFailureEnabled)
                {
                    ShowNotification(new TraktScrobbleStartedNotification(ex.Message, false, 0, "Unspecified"), TimeSpan.FromSeconds(5));
                }
                _mediaPortalServices.GetLogger().Error("Trakt: exception occurred while starting scrobble: " + ex);
                _traktEpisode = null;
                _traktMovie   = null;
                _duration     = TimeSpan.Zero;
            }
        }
Exemple #11
0
        /// <summary>
        /// Set the player position to the given absolute time (in s)
        /// </summary>
        /// <param name="position">position in s</param>
        /// <param name="absolute">absolute or relative to current position</param>
        internal static void SetPosition(double position, bool absolute)
        {
            IPlayer player = ServiceRegistration.Get <IPlayerContextManager>(false)?.CurrentPlayerContext?.CurrentPlayer;
            IMediaPlaybackControl mediaPlaybackControl = player as IMediaPlaybackControl;

            if (mediaPlaybackControl != null)
            {
                if (absolute)
                {
                    TimeSpan finalPosition = TimeSpan.FromSeconds(position);
                    mediaPlaybackControl.CurrentTime = finalPosition;
                }
                else
                {
                    TimeSpan finalPosition = TimeSpan.FromSeconds(mediaPlaybackControl.CurrentTime.TotalSeconds + position);
                    mediaPlaybackControl.CurrentTime = finalPosition;
                }
            }
        }
Exemple #12
0
        /// <summary>
        /// Provides a callable method for the skin to set the time of the sleeptimer
        /// to the length of the current playlist
        /// </summary>
        public void FromPlaylist()
        {
            try
            {
                IPlayerContextManager playerContextManager = ServiceRegistration.Get <IPlayerContextManager>();
                if (playerContextManager == null)
                {
                    return;
                }
                IPlayerContext playerContext = playerContextManager.CurrentPlayerContext;
                if (playerContext == null)
                {
                    return;
                }

                IPlaylist playlist = playerContext.Playlist;
                if (playlist == null)
                {
                    return;
                }

                // playlistTime
                TimeSpan  playlistDuration = new TimeSpan();
                MediaItem item;
                for (int i = 0; (item = playlist[i]) != null; i++)
                {
                    IList <MediaItemAspect> aspects;
                    if (item.Aspects.TryGetValue(AudioAspect.ASPECT_ID, out aspects))
                    {
                        var      aspect = aspects.First();
                        long?    dur    = aspect == null ? null : (long?)aspect[AudioAspect.ATTR_DURATION];
                        TimeSpan miDur  = dur.HasValue ? TimeSpan.FromSeconds(dur.Value) : TimeSpan.FromSeconds(0);
                        playlistDuration = playlistDuration.Add(miDur);
                    }
                    else if (item.Aspects.TryGetValue(VideoStreamAspect.ASPECT_ID, out aspects))
                    {
                        var  aspect  = aspects.First();
                        int? part    = (int?)aspect[VideoStreamAspect.ATTR_VIDEO_PART];
                        int? partSet = (int?)aspect[VideoStreamAspect.ATTR_VIDEO_PART_SET];
                        long?dur     = null;
                        if (!part.HasValue || part < 0)
                        {
                            dur = (long?)aspect[VideoStreamAspect.ATTR_DURATION];
                        }
                        else if (partSet.HasValue)
                        {
                            dur = aspects.Where(a => (int?)a[VideoStreamAspect.ATTR_VIDEO_PART_SET] == partSet &&
                                                aspect[VideoStreamAspect.ATTR_DURATION] != null).Sum(a => (long)a[VideoStreamAspect.ATTR_DURATION]);
                        }
                        TimeSpan miDur = dur.HasValue ? TimeSpan.FromSeconds(dur.Value) : TimeSpan.FromSeconds(0);
                        playlistDuration = playlistDuration.Add(miDur);
                    }
                }

                // currentTime
                IPlayer player = playerContext.CurrentPlayer;
                IMediaPlaybackControl control = player as IMediaPlaybackControl;
                if (control == null)
                {
                    return;
                }

                TimeSpan duration = playlistDuration.Subtract(control.CurrentTime);
                int      minutes  = (int)duration.TotalMinutes;
                // Add 1 extra Minute to ensure, that the player finished
                minutes       += 1;
                InitialMinutes = minutes;
            }
            catch (Exception)
            {
                // nur zur Sicherheit
            }
        }
Exemple #13
0
        private void UpdateButtonEnabled()
        {
            ILocalization localization = ServiceRegistration.Get <ILocalization>();

            if (_actSystemState.HasValue)
            {
                MediaItemEnabled   = false;
                TextInputEnabled   = false;
                AddEnabled         = false;
                SubEnabled         = false;
                ActivateEnabled    = true;
                ButtonText         = localization.ToString(Consts.GetResourceIdentifierForMenuItem(_actSystemState.Value));
                StartButtonText    = "[SleepTimer.Stop]";
                IsSleepTimerActive = true;
                return;
            }

            bool playActive = false;

            try
            {
                IPlayerContextManager playerContextManager = ServiceRegistration.Get <IPlayerContextManager>();
                if (playerContextManager != null)
                {
                    IPlayerContext playerContext = playerContextManager.CurrentPlayerContext;
                    if (playerContext != null)
                    {
                        IPlayer player = playerContext.CurrentPlayer;
                        IMediaPlaybackControl control = player as IMediaPlaybackControl;
                        if (control != null)
                        {
                            playActive = true;
                        }
                    }
                }
            }
            catch (Exception)
            {
                // nur zur Sicherheit
            }

            if (InitialMinutes <= 0)
            {
                SubEnabled = false;
                AddEnabled = true;
            }
            if (InitialMinutes >= _maxSleepTimeInMinutes)
            {
                SubEnabled = true;
                AddEnabled = false;
            }
            if (InitialMinutes > 0 && InitialMinutes < _maxSleepTimeInMinutes)
            {
                SubEnabled = true;
                AddEnabled = true;
            }
            if (_hasInputError || InitialMinutes <= 0 || InitialMinutes > _maxSleepTimeInMinutes)
            {
                ActivateEnabled = false;
            }
            else
            {
                ActivateEnabled = true;
            }

            MediaItemEnabled = playActive;
            TextInputEnabled = true;

            ButtonText         = localization.ToString(Consts.GetResourceIdentifierForMenuItem(_wantedSystemState));
            StartButtonText    = "[SleepTimer.Start]";
            IsSleepTimerActive = false;
        }
 public void SetPlayer(IMediaPlaybackControl p)
 {
   lock (_syncObj)
   {
     _subtitles.Clear();
     _clearOnNextRender = true;
     _player = p;
   }
 }
        /// <summary>
        /// Creates Scrobble data based on a DBMovieInfo object
        /// </summary>
        /// <param name="psc"></param>
        /// <param name="pc">PlayerContext</param>
        /// <param name="starting"></param>
        /// <param name="scrobbleData"></param>
        /// <param name="state"></param>
        /// <returns>The Trakt scrobble data to send</returns>
        private bool TryCreateScrobbleData(IPlayerSlotController psc, IPlayerContext pc, bool starting, out AbstractScrobble scrobbleData, out TraktScrobbleStates state)
        {
            scrobbleData = null;
            state        = starting ? TraktScrobbleStates.watching : TraktScrobbleStates.scrobble;
            if (_settings.Settings.Authentication == null)
            {
                return(false);
            }

            string username = _settings.Settings.Authentication.Username;
            string password = _settings.Settings.Authentication.Password;

            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
            {
                return(false);
            }

            // For canceling the watching, it is to have no TraktMovieScrobble.
            if (pc.CurrentMediaItem == null)
            {
                if (starting)
                {
                    return(false);
                }
                state = TraktScrobbleStates.cancelwatching;
                return(true);
            }

            bool isMovie  = pc.CurrentMediaItem.Aspects.ContainsKey(MovieAspect.ASPECT_ID);
            bool isSeries = pc.CurrentMediaItem.Aspects.ContainsKey(SeriesAspect.ASPECT_ID);

            if (!isMovie && !isSeries)
            {
                return(false);
            }

            string title = pc.CurrentPlayer != null ? pc.CurrentPlayer.MediaItemTitle : null;
            IMediaPlaybackControl pmc = pc.CurrentPlayer as IMediaPlaybackControl;
            TimeSpan currentPosition;

            if (pmc != null)
            {
                _progressUpdateWorks[psc].Duration = pmc.Duration;
                currentPosition = pmc.CurrentTime;
            }
            else
            {
                // Player is already removed on stopping, so take the resume position if available
                currentPosition = _progressUpdateWorks[psc].ResumePosition;
            }

            int progress = currentPosition == TimeSpan.Zero ? (starting ? 0 : 100) : Math.Min((int)(currentPosition.TotalSeconds * 100 / _progressUpdateWorks[psc].Duration.TotalSeconds), 100);

            string   value;
            int      iValue;
            DateTime dtValue;
            long     lValue;

            if (isMovie)
            {
                TraktMovieScrobble movie = new TraktMovieScrobble();
                if (MediaItemAspect.TryGetAttribute(pc.CurrentMediaItem.Aspects, MovieAspect.ATTR_IMDB_ID, out value) && !string.IsNullOrWhiteSpace(value))
                {
                    movie.IMDBID = value;
                }

                if (MediaItemAspect.TryGetAttribute(pc.CurrentMediaItem.Aspects, MovieAspect.ATTR_TMDB_ID, out iValue) && iValue > 0)
                {
                    movie.TMDBID = iValue.ToString();
                }

                if (MediaItemAspect.TryGetAttribute(pc.CurrentMediaItem.Aspects, MediaAspect.ATTR_RECORDINGTIME, out dtValue))
                {
                    movie.Year = dtValue.Year.ToString();
                }

                if (MediaItemAspect.TryGetAttribute(pc.CurrentMediaItem.Aspects, MovieAspect.ATTR_RUNTIME_M, out iValue) && iValue > 0)
                {
                    movie.Duration = iValue.ToString();
                }

                scrobbleData = movie;
            }
            if (isSeries)
            {
                TraktEpisodeScrobble series = new TraktEpisodeScrobble();
                if (MediaItemAspect.TryGetAttribute(pc.CurrentMediaItem.Aspects, SeriesAspect.ATTR_IMDB_ID, out value) && !string.IsNullOrWhiteSpace(value))
                {
                    series.IMDBID = value;
                }

                if (MediaItemAspect.TryGetAttribute(pc.CurrentMediaItem.Aspects, SeriesAspect.ATTR_TVDB_ID, out iValue))
                {
                    series.TVDBID = iValue.ToString();
                }

                if (MediaItemAspect.TryGetAttribute(pc.CurrentMediaItem.Aspects, SeriesAspect.ATTR_SERIESNAME, out value) && !string.IsNullOrWhiteSpace(value))
                {
                    series.Title = value;
                }

                if (MediaItemAspect.TryGetAttribute(pc.CurrentMediaItem.Aspects, SeriesAspect.ATTR_FIRSTAIRED, out dtValue))
                {
                    series.Year = dtValue.Year.ToString();
                }

                if (MediaItemAspect.TryGetAttribute(pc.CurrentMediaItem.Aspects, SeriesAspect.ATTR_SEASON, out iValue))
                {
                    series.Season = iValue.ToString();
                }
                List <int> intList;
                if (MediaItemAspect.TryGetAttribute(pc.CurrentMediaItem.Aspects, SeriesAspect.ATTR_EPISODE, out intList) && intList.Any())
                {
                    series.Episode = intList.First().ToString(); // TODO: multi episode files?!
                }
                scrobbleData = series;
            }

            // Fallback duration info
            if (string.IsNullOrWhiteSpace(scrobbleData.Duration) && MediaItemAspect.TryGetAttribute(pc.CurrentMediaItem.Aspects, VideoAspect.ATTR_DURATION, out lValue) && lValue > 0)
            {
                scrobbleData.Duration = (lValue / 60).ToString();
            }

            if (string.IsNullOrWhiteSpace(scrobbleData.Title))
            {
                scrobbleData.Title = title;
            }

            scrobbleData.Progress = progress.ToString();
            if (!starting && progress < WATCHED_PERCENT)
            {
                state = TraktScrobbleStates.cancelwatching;
            }

            scrobbleData.PluginVersion        = TraktSettings.Version;
            scrobbleData.MediaCenter          = "MediaPortal 2";
            scrobbleData.MediaCenterVersion   = Assembly.GetEntryAssembly().GetName().Version.ToString();
            scrobbleData.MediaCenterBuildDate = String.Empty;
            scrobbleData.Username             = username;
            scrobbleData.Password             = password;
            return(true);
        }
Exemple #16
0
 private float GetCurrentProgress(IMediaPlaybackControl pmc)
 {
     return((float)(100 * pmc.CurrentTime.TotalMilliseconds / pmc.Duration.TotalMilliseconds));
 }