Esempio n. 1
0
        public override void ActivateResource(ResourceActivationContext context, SavePoint resource)
        {
            if (!context.IsClosed)
            {
                var time = context.Retrieve <string>();

                if (time == null)
                {
                    context.Store(DateTime.Now.ToString());

                    SavePointManager.Instance.ActivateSavePoint(context, resource);
                }

                context.Close();
            }

            base.ActivateResource(context, resource);
        }
Esempio n. 2
0
        public void PlayAudioContent(ResourceActivationContext activationContext, LocalizedAudioContent audioContent, AudioContentRoute route, Action <Action> beforeOpen, Action onComplete)
        {
            if (IsPaused)
            {
                m_onUnpause[activationContext.InstanceId] = () => { PlayAudioContent(activationContext, audioContent, route, beforeOpen, onComplete); };
                return;
            }

            if (audioContent == null ||
                audioContent.MediaItem == null)
            {
                m_logger.Warning("Playable did not contain audio content!");

                if (onComplete != null)
                {
                    onComplete();
                }

                return;
            }

            var path   = WebServices.Instance.MediaDownloadManager.GetPathForItem(audioContent.MediaItem.Url);
            var player = m_channel.CreatePlayer(new Uri(path));

            player.Loop   = audioContent.Loop;
            player.Volume = audioContent.Volume;

            PlaybackContext Resume = activationContext.Retrieve <PlaybackContext>();

            if (Resume != null)
            {
                player.Position = Resume.PausedTime;
            }

            var ctxt = new PlayerContext(activationContext, player, audioContent);

            lock (m_playablePlayers)
            {
                m_playablePlayers.Add(activationContext.InstanceId, ctxt);
            }

            // Set up values
            Action play = () =>
            {
                switch (route)
                {
                case AudioContentRoute.Soundtrack:
                {
                    // FIX:: SOUNDTRACK LOCK OBJECT.
                    lock (SoundtrackLockObject)
                    {
                        bool fadeIn = false;

                        if (CurrentSoundtrackPlayer != null && m_isPlayingSoundtrack)
                        {
                            fadeIn = true;

                            // Main thing we're trying to do here is make sure we don't stack a bunch
                            // of previously activated sounds if they weren't deactivated
                            if (m_currentSoundtrackPlayTime.HasValue &&
                                (DateTime.Now - m_currentSoundtrackPlayTime.Value).TotalSeconds < FadeDuration / 2)
                            {
                                CurrentSoundtrackPlayer.Stop();
                            }
                            else
                            {
                                Fader.FadeOut(CurrentSoundtrackPlayer.Player, TimeSpan.FromSeconds(FadeDuration));
                            }
                        }

                        m_soundtrackPlayers.Add(ctxt);

                        if (m_isPlayingSoundtrack)
                        {
                            m_currentSoundtrackPlayTime = DateTime.Now;

                            if (fadeIn)
                            {
                                FadeInSoundtrack(ctxt, FadeDuration, onComplete);
                            }
                            else
                            {
                                player.Play((success) =>
                                    {
                                        StopPlaying(activationContext);

                                        onComplete();
                                    });
                            }
                        }
                    }
                    break;
                }

                case AudioContentRoute.Narrator:
                {
                    CurrentNarratorPlayer = player;

                    // Optionally duck the other channels
                    DuckExcept(ctxt);

                    player.Play((success) =>
                        {
                            CurrentNarratorPlayer = null;

                            Unduck();

                            StopPlaying(activationContext);

                            onComplete();
                        });

                    break;
                }

                case AudioContentRoute.Ambient:
                default:
                {
                    player.Play((success) =>
                        {
                            StopPlaying(activationContext);

                            onComplete();
                        });

                    break;
                };
                }
            };

            if (beforeOpen != null)
            {
                beforeOpen(play);
            }
            else
            {
                play();
            }
        }