private void OnMessageReceived(AsynchronousMessageQueue queue, SystemMessage message) { if (message.ChannelName == SystemMessaging.CHANNEL) { SystemMessaging.MessageType messageType = (SystemMessaging.MessageType)message.MessageType; switch (messageType) { case SystemMessaging.MessageType.SystemStateChanged: SystemState newState = (SystemState)message.MessageData[SystemMessaging.NEW_STATE]; if (newState == SystemState.Resuming) { // Signal the event, callback is executed after timeout, see OnResume _resumeEvent.EnqueueEvent(this, EventArgs.Empty); } if (newState == SystemState.Suspending) { ServiceRegistration.Get <ILogger>().Info("SlimTvClientModel: System suspending, stopping all SlimTV players"); IPlayerContextManager playerContextManager = ServiceRegistration.Get <IPlayerContextManager>(); for (int index = 0; index < playerContextManager.NumActivePlayerContexts; index++) { IPlayerContext playerContext = playerContextManager.GetPlayerContext(index); if (playerContext != null && playerContext.CurrentMediaItem is LiveTvMediaItem) { playerContext.Stop(); _tvWasActive = true; } } } break; } } }
void StopPlayer <T>() { IPlayerContext context = GetPlayerContext <T>(); if (context != null) { context.Stop(); } }
public void Stop() { IPlayerContext playerContext = CurrentPlayerContext; if (playerContext == null) { return; } playerContext.Stop(); }
private void OnMessageReceived(AsynchronousMessageQueue queue, SystemMessage message) { if (message.ChannelName == SystemMessaging.CHANNEL) { SystemMessaging.MessageType messageType = (SystemMessaging.MessageType)message.MessageType; switch (messageType) { case SystemMessaging.MessageType.SystemStateChanged: SystemState newState = (SystemState)message.MessageData[SystemMessaging.NEW_STATE]; if (newState == SystemState.Resuming) { // Signal the event, callback is executed after timeout, see OnResume _resumeEvent.EnqueueEvent(this, EventArgs.Empty); } if (newState == SystemState.Suspending) { ServiceRegistration.Get <ILogger>().Info("SlimTvClientModel: System suspending, stopping all SlimTV players"); IPlayerContextManager playerContextManager = ServiceRegistration.Get <IPlayerContextManager>(); for (int index = 0; index < playerContextManager.NumActivePlayerContexts; index++) { IPlayerContext playerContext = playerContextManager.GetPlayerContext(index); if (playerContext != null && playerContext.CurrentMediaItem is LiveTvMediaItem ltvi) { if (ltvi.AdditionalProperties.ContainsKey(LiveTvMediaItem.CHANNEL)) { _ = UpdateWatchDuration((IChannel)ltvi.AdditionalProperties[LiveTvMediaItem.CHANNEL]); } playerContext.Stop(); _tvWasActive = true; } } } break; } } else if (message.ChannelName == ServerStateMessaging.CHANNEL) { //Check if Tv Server state has changed and update if necessary ServerStateMessaging.MessageType messageType = (ServerStateMessaging.MessageType)message.MessageType; if (messageType == ServerStateMessaging.MessageType.StatesChanged) { var states = message.MessageData[ServerStateMessaging.STATES] as IDictionary <Guid, object>; if (states != null && states.ContainsKey(TvServerState.STATE_ID)) { ServerState = states[TvServerState.STATE_ID] as TvServerState; } } } else if (message.ChannelName == PlayerManagerMessaging.CHANNEL) { PlayerManagerMessaging.MessageType messageType = (PlayerManagerMessaging.MessageType)message.MessageType; switch (messageType) { case PlayerManagerMessaging.MessageType.PlayerStopped: case PlayerManagerMessaging.MessageType.PlayerEnded: if (_lastTunedChannel != null) { _ = UpdateWatchDuration(_lastTunedChannel); } break; } } }