public override void Play(ResourceActivationContext activationContext, PlayableContent playable, Action onClose = null)
        {
            if (playable.Content is LocalizedAudioContent)
            {
                QueueAudioContent(activationContext, playable, playable.Content as LocalizedAudioContent, onClose);
            }
            else if (playable.Content is LocativeAudioContent)
            {
                m_locativeAudioProcessor.ActivateResource(activationContext, playable.Content as LocativeAudioContent);
            }
            else if (IsScreenContent(playable))
            {
                QueueScreenContent(activationContext, playable, onClose);
            }
            else
            {
                m_logger.Warning("Unhandled content type {0} (playable.Id={1})",
                                 playable.Content != null ? playable.Content.Type : null,
                                 playable.Id);

                if (onClose != null)
                {
                    onClose();
                }
            }
        }
        protected virtual void PlayNotification(ResourceActivationContext context, PlayableContent playable, Notification notification, ResourcePanelData <Notification> data, Action onClose)
        {
            if (Platform.Instance.IsInBackground)
            {
                context.Open();

                if (!BackgroundNotifier.Instance.HasNotification(context.InstanceId))
                {
                    var localNotification = new Motive.Core.Notifications.LocalNotification();

                    localNotification.Title = notification.Title;
                    localNotification.Text  = notification.Message;

                    Platform.Instance.LocalNotificationManager.PostNotification(playable.Id, localNotification);
                }

                BackgroundNotifier.Instance.RemoveNotification(context.InstanceId);

                /*
                 * if (notification.SoundUrl != null)
                 * {
                 *  var path = WebServices.Instance.MediaDownloadManager.GetPathForItem(notification.SoundUrl);
                 *  m_channel.Play(new Uri(path));
                 * }*/

                if (onClose != null)
                {
                    onClose();
                }
            }
            else
            {
                if (notification.Title != null ||
                    notification.Message != null)
                {
                    Push(context, PanelStack, NotificationPanel, data, onClose);
                }
                else
                {
                    context.Open();

                    if (notification.Vibrate)
                    {
                        Platform.Instance.LocalNotificationManager.Vibrate();
                    }

                    if (notification.Sound != null)
                    {
                        Platform.Instance.PlaySound(notification.Sound.Url);
                    }

                    if (onClose != null)
                    {
                        onClose();
                    }
                }
            }
        }
        void Play(BatchContext context, PlayableContent playable, Action onClose)
        {
            if (!context.ActivationContext.IsClosed)
            {
                // If there's a script timer, use the activation time as a base to
                // play this content later.
                if (playable.Timer != null)
                {
                    // Use clock manager so that we can use debug clock features
                    var fireTime = playable.Timer.GetNextFireTime(context.ActivationContext.ActivationTime);
                    var delta    = ClockManager.Instance.GetTimespanFromNow(fireTime);

                    if (delta.TotalSeconds > 0)
                    {
                        // Actual play time is real Now + delta - this can be different from the
                        // computed fire time above if we're using a debug clock.
                        var actualPlayTime = DateTime.Now + delta;

                        Delegate.Preview(context.ActivationContext, playable, actualPlayTime);
                    }

                    context.Timer = Timer.Call(delta,
                                               () =>
                    {
                        m_logger.Debug("Fired timer!");

                        Delegate.Play(context.ActivationContext, playable, () =>
                        {
                            context.ActivationContext.Close();

                            if (onClose != null)
                            {
                                onClose();
                            }
                        });
                    });
                }
                else
                {
                    Delegate.Play(context.ActivationContext, playable, () =>
                    {
                        context.ActivationContext.Close();

                        if (onClose != null)
                        {
                            onClose();
                        }
                    });
                }
            }
            else
            {
                if (onClose != null)
                {
                    onClose();
                }
            }
        }
        protected virtual void PlayScreenContent(ResourceActivationContext context, PlayableContent playable, Action onClose)
        {
            if (playable.Content is ScreenMessage)
            {
                var screenMsg = playable.Content as ScreenMessage;

                var data = new ResourcePanelData <ScreenMessage>(context, screenMsg);

                if (screenMsg.Responses != null && screenMsg.Responses.Length > 0)
                {
                    PushScreenDialogPanel(context, playable, screenMsg, data, onClose);
                }
                else
                {
                    PushScreenMessagePanel(context, playable, screenMsg, data, onClose);
                }
            }
            else if (playable.Content is CharacterMessage)
            {
                var charMsg = playable.Content as CharacterMessage;

                var data = new ResourcePanelData <CharacterMessage>(context, charMsg);

                if (charMsg.Responses != null && charMsg.Responses.Length > 0)
                {
                    PushCharacterDialogPanel(context, playable, charMsg, data, onClose);
                }
                else
                {
                    PushCharacterMessagePanel(context, playable, charMsg, data, onClose);
                }
            }
            else if (playable.Content is Notification)
            {
                var notification = playable.Content as Notification;

                var data = new ResourcePanelData <Notification>(context, notification);

                PlayNotification(context, playable, playable.Content as Notification, data, onClose);
            }
            else if (playable.Content is MediaContent)
            {
                var media = playable.Content as MediaContent;

                var data = new ResourcePanelData <MediaContent>(context, media);

                PlayMediaContent(context, playable, media, data, onClose);
            }
            else
            {
                m_logger.Error("Unsupported content type with route=screen: {0}",
                               playable.Content == null ? "null" : playable.Content.Type);
            }
        }
        protected virtual bool IsScreenContent(PlayableContent playable)
        {
            if (playable.Content is ScreenMessage ||
                playable.Content is CharacterMessage ||
                playable.Content is Notification ||
                playable.Route == "screen")
            {
                return(true);
            }

            return(IsVideoContent(playable.Content) || IsImageContent(playable.Content));
        }
        void QueueAudioContent(ResourceActivationContext activationContext, PlayableContent playable, LocalizedAudioContent localizedAudio, Action onClose)
        {
            var audioRoute = GetRouteForAudioContent(playable);

            if (audioRoute == AudioContentRoute.Narrator)
            {
                AddToQueue(m_narratorQueue, activationContext, playable, PlayAudioContent, onClose);
            }
            else
            {
                PlayAudioContent(activationContext, playable, onClose);
            }
        }
        internal void Remove(PlayableContent playable)
        {
            lock (m_queuedPlayables)
            {
                if (CurrentlyPlaying != null && CurrentlyPlaying.Playable == playable)
                {
                    LastPlayFinish = DateTime.Now;

                    CurrentlyPlaying = null;
                }

                m_queuedPlayables.RemoveAll((_ctxt) => _ctxt.Playable == playable);
            }
        }
        public override void Activate(LocationAttraction attraction, bool autoplay)
        {
            // Activate (with autoplay)
            if (autoplay && Item != null)
            {
                var playable = new PlayableContent
                {
                    Content = Item,
                    Route   = PlayableContentRoute.Screen
                };

                PlayableContentHandler.Instance.Play(ActivationContext, playable);
            }
        }
        /// <summary>
        /// Play the specified playable. NOTE that this is called off-thread! Any
        /// interaction with Unity needs to use ThreadHelper.
        /// </summary>
        /// <param name="ctxt">Ctxt.</param>
        /// <param name="playable">Playable.</param>
        /// <param name="onClose">On close.</param>
        public void Play(ResourceActivationContext ctxt, PlayableContent playable, Action onClose = null)
        {
            m_logger.Debug("Play {0}", playable.Type);

            BatchContext playableContext = new BatchContext
            {
                ActivationContext = ctxt,
                Playables         = new PlayableContent[] { playable }
            };

            m_containers[ctxt.InstanceId] = playableContext;

            Play(playableContext, playable, onClose);
        }
        protected virtual AudioContentRoute GetRouteForAudioContent(PlayableContent playable)
        {
            switch (playable.Route)
            {
            case PlayableContentRoute.Narrator:
                return(AudioContentRoute.Narrator);

            case PlayableContentRoute.Soundtrack:
                return(AudioContentRoute.Soundtrack);

            case PlayableContentRoute.Ambient:
                return(AudioContentRoute.Ambient);
            }

            return(AudioContentRoute.Ambient);
        }
        public override void StopPlaying(ResourceActivationContext ctxt, PlayableContent playable, bool interrupt = false)
        {
            PlayableContentQueue queue = null;

            lock (m_queues)
            {
                m_queues.TryGetValue(ctxt.InstanceId, out queue);
            }

            var audioContent = playable.Content as LocalizedAudioContent;

            if (audioContent != null)
            {
                if (AudioContentPlayer.Instance.StopPlaying(ctxt.InstanceId, interrupt))
                {
                    // If audio content player didn't stop in this call, the playable will
                    // stop playing and call back, we can remove it from the queue then
                    if (queue != null)
                    {
                        queue.Remove(playable);
                    }
                }
            }
            else if (playable.Content is LocativeAudioContent)
            {
                m_locativeAudioProcessor.DeactivateResource(ctxt, playable.Content as LocativeAudioContent);
            }
            else
            {
                if (queue != null)
                {
                    queue.Remove(playable);
                }
            }

            lock (m_queues)
            {
                m_queues.Remove(ctxt.InstanceId);
            }

            if (queue != null)
            {
                PlayNextSequentialContent(queue);
            }
        }
 protected virtual void PlayMediaContent(ResourceActivationContext context, PlayableContent playable, MediaContent media, ResourcePanelData <MediaContent> data, Action onClose)
 {
     if (IsAudioContent(playable.Content))
     {
         PushAudioPanel(context, playable, media, data, onClose);
     }
     else if (IsImageContent(playable.Content))
     {
         PushImagePanel(context, playable, media, data, onClose);
     }
     else if (IsVideoContent(media))
     {
         PushVideoPanel(context, playable, media, data, onClose);
     }
     else
     {
         m_logger.Error("Unsupported content type with route=screen: {0}",
                        playable.Content == null ? "null" : playable.Content.Type);
     }
 }
 protected virtual Panel GetScreenDialogPanel(ResourceActivationContext context, PlayableContent playable)
 {
     return(ScreenDialogPanel);
 }
        protected virtual void QueueNotification(ResourceActivationContext activationContext, PlayableContent playable, Action onClose)
        {
            var notification = (Notification)playable.Content;

            PlayNotification(activationContext, playable, notification, new ResourcePanelData <Notification>(activationContext, notification), onClose);
        }
 protected virtual Panel GetCharacterDialogPanel(ResourceActivationContext context, PlayableContent playable)
 {
     return(CharacterDialogPanel);
 }
 protected virtual void PushAudioPanel(ResourceActivationContext context, PlayableContent playable, MediaContent media, ResourcePanelData <MediaContent> data, Action onClose)
 {
     Push(context, PanelStack, GetAudioPanel(context, playable), data, onClose);
 }
 protected virtual void PushCharacterMessagePanel(ResourceActivationContext context, PlayableContent playable, CharacterMessage charMsg, ResourcePanelData <CharacterMessage> data, Action onClose)
 {
     Push(context, PanelStack, GetCharacterMessagePanel(context, playable), data, onClose);
 }
Example #18
0
 public abstract void Play(ResourceActivationContext activationContext, PlayableContent playable, Action onClose);
 public override void Preview(ResourceActivationContext activationContext, PlayableContent playable, DateTime playTime)
 {
     // Preview is called for playables that will be played in the future.
     // This can be useful for setting up system notifications.
 }
        public virtual void PlayAudioContent(ResourceActivationContext activationContext, PlayableContent playable, Action onClose)
        {
            activationContext.Open();

            AudioContentPlayer.Instance.PlayAudioContent(activationContext.InstanceId, playable.Content as LocalizedAudioContent, GetRouteForAudioContent(playable), (whenDone) =>
            {
                BeforePlayAudio(activationContext, playable, whenDone);
            },
                                                         () =>
            {
                AfterPlayAudio(activationContext, playable, onClose);
            });
        }
 protected virtual void AfterPlayAudio(ResourceActivationContext activationContext, PlayableContent playable, Action onComplete)
 {
     onComplete();
 }
        protected PlayableContentQueue GetQueue(ResourceActivationContext activationContext, PlayableContent playable)
        {
            if (playable.Content is ScreenMessage || playable.Content is CharacterMessage)
            {
                return(m_screenQueue);
            }

            return(null);
        }
 protected virtual Panel GetVideoPanel(ResourceActivationContext context, PlayableContent playable)
 {
     return(VideoPanel);
 }
Example #24
0
 public abstract void Preview(ResourceActivationContext activationContext, PlayableContent playable, DateTime playTime);
 protected virtual PlayableContentQueue GetScreenContentQueue(ResourceActivationContext activationContext, PlayableContent playable)
 {
     return(m_screenQueue);
 }
Example #26
0
 public abstract void StopPlaying(ResourceActivationContext activationContext, PlayableContent playable, bool interrupt);
        protected virtual void AddToQueue(PlayableContentQueue queue, ResourceActivationContext activationContext, PlayableContent playable, PlayContentDelegate onPlay, Action onClose)
        {
            lock (m_queues)
            {
                m_queues.Add(activationContext.InstanceId, queue);
            }

            switch (playable.Priority)
            {
            case PlayableContentPriority.High:
                // Todo: actually want to be a bit more clever and *don't* move in front of
                // other high priority ones.
                queue.AddToFront(
                    new QueuedPlayableContext
                {
                    ActivationContext = activationContext,
                    Playable          = playable,
                    OnClose           = onClose,
                    OnPlay            = onPlay
                });

                PlayNextSequentialContent(queue);
                break;

            case PlayableContentPriority.Interrupt:
                QueuedPlayableContext toStop = null;

                lock (queue.SyncRoot)
                {
                    toStop = queue.CurrentlyPlaying;
                }

                if (toStop != null)
                {
                    StopPlaying(toStop.ActivationContext, toStop.Playable, true);
                    toStop.ActivationContext.Close();
                }

                queue.AddToFront(
                    new QueuedPlayableContext
                {
                    ActivationContext = activationContext,
                    Playable          = playable,
                    OnClose           = onClose,
                    OnPlay            = onPlay
                });

                PlayNextSequentialContent(queue);
                break;

            case PlayableContentPriority.Filler:
                // Only if nothing has played on this queue for a while...
                bool doPlay = false;

                lock (queue.SyncRoot)
                {
                    doPlay = queue.CurrentlyPlaying == null &&
                             (DateTime.Now - queue.LastPlayFinish).TotalSeconds >= MinFillerDelay;
                }

                if (doPlay)
                {
                    queue.Add(
                        new QueuedPlayableContext
                    {
                        ActivationContext = activationContext,
                        Playable          = playable,
                        OnClose           = onClose,
                        OnPlay            = onPlay
                    });

                    PlayNextSequentialContent(queue);
                }
                break;

            case PlayableContentPriority.Normal:
            default:
                queue.Add(
                    new QueuedPlayableContext
                {
                    ActivationContext = activationContext,
                    Playable          = playable,
                    OnClose           = onClose,
                    OnPlay            = onPlay
                });

                PlayNextSequentialContent(queue);
                break;
            }
        }
        protected virtual void QueueScreenContent(ResourceActivationContext activationContext, PlayableContent playable, Action onClose)
        {
            var queue = GetScreenContentQueue(activationContext, playable);

            if (queue != null)
            {
                AddToQueue(queue, activationContext, playable, PlayScreenContent, onClose);
            }
            else
            {
                PlayScreenContent(activationContext, playable, onClose);
            }
        }
 protected virtual void PushScreenMessagePanel(ResourceActivationContext context, PlayableContent playable, ScreenMessage screenMsg, ResourcePanelData <ScreenMessage> data, Action onClose)
 {
     Push(context, PanelStack, GetScreenMessagePanel(context, playable), data, onClose);
 }