コード例 #1
0
        internal void LoadSettings()
        {
            ISettingsManager      settingsManager = ServiceRegistration.Get <ISettingsManager>();
            PlayerManagerSettings settings        = settingsManager.Load <PlayerManagerSettings>();

            _volume = settings.Volume;
        }
コード例 #2
0
ファイル: BassPlayer.cs プロジェクト: haibin05/MediaPortal-2
        protected async Task NotifyPlayback()
        {
            IUserManagement       userProfileDataManagement = ServiceRegistration.Get <IUserManagement>();
            ISettingsManager      settingsManager           = ServiceRegistration.Get <ISettingsManager>();
            PlayerManagerSettings settings = settingsManager.Load <PlayerManagerSettings>();
            int  playPercentage            = GetCurrentPlayPercentage();
            bool played = playPercentage >= settings.WatchedPlayPercentage;

            if (played)
            {
                playPercentage = 100;
            }

            IServerConnectionManager scm = ServiceRegistration.Get <IServerConnectionManager>();
            IContentDirectory        cd  = scm.ContentDirectory;

            if (_mediaItemId.HasValue && _mediaItemId.Value != Guid.Empty && cd != null)
            {
                if (userProfileDataManagement.IsValidUser)
                {
                    bool updateLastPlayed = (played || playPercentage >= PLAY_THRESHOLD_PERCENT || CurrentTime.TotalSeconds >= PLAY_THRESHOLD_SEC);
                    await cd.NotifyUserPlaybackAsync(userProfileDataManagement.CurrentUser.ProfileId, _mediaItemId.Value, playPercentage, updateLastPlayed);
                }
                else
                {
                    await cd.NotifyPlaybackAsync(_mediaItemId.Value, played);
                }
            }
        }
コード例 #3
0
        protected static void NotifyPlayback(MediaItem mediaItem, int playPercentage)
        {
            ISettingsManager      settingsManager = ServiceRegistration.Get <ISettingsManager>();
            PlayerManagerSettings settings        = settingsManager.Load <PlayerManagerSettings>();
            bool watched = playPercentage >= settings.WatchedPlayPercentage;

            if (watched)
            {
                playPercentage = 100;
            }

            IServerConnectionManager scm = ServiceRegistration.Get <IServerConnectionManager>();
            IContentDirectory        cd  = scm.ContentDirectory;

            // Server will update the PlayCount of MediaAspect in ML, this does not affect loaded items.
            if (cd != null)
            {
                cd.NotifyPlayback(mediaItem.MediaItemId, watched);
            }

            // Update loaded item also, so changes will be visible in GUI without reloading
            if (!mediaItem.UserData.ContainsKey(UserDataKeysKnown.KEY_PLAY_PERCENTAGE))
            {
                mediaItem.UserData.Add(UserDataKeysKnown.KEY_PLAY_PERCENTAGE, "0");
            }
            mediaItem.UserData[UserDataKeysKnown.KEY_PLAY_PERCENTAGE] = playPercentage.ToString();

            IUserManagement userProfileDataManagement = ServiceRegistration.Get <IUserManagement>();

            if (userProfileDataManagement.IsValidUser)
            {
                userProfileDataManagement.UserProfileDataManagement.SetUserMediaItemData(userProfileDataManagement.CurrentUser.ProfileId, mediaItem.MediaItemId,
                                                                                         UserDataKeysKnown.KEY_PLAY_PERCENTAGE, playPercentage.ToString());
            }

            if (watched)
            {
                // Update loaded item also, so changes will be visible in GUI without reloading
                int currentPlayCount;
                if (MediaItemAspect.TryGetAttribute(mediaItem.Aspects, MediaAspect.ATTR_PLAYCOUNT, 0, out currentPlayCount))
                {
                    MediaItemAspect.SetAttribute(mediaItem.Aspects, MediaAspect.ATTR_PLAYCOUNT, ++currentPlayCount);
                }

                if (!mediaItem.UserData.ContainsKey(UserDataKeysKnown.KEY_PLAY_COUNT))
                {
                    mediaItem.UserData.Add(UserDataKeysKnown.KEY_PLAY_COUNT, "0");
                }
                currentPlayCount = Convert.ToInt32(mediaItem.UserData[UserDataKeysKnown.KEY_PLAY_COUNT]);
                currentPlayCount++;
                mediaItem.UserData[UserDataKeysKnown.KEY_PLAY_COUNT] = currentPlayCount.ToString();

                if (userProfileDataManagement.IsValidUser)
                {
                    userProfileDataManagement.UserProfileDataManagement.SetUserMediaItemData(userProfileDataManagement.CurrentUser.ProfileId, mediaItem.MediaItemId,
                                                                                             UserDataKeysKnown.KEY_PLAY_COUNT, currentPlayCount.ToString());
                }
            }
            ContentDirectoryMessaging.SendMediaItemChangedMessage(mediaItem, ContentDirectoryMessaging.MediaItemChangeType.Updated);
        }
コード例 #4
0
        public override void Save()
        {
            base.Save();
            PlayerManagerSettings settings = SettingsManager.Load <PlayerManagerSettings>();

            settings.WatchedPlayPercentage = (int)_value;
            SettingsManager.Save(settings);
        }
コード例 #5
0
        protected static async Task NotifyPlayback(MediaItem mediaItem, int playPercentage, double playDuration)
        {
            ISettingsManager      settingsManager = ServiceRegistration.Get <ISettingsManager>();
            PlayerManagerSettings settings        = settingsManager.Load <PlayerManagerSettings>();
            bool watched = playPercentage >= settings.WatchedPlayPercentage;

            if (watched && mediaItem.IsLastPart)
            {
                playPercentage = 100;
            }
            else if (watched && !mediaItem.IsLastPart)
            {
                playPercentage = 50;
            }

            IServerConnectionManager scm = ServiceRegistration.Get <IServerConnectionManager>();
            IContentDirectory        cd  = scm.ContentDirectory;

            if (cd != null)
            {
                IUserManagement userProfileDataManagement = ServiceRegistration.Get <IUserManagement>();
                if (userProfileDataManagement.IsValidUser)
                {
                    bool updatePlayDate = (watched || playDuration >= MINIMUM_WATCHED_SEC || playPercentage >= MINIMUM_WATCHED_PERCENT);
                    await cd.NotifyUserPlaybackAsync(userProfileDataManagement.CurrentUser.ProfileId, mediaItem.MediaItemId, playPercentage, updatePlayDate);
                }
                else
                {
                    await cd.NotifyPlaybackAsync(mediaItem.MediaItemId, watched);
                }
            }

            // Update loaded item also, so changes will be visible in GUI without reloading
            if (!mediaItem.UserData.ContainsKey(UserDataKeysKnown.KEY_PLAY_PERCENTAGE))
            {
                mediaItem.UserData.Add(UserDataKeysKnown.KEY_PLAY_PERCENTAGE, "0");
            }
            mediaItem.UserData[UserDataKeysKnown.KEY_PLAY_PERCENTAGE] = UserDataKeysKnown.GetSortablePlayPercentageString(playPercentage);

            if (watched)
            {
                // Update loaded item also, so changes will be visible in GUI without reloading
                int currentPlayCount;
                if (MediaItemAspect.TryGetAttribute(mediaItem.Aspects, MediaAspect.ATTR_PLAYCOUNT, 0, out currentPlayCount))
                {
                    MediaItemAspect.SetAttribute(mediaItem.Aspects, MediaAspect.ATTR_PLAYCOUNT, ++currentPlayCount);
                }

                if (!mediaItem.UserData.ContainsKey(UserDataKeysKnown.KEY_PLAY_COUNT))
                {
                    mediaItem.UserData.Add(UserDataKeysKnown.KEY_PLAY_COUNT, UserDataKeysKnown.GetSortablePlayCountString(0));
                }
                currentPlayCount = Convert.ToInt32(mediaItem.UserData[UserDataKeysKnown.KEY_PLAY_COUNT]);
                currentPlayCount++;
                mediaItem.UserData[UserDataKeysKnown.KEY_PLAY_COUNT] = UserDataKeysKnown.GetSortablePlayCountString(currentPlayCount);
            }
            ContentDirectoryMessaging.SendMediaItemChangedMessage(mediaItem, ContentDirectoryMessaging.MediaItemChangeType.Updated);
        }