void OnMessageReceived(AsynchronousMessageQueue queue, SystemMessage message) { if (message.ChannelName == WorkflowManagerMessaging.CHANNEL) { // Adjust our knowledge about the currently opened FSC/CP state if the user switches to one of them WorkflowManagerMessaging.MessageType messageType = (WorkflowManagerMessaging.MessageType)message.MessageType; switch (messageType) { case WorkflowManagerMessaging.MessageType.StatesPopped: ICollection <Guid> statesRemoved = new List <Guid>( ((IDictionary <Guid, NavigationContext>)message.MessageData[WorkflowManagerMessaging.CONTEXTS]).Keys); HandleStatesRemovedFromWorkflowStack(statesRemoved); break; case WorkflowManagerMessaging.MessageType.StatePushed: NavigationContext context = (NavigationContext)message.MessageData[WorkflowManagerMessaging.CONTEXT]; Guid stateId = context.WorkflowState.StateId; HandleWorkflowStatePushed(stateId); break; } } else if (message.ChannelName == PlayerManagerMessaging.CHANNEL) { // React to player changes PlayerManagerMessaging.MessageType messageType = (PlayerManagerMessaging.MessageType)message.MessageType; IPlayerSlotController psc; MediaItem mediaItem; switch (messageType) { case PlayerManagerMessaging.MessageType.PlayerResumeState: psc = (IPlayerSlotController)message.MessageData[PlayerManagerMessaging.PLAYER_SLOT_CONTROLLER]; IResumeState resumeState = (IResumeState)message.MessageData[PlayerManagerMessaging.KEY_RESUME_STATE]; mediaItem = (MediaItem)message.MessageData[PlayerManagerMessaging.KEY_MEDIAITEM]; HandleResumeInfo(psc, mediaItem, resumeState).Wait(); break; case PlayerManagerMessaging.MessageType.PlayerError: case PlayerManagerMessaging.MessageType.PlayerEnded: psc = (IPlayerSlotController)message.MessageData[PlayerManagerMessaging.PLAYER_SLOT_CONTROLLER]; HandlePlayerEnded(psc); break; case PlayerManagerMessaging.MessageType.PlayerStopped: psc = (IPlayerSlotController)message.MessageData[PlayerManagerMessaging.PLAYER_SLOT_CONTROLLER]; TimeSpan?position = null; if (message.MessageData.ContainsKey(PlayerManagerMessaging.PLAYER_POSITION)) { position = (TimeSpan?)message.MessageData[PlayerManagerMessaging.PLAYER_POSITION]; } HandlePlayerStopped(psc, position); break; case PlayerManagerMessaging.MessageType.RequestNextItem: psc = (IPlayerSlotController)message.MessageData[PlayerManagerMessaging.PLAYER_SLOT_CONTROLLER]; HandleRequestNextItem(psc); break; } CleanupPlayerContexts(); CheckMediaWorkflowStates_NoLock(); // Primary player could have been changed or closed or CP player could have been closed } else if (message.ChannelName == PlayerContextManagerMessaging.CHANNEL) { // React to internal player context manager changes PlayerContextManagerMessaging.MessageType messageType = (PlayerContextManagerMessaging.MessageType)message.MessageType; switch (messageType) { case PlayerContextManagerMessaging.MessageType.UpdatePlayerRolesInternal: PlayerContext newCurrentPlayer = (PlayerContext)message.MessageData[PlayerContextManagerMessaging.NEW_CURRENT_PLAYER_CONTEXT]; PlayerContext newAudioPlayer = (PlayerContext)message.MessageData[PlayerContextManagerMessaging.NEW_AUDIO_PLAYER_CONTEXT]; HandleUpdatePlayerRoles(newCurrentPlayer, newAudioPlayer); break; // PlayerContextManagerMessaging.MessageType.CurrentPlayerChanged not handled here } } }
protected void HandleUpdatePlayerRoles(PlayerContext newCurrentPlayerContext, PlayerContext newAudioPlayerContext) { IPlayerManager playerManager = ServiceRegistration.Get <IPlayerManager>(); CurrentPlayerContext = newCurrentPlayerContext; playerManager.AudioSlotController = newAudioPlayerContext.PlayerSlotController; }
protected static PlayerContext GetPlayerContextInternal(int slotIndex) { IPlayerManager playerManager = ServiceRegistration.Get <IPlayerManager>(); return(PlayerContext.GetPlayerContext(playerManager.GetPlayerSlotController(slotIndex))); }