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; } }
private void SetPlayerAndContentDirForMovie(IMediaPortalServices mediaPortalServices, MediaItem mediaItem) { IList <MediaItem> mediaItems = new List <MediaItem>(); mediaItems.Add(mediaItem); IContentDirectory contentDirectory = Substitute.For <IContentDirectory>(); contentDirectory.SearchAsync(Arg.Any <MediaItemQuery>(), false, null, true).Returns(mediaItems); mediaPortalServices.GetServerConnectionManager().ContentDirectory.Returns(contentDirectory); IPlayerContext playerContext = Substitute.For <IPlayerContext>(); playerContext.CurrentMediaItem.Returns(mediaItem); IPlayer player = Substitute.For <IPlayer, IMediaPlaybackControl>(); ((IMediaPlaybackControl)player).Duration.Returns(TimeSpan.FromMinutes(90)); playerContext.CurrentPlayer.Returns(player); mediaPortalServices.GetPlayerContext(Arg.Any <IPlayerSlotController>()).Returns(playerContext); }