Пример #1
0
        public void StartSoundtrack()
        {
            // FIX:: SOUNDTRACK LOCK OBJECT.
            lock (SoundtrackLockObject)
            {
                m_isPlayingSoundtrack = true;

                if (CurrentSoundtrackPlayer != null)
                {
                    m_currentSoundtrackPlayTime = DateTime.Now;

                    CurrentSoundtrackPlayer.Play();
                }
            }
        }
Пример #2
0
        public void PlayAudioContent(string instanceId, LocalizedAudioContent audioContent, AudioContentRoute route, Action <Action> beforeOpen, Action onComplete)
        {
            if (IsPaused)
            {
                m_onUnpause[instanceId] = () => { PlayAudioContent(instanceId, 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;

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

            lock (m_playablePlayers)
            {
                m_playablePlayers.Add(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(instanceId);

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

                case AudioContentRoute.Narrator:
                {
                    CurrentNarratorPlayer = player;

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

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

                            Unduck();

                            StopPlaying(instanceId);

                            onComplete();
                        });

                    break;
                }

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

                            onComplete();
                        });

                    break;
                };
                }
            };

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