From e2d6a5c05df874cb812cbc0b85e7deda22ce567a Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 17 May 2013 14:05:49 -0400 Subject: support static trailer streaming --- .../Session/SessionManager.cs | 37 ++++++++++++++-------- 1 file changed, 23 insertions(+), 14 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Session') diff --git a/MediaBrowser.Server.Implementations/Session/SessionManager.cs b/MediaBrowser.Server.Implementations/Session/SessionManager.cs index 2f9c7e389..d3dbbc62b 100644 --- a/MediaBrowser.Server.Implementations/Session/SessionManager.cs +++ b/MediaBrowser.Server.Implementations/Session/SessionManager.cs @@ -200,7 +200,7 @@ namespace MediaBrowser.Server.Implementations.Session /// Name of the device. /// /// - public void OnPlaybackStart(User user, BaseItem item, string clientType, string deviceId, string deviceName) + public async Task OnPlaybackStart(User user, BaseItem item, string clientType, string deviceId, string deviceName) { if (user == null) { @@ -213,6 +213,15 @@ namespace MediaBrowser.Server.Implementations.Session UpdateNowPlayingItemId(user, clientType, deviceId, deviceName, item, false); + var key = item.GetUserDataKey(); + + var data = await _userDataRepository.GetUserData(user.Id, key).ConfigureAwait(false); + + data.PlayCount++; + data.LastPlayedDate = DateTime.UtcNow; + + await _userDataRepository.SaveUserData(user.Id, key, data, CancellationToken.None).ConfigureAwait(false); + // Nothing to save here // Fire events to inform plugins EventHelper.QueueEventIfNotNull(PlaybackStart, this, new PlaybackProgressEventArgs @@ -254,7 +263,7 @@ namespace MediaBrowser.Server.Implementations.Session { var data = await _userDataRepository.GetUserData(user.Id, key).ConfigureAwait(false); - UpdatePlayState(item, data, positionTicks.Value, false); + UpdatePlayState(item, data, positionTicks.Value); await _userDataRepository.SaveUserData(user.Id, key, data, CancellationToken.None).ConfigureAwait(false); } @@ -297,7 +306,7 @@ namespace MediaBrowser.Server.Implementations.Session if (positionTicks.HasValue) { - UpdatePlayState(item, data, positionTicks.Value, true); + UpdatePlayState(item, data, positionTicks.Value); } else { @@ -322,11 +331,12 @@ namespace MediaBrowser.Server.Implementations.Session /// The item /// User data for the item /// The current playback position - /// Whether or not to increment playcount - private void UpdatePlayState(BaseItem item, UserItemData data, long positionTicks, bool incrementPlayCount) + private void UpdatePlayState(BaseItem item, UserItemData data, long positionTicks) { + var hasRuntime = item.RunTimeTicks.HasValue && item.RunTimeTicks > 0; + // If a position has been reported, and if we know the duration - if (positionTicks > 0 && item.RunTimeTicks.HasValue && item.RunTimeTicks > 0) + if (positionTicks > 0 && hasRuntime) { var pctIn = Decimal.Divide(positionTicks, item.RunTimeTicks.Value) * 100; @@ -334,7 +344,6 @@ namespace MediaBrowser.Server.Implementations.Session if (pctIn < _configurationManager.Configuration.MinResumePct) { positionTicks = 0; - incrementPlayCount = false; } // If we're at the end, assume completed @@ -356,19 +365,19 @@ namespace MediaBrowser.Server.Implementations.Session } } } + else if (!hasRuntime) + { + // If we don't know the runtime we'll just have to assume it was fully played + data.Played = true; + positionTicks = 0; + } if (item is Audio) { - data.PlaybackPositionTicks = 0; + positionTicks = 0; } data.PlaybackPositionTicks = positionTicks; - - if (incrementPlayCount) - { - data.PlayCount++; - data.LastPlayedDate = DateTime.UtcNow; - } } } } -- cgit v1.2.3