Ejemplo n.º 1
0
        public static void Play()
        {
            FrameworkDispatcher.Update();

            switch (MediaPlayer.State)
            {
            case MediaState.Playing:

                var toast = new ToastPrompt
                {
                    Message  = AppResources.TextMusicIsPlaying,
                    FontSize = 30,
                };
                toast.Show();
                break;

            case MediaState.Paused:

                MediaPlayer.Resume();

                break;

            case MediaState.Stopped:

                var mediaLibrary = new MediaLibrary();

                if (mediaLibrary.Songs.Count > 0)
                {
                    MediaPlayer.Play(mediaLibrary.Songs);
                }

                break;
            }
        }
Ejemplo n.º 2
0
        // 提示音提醒 方法
        private void Ring()
        {
            Stream stream = TitleContainer.OpenStream(SoundModel.GetSoundUriByID(soundId));

            effectInstance = SoundEffect.FromStream(stream).CreateInstance();
            FrameworkDispatcher.Update();
            int times = 20;

            new Thread(new ParameterizedThreadStart(param =>
            {
                do
                {
                    if (effectInstance.State.Equals(SoundState.Stopped))
                    {
                        effectInstance.Play();

                        times--;
                    }
                    Thread.Sleep(2000);

                    if (times == 0)
                    {
                        break;
                    }

                    if (loopPlay == false)
                    {
                        break;
                    }
                } while (true);
            })).Start();
        }
Ejemplo n.º 3
0
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            this.DataContext = _viewModel.Items;

            var dragReOrderInteraction = new DragReOrderInteraction(dragImageControl);

            dragReOrderInteraction.Initialise(todoList, _viewModel.Items);

            var swipeInteraction = new SwipeInteraction();

            swipeInteraction.Initialise(todoList, _viewModel.Items);

            var tapEditInteraction = new TapEditInteraction();

            tapEditInteraction.Initialise(todoList, _viewModel.Items);

            var addItemInteraction = new PullDownToAddNewInteraction(tapEditInteraction, pullDownItemInFront);

            addItemInteraction.Initialise(todoList, _viewModel.Items);

            _pinchAddNewItemInteraction = new PinchAddNewInteraction(tapEditInteraction, pullDownItemBehind);
            _pinchAddNewItemInteraction.Initialise(todoList, _viewModel.Items);

            _interactionManager.AddInteraction(swipeInteraction);
            _interactionManager.AddInteraction(dragReOrderInteraction);
            _interactionManager.AddInteraction(addItemInteraction);
            _interactionManager.AddInteraction(tapEditInteraction);
            _interactionManager.AddInteraction(_pinchAddNewItemInteraction);

            FrameworkDispatcher.Update();
        }
Ejemplo n.º 4
0
        private void PlayMusicButton_OnClick(object sender, RoutedEventArgs e)
        {
            MusicPopup.IsOpen = false;
            if (MusicList.SelectedItem == null)
            {
                return;
            }
            string chosenMusic = MusicList.SelectedItem.ToString();

            using (var library = new MediaLibrary())
            {
                foreach (var song in library.Songs)
                {
                    if (song.Name == chosenMusic)
                    {
                        FrameworkDispatcher.Update();
                        MediaPlayer.Play(song);
                        var uri = new Uri(StopIcon, UriKind.Relative);
                        MusicPlayButtonBackground.ImageSource = new BitmapImage(uri);
                        IsPlayingMusic = true;
                        return;
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public YapperChatTaskPivot()
        {
            InitializeComponent();

            UserSettingsModel.Instance.LastTaskPageViewTime = DateTime.Now;
            Messenger.Default.Send <SuspendTaskCountEvent>(new SuspendTaskCountEvent()
            {
                Suspend = true
            });
            YapperChatViewModel viewModel = new YapperChatViewModel(false);

            this.DataContext = viewModel;
            PushNotification.PushNotification.Instance.Setup();
            this.TasksListSelector.ItemsSource = viewModel.Tasks.Tasks;

            this.swipeInteraction = new SwipeInteraction <MessageModel>();
            swipeInteraction.Initialize(this.TasksListSelector, itemManager, viewModel.Tasks.Tasks);

            this.tapEditInteraction = new TapEditInteraction <MessageModel>();
            tapEditInteraction.Initialize(this.TasksListSelector, itemManager, viewModel.Tasks.Tasks);
            tapEditInteraction.SaveEditText = this.SaveTaskName;

            _interactionManager.AddInteraction(swipeInteraction);
            FrameworkDispatcher.Update();

            BuildLocalizedApplicationBar();
        }
Ejemplo n.º 6
0
        public Analysis()
        {
            InitializeComponent();

            var dispTimer = new DispatcherTimer {
                Interval = TimeSpan.FromMilliseconds(50)
            };

            dispTimer.Tick += delegate
            {
                try
                {
                    FrameworkDispatcher.Update();
                }
                catch
                {
                }
            };
            dispTimer.Start();
            MessageTextBlock.Text           = "";
            NoteTextBlock.Text              = "";
            CommandTextBlock.Text           = "Sing musical notes in the order - as high as you can and as low as you can. If you can't - just click \"STOP\"";
            _soundManager                   = new SoundManager(this);
            _soundManager.CorrectNoteEvent += OnCorrectNote;
        }
Ejemplo n.º 7
0
        // Check whether user is playing music on the phones media player

        public void checkMusic()
        {
            FrameworkDispatcher.Update();

            if (MediaPlayer.GameHasControl)
            {
                try
                {
                    Browser.InvokeScript("eval", "window['deviceMusicPlaying'] = false;");
                }
                catch
                {
                }
            }
            else
            {
                try
                {
                    Browser.InvokeScript("eval", "window['deviceMusicPlaying'] = true;");
                }
                catch
                {
                }
            }
        }
 public XNAFrameworkDispatcherService()
 {
     this.frameworkDispatcherTimer          = new DispatcherTimer();
     this.frameworkDispatcherTimer.Interval = TimeSpan.FromTicks(333333);
     this.frameworkDispatcherTimer.Tick    += frameworkDispatcherTimer_Tick;
     FrameworkDispatcher.Update();
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Updates the XNA FrameworkDispatcher and updates the playing state
        /// if sound has stopped playing.
        /// </summary>
        /// <param name="sender">DispatcherTimer.</param>
        /// <param name="e">Event arguments.</param>
        void dt_Tick(object sender, EventArgs e)
        {
            try { FrameworkDispatcher.Update(); }
            catch { }

            if (true == App.AudioModel.IsPlaying)
            {
                if (!wasapiInUse)
                {
                    if (!xnaAudio.SoundIsPlaying())
                    {
                        xnaAudio.StopPlayback();
                        App.AudioModel.IsPlaying = false;
                    }
                }
                else
                {
                    App.AudioModel.IsPlaying = wasapiAudio.Update();
                }
            }
            else if (true == App.AudioModel.IsRecording && wasapiInUse)
            {
                // XnaAudio stores the buffer in callback method.
                // Buffer is retrieved manually when recording using WASAPI.
                byte[] bytes = null;
                int    size  = wasapiAudio.ReadBytes(out bytes);

                if (size > 0)
                {
                    App.AudioModel.AudioBuffer = bytes;
                    App.AudioModel.stream.Write(bytes, 0, size);
                }
            }
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            FrameworkDispatcher.Update();
            Song temp = Song.FromUri("Question", new Uri(Question_Sound, UriKind.Relative));

            MediaPlayer.Play(temp);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Starts recording, data is stored in memory
 /// </summary>
 /// <param name="filePath"></param>
 public void startRecording(string filePath)
 {
     if (this.player != null)
     {
         this.handler.InvokeCustomScript(new ScriptCallback(CallbackFunction, this.id, MediaError, MediaErrorPlayModeSet));
     }
     else if (this.recorder == null)
     {
         try
         {
             this.audioFile = filePath;
             this.InitializeXnaGameLoop();
             this.recorder = Microphone.Default;
             this.recorder.BufferDuration = TimeSpan.FromMilliseconds(500);
             this.buffer = new byte[recorder.GetSampleSizeInBytes(this.recorder.BufferDuration)];
             this.recorder.BufferReady += new EventHandler <EventArgs>(recorderBufferReady);
             this.memoryStream          = new MemoryStream();
             this.WriteWavHeader(this.memoryStream, this.recorder.SampleRate);
             this.recorder.Start();
             FrameworkDispatcher.Update();
             this.SetState(MediaRunning);
         }
         catch (Exception)
         {
             this.handler.InvokeCustomScript(new ScriptCallback(CallbackFunction, this.id, MediaError, MediaErrorStartingRecording));
         }
     }
     else
     {
         this.handler.InvokeCustomScript(new ScriptCallback(CallbackFunction, this.id, MediaError, MediaErrorAlreadyRecording));
     }
 }
Ejemplo n.º 12
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            string select = null;
            string genre  = null;

            if (this.NavigationContext.QueryString.ContainsKey("select"))
            {
                select = this.NavigationContext.QueryString["select"];
            }
            if (this.NavigationContext.QueryString.ContainsKey("genre"))
            {
                genre = this.NavigationContext.QueryString["genre"];
            }

            using (var library = new MediaLibrary())
            {
                var songResults = from song in library.Songs
                                  where (song.Genre.ToString().ToLower().IndexOf(genre) == -1)
                                  select song;


                var playlists = library.Playlists;
                var playlist  = library.
                                var songResults = library.Songs.Where(s => s.Genre.ToString().ToLower().IndexOf(genre) > -1);
                foreach (var song in songResults)
                {
                    songList.Add(song);
                }

                songCollection = library.Songs;
            }

            frameworkDispatchTimer.Start();
            FrameworkDispatcher.Update();
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Initializes new instance of WitMic
        /// </summary>
        /// <param name="witPipedStream">Stream to write audio to</param>
        /// <param name="detectSpeechStop">Voice activity detection feature</param>
        public WitMic(WitPipedStream witPipedStream, bool detectSpeechStop)
        {
            this.witPipedStream   = witPipedStream;
            this.detectSpeechStop = detectSpeechStop;

            microphone = Microphone.Default;

            if (microphone == null)
            {
                WitLog.Log("Did you enabled ID_CAP_MICROPHONE in WMAppManifest.xml?");

                return;
            }

            witDetectTalking = new WitVadWrapper(8.0, 16000, 60);

            microphone.BufferDuration = TimeSpan.FromMilliseconds(100);

            speech = new byte[microphone.GetSampleSizeInBytes(microphone.BufferDuration)];

            microphone.BufferReady += microphone_BufferReady;

            updateTimer = new DispatcherTimer()
            {
                Interval = TimeSpan.FromMilliseconds(1)
            };
            updateTimer.Tick += (s, e) =>
            {
                FrameworkDispatcher.Update();
            };
        }
Ejemplo n.º 14
0
        private void KeyboardControl_IsTitleFoundChanged(object sender, SimpleMvvmToolkit.NotificationEventArgs e)
        {
            Debug.WriteLine("Keyboard event : IsTitleFoundChanged");
            KeyboardControl keyboardControl = sender as KeyboardControl;

            if (keyboardControl == null || this.CurrentViewModel == null || this.CurrentViewModel.SelectedMedia == null)
            {
                return;
            }

            if (keyboardControl.IsFound)
            {
                this.CurrentViewModel.CurrentMediaTitleFound();


                if (AppSettings.Instance.SoundOnOffSetting)
                {
                    // Load the SoundEffect
                    var         info   = App.GetResourceStream(new Uri("Resources/Sounds/success.wav", UriKind.Relative));
                    SoundEffect effect = SoundEffect.FromStream(info.Stream);
                    // Tell the XNA Libraries to continue to run
                    FrameworkDispatcher.Update();
                    // Play the Sound
                    effect.Play();
                }
            }

            //this.CurrentViewModel.SelectedMedia.IsCompleted = keyboardControl.IsFound;
            //this.CurrentViewModel.ProposerTitre();
        }
Ejemplo n.º 15
0
        private void InitializeGFX(IGraphicsDeviceService graphics)
        {
            services = new GameServiceContainer();
            services.AddService <IGraphicsDeviceService>(graphics);
            this.graphics = graphics.GraphicsDevice;

            Content     = new ContentManager(services, "Content");
            spriteBatch = new SpriteBatch(graphics.GraphicsDevice);

            Pixel = new Texture2D(graphics.GraphicsDevice, 1, 1);
            Pixel.SetData(new[] { Color.White });

            Format = new System.Globalization.NumberFormatInfo();
            Format.CurrencyDecimalSeparator = ".";

            Cam             = new Camera2D();
            Cam.GetPosition = new Vector2(
                graphics.GraphicsDevice.Viewport.Width / 2, graphics.GraphicsDevice.Viewport.Height / 2);
#if DX
            InternContent = new ResourceContentManager(services, DX.Properties.Resources.ResourceManager);

            GetRenderTargetManager  = new RenderTargetManager(this);
            AntialisingRenderTarget = GetRenderTargetManager.CreateNewRenderTarget2D("MSAA", true);

            RenderTargetTimer          = new Timer();
            RenderTargetTimer.Interval = 500;
            RenderTargetTimer.Elapsed += (sender, e) => OnRenderTargetTimeOutEnd();
#elif GL
            InternContent = new ResourceContentManager(services, GL.Properties.Resources.ResourceManager);
#endif
            Font       = InternContent.Load <SpriteFont>("Font");
            FontHeight = Font.MeasureString("A").Y;

            FrameworkDispatcher.Update();
        }
Ejemplo n.º 16
0
 public XNAAsyncDispatcher(TimeSpan dispatchInterval)
 {
     FrameworkDispatcher.Update();
     this._frameworkDispatcherTimer          = new DispatcherTimer();
     this._frameworkDispatcherTimer.Tick    += new EventHandler(frameworkDispatcherTimer_Tick);
     this._frameworkDispatcherTimer.Interval = dispatchInterval;
 }
Ejemplo n.º 17
0
 public XnaFrameworkDispatcherService()
 {
     timer          = new DispatcherTimer();
     timer.Interval = TimeSpan.FromTicks(333333);
     timer.Tick    += OnTimerTick;
     FrameworkDispatcher.Update();
 }
Ejemplo n.º 18
0
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            DispatcherTimer timer = new DispatcherTimer();

            // Run it a little faster than our buffer updates
            timer.Interval = TimeSpan.FromMilliseconds(80);
            timer.Tick    += OnTimerTick;
            timer.Start();
            FrameworkDispatcher.Update();

            // Add in the event handler for when a new buffer of audio is available
            audioIn.BufferReady += new EventHandler <EventArgs>(Microphone_BufferReady);

            // XNA is limited to 100ms latency. :(
            audioIn.BufferDuration = TimeSpan.FromMilliseconds(100);

            // Create a buffer of the appropriate length
            int bufferLen = audioIn.GetSampleSizeInBytes(audioIn.BufferDuration);

            audioBuffer = new byte[bufferLen];

            // Create our audio out interface with the same samplerate and channels of the audio input
            // We couldn't create this above because we needed to get audioIn.SampleRate
            audioOut = new DynamicSoundEffectInstance(audioIn.SampleRate, AudioChannels.Mono);

            // Start recording and playing
            audioIn.Start();
            audioOut.Play();
        }
Ejemplo n.º 19
0
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            /**********
             * // Timer to simulate the XNA game loop (SoundEffect class is from the XNA Framework)
             * GameTimer gameTimer = new GameTimer();
             * gameTimer.UpdateInterval = TimeSpan.FromMilliseconds(33);
             *
             * // Call FrameworkDispatcher.Update to update the XNA Framework internals.
             * gameTimer.Update += delegate { try { FrameworkDispatcher.Update(); } catch { } };
             *
             * // Start the GameTimer running.
             * gameTimer.Start();
             *
             ***********/


            // Prime the pump or we'll get an exception.
            FrameworkDispatcher.Update();  //We have Update FrameworkDispatcher to play sound using SoundEffect

            LoadSoundFile("sounds/logon.wav", out soundLogon);
            LoadSoundFile("sounds/on.wav", out soundOn);
            LoadSoundFile("sounds/off.wav", out soundOff);

            soundLogon.Play();

            mediaEle.Source      = new Uri("sounds/Sleep Away.mp3", UriKind.Relative);
            mediaEle.Volume      = 1f;
            mediaEle.MediaEnded += new RoutedEventHandler(mediaEle_MediaEnded);

            mediaEle.Visibility = Visibility.Collapsed;
        }
Ejemplo n.º 20
0
        public SoundManager()
        {
            LoadSound("Sounds/started.wav", out startedSound);
            LoadSound("Sounds/lightbox.activated.wav", out lightboxActivatedSound);
            LoadSound("Sounds/guess.added.wav", out guessAddedSound);
            LoadSound("Sounds/guess.removed.wav", out guessRemovedSound);
            LoadSound("Sounds/guess.transferred.wav", out guessTransferredSound);
            LoadSound("Sounds/guess.wrong.placed.wav", out guessWrongPlacedSound);
            LoadSound("Sounds/guess.success.wav", out guessSuccessSound);
            LoadSound("Sounds/guess.failed.wav", out guessFailedSound);
            LoadSound("Sounds/won.wav", out wonSound);
            LoadSound("Sounds/debunk.wav", out debunkSound);
            LoadSound("Sounds/restarted.wav", out restartedSound);
            LoadSound("Sounds/appbar.clicked.wav", out appbarClickedSound);
            LoadSound("Sounds/about.shown.wav", out aboutShownSound);
            LoadSound("Sounds/game.over.wav", out gameOverSound);
            LoadSoundInstance("Sounds/background.music.wav", out backgroundMusic, out backgroundMusicInstance);

            // Set the volume a little lower than full so it becomes the background.
            backgroundMusicInstance.Volume = 0.7f;

            // Turn on looping so it runs continually in the background.
            backgroundMusicInstance.IsLooped = true;

            // Timer to simulate the XNA game loop (SoundEffect classes are from the XNA Framework)
            DispatcherTimer XnaDispatchTimer = new DispatcherTimer();

            XnaDispatchTimer.Interval = TimeSpan.FromMilliseconds(50);

            // Call FrameworkDispatcher.Update to update the XNA Framework internals.
            XnaDispatchTimer.Tick += delegate { try { FrameworkDispatcher.Update(); } catch { } };

            // Start the DispatchTimer running.
            XnaDispatchTimer.Start();
        }
Ejemplo n.º 21
0
        //setting states and updating the Dispatcher while recording the sound.
        void settingState(object sender, EventArgs e)
        {
            try
            {
                try { FrameworkDispatcher.Update(); }
                catch (Exception ee)
                {
                    MessageBox.Show(ee.Message);
                }
                if (soundIsPlaying == true)
                {
                    if (soundInstance.State != SoundState.Playing)
                    {
                        soundIsPlaying = false;

                        UserHelp1.Text = "press play";
                        SetButtonStates(true, true, false, true);
                    }
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }
Ejemplo n.º 22
0
        public static void ChangeButton(Button play, Button pause)
        {
            try
            {
                FrameworkDispatcher.Update();
                switch (MediaPlayer.State)
                {
                case MediaState.Playing:
                    play.Visibility  = Visibility.Collapsed;
                    pause.Visibility = Visibility.Visible;
                    break;

                case MediaState.Paused:
                    play.Visibility  = Visibility.Visible;
                    pause.Visibility = Visibility.Collapsed;
                    break;

                case MediaState.Stopped:
                    play.Visibility  = Visibility.Visible;
                    pause.Visibility = Visibility.Collapsed;
                    break;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(":(" + ex.Message);
            }
        }
Ejemplo n.º 23
0
        public static void PlaySound(string uri)
        {
            Stream      stream = TitleContainer.OpenStream(uri);
            SoundEffect effect = SoundEffect.FromStream(stream);

            FrameworkDispatcher.Update();
            effect.Play();
        }
Ejemplo n.º 24
0
        private void pop_sound()
        {
            Stream      stream = TitleContainer.OpenStream("Sounds/Blop.wav");
            SoundEffect effect = SoundEffect.FromStream(stream);

            FrameworkDispatcher.Update();
            effect.Play();
        }
Ejemplo n.º 25
0
        public static void StartAudioPlayback(string AudioFilePath)
        {
            Stream      stream = TitleContainer.OpenStream(AudioFilePath);
            SoundEffect effect = SoundEffect.FromStream(stream);

            FrameworkDispatcher.Update();
            effect.Play();
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Uses the XNA framework to play a given sound effect
        /// </summary>
        /// <param name="path"> the relative path of the sound being played </param>
        private void PlaySound(string path)
        {
            var stream = TitleContainer.OpenStream(path);
            var effect = SoundEffect.FromStream(stream);

            FrameworkDispatcher.Update();
            effect.Play();
        }
Ejemplo n.º 27
0
 public void Setup()
 {
     // Necessary to get audio initialised
     FrameworkDispatcher.Update();
     _audioEngine = new AudioEngine(@"Assets\Audio\Win\Tests.xgs");
     _waveBank    = new WaveBank(_audioEngine, @"Assets\Audio\Win\Tests.xwb");
     _soundBank   = new SoundBank(_audioEngine, @"Assets\Audio\Win\Tests.xsb");
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Special initialization required for the microphone: XNA game loop
 /// </summary>
 private void InitializeXnaGameLoop()
 {
     // Timer to simulate the XNA game loop (Microphone is from XNA)
     this.dtXna          = new DispatcherTimer();
     this.dtXna.Interval = TimeSpan.FromMilliseconds(33);
     this.dtXna.Tick    += delegate { try { FrameworkDispatcher.Update(); } catch { } };
     this.dtXna.Start();
 }
Ejemplo n.º 29
0
 public XNAFrameworkDispatcherUpdater()
 {
     timer = new DispatcherTimer {
         Interval = TimeSpan.FromMilliseconds(100)
     };
     timer.Tick += OnTick;
     FrameworkDispatcher.Update();
 }
Ejemplo n.º 30
0
 private void timer_Tick(object sender, EventArgs e)
 {
     FrameworkDispatcher.Update();
     Pitch = micRecorder.Pitch;
     Note  = micRecorder.Note;
     // Binding does not work with slider, fix:
     //PitchSlider.Value = micRecorder.Pitch;
 }