public async Task PlayerSource_MediaPlayer() { var testFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///TestContent/test_signal.mp3")); var player = new MediaPlayer(); var playerSource = new AudioVisualizer.PlaybackSource(player); List <IVisualizationSource> sources = new List <IVisualizationSource>(); ManualResetEventSlim ev = new ManualResetEventSlim(); playerSource.SourceChanged += new TypedEventHandler <object, IVisualizationSource>( (sender, source) => { sources.Add(source); ev.Set(); } ); player.Source = MediaSource.CreateFromStorageFile(testFile); player.Play(); if (Task.Run(() => { ev.Wait(); }).Wait(1000)) { Assert.IsTrue(sources.Count == 1); Assert.IsNotNull(sources[0]); Assert.IsInstanceOfType(sources[0], typeof(AudioVisualizer.MediaAnalyzer)); } else { Assert.Fail("Timeout when waiting for the source creation"); } }
public PlayerService() { _player = new MediaPlayer(); _source = new PlaybackSource(_player); _source.SourceChanged += _source_SourceChanged; _player.MediaOpened += Player_MediaOpened; _player.PlaybackSession.PositionChanged += PlaybackSession_PositionChanged; }