예제 #1
0
        private async Task <SoundShuffler> GetSoundShufflerAsync()
        {
            var soundShuffler = new SoundShuffler();

            // Add music files
            await Task.Run(() =>
            {
                var directoryPath = ResourcesPath + "\\Music\\";
                // var directoryPath = Environment.CurrentDirectory + "/Resources/Music/";
                string[] filePaths = Directory.GetFiles(@directoryPath, "*.wav", SearchOption.TopDirectoryOnly);
                foreach (string filePath in filePaths)
                {
                    soundShuffler.AddSound(filePath);
                }
            });

            return(soundShuffler);
        }
예제 #2
0
        private async Task InitPlaybackEventActionsAsync(SoundShuffler soundShuffler, CancellationToken cancellationToken)
        {
            // When initialized asynchronously, the current thread may be a background thread at this point.
            // Do any initialization that requires the UI thread after switching to the UI thread.
            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            // Play elevator music when the build starts and stop the playback when the build is finished
            var dte = await GetServiceAsync(typeof(DTE)) as DTE;

            Assumes.Present(dte);
            dte.Events.BuildEvents.OnBuildBegin += (vsBuildScope Scope, vsBuildAction Action) => soundShuffler.ShufflePlayAsync(true).ConfigureAwait(true);
            dte.Events.BuildEvents.OnBuildDone  += (vsBuildScope Scope, vsBuildAction Action) =>
            {
                // Stop the music
                soundShuffler.StopPlayback();

                // Play elevator bell sound
                new SoundPlayer(ResourcesPath + "\\Audio\\Elevator Bell.wav").Play();
            };
        }