示例#1
0
        public void Support_Balance()
        {
#if NCRUNCH
            Assert.Inconclusive("skip for NCrunch");
#endif

            var ctx = new CreationContext {
                VolumeEndpoint = CoreAudio.GetDefaultVolumeEndpoint()
            };

            var sut = ctx.Create();

            var       duration = TimeSpan.FromSeconds(3);
            const int n        = 50;

            var dt = (int)(duration.TotalMilliseconds / n);
            for (var i = 1; i <= n; i++)
            {
                var balance = Math.Sin(2 * i * Math.PI / n);
                sut.Balance = balance;

                Thread.Sleep(dt);

                sut.Balance.Should().BeApproximately(balance, VlcMediaPlayer.BalanceEps);
            }
        }
示例#2
0
        public void Allow_play_if_at_the_end()
        {
            var ctx = new CreationContext();

            ctx.Player.Length.Returns(100);
            var sut = ctx.Create();

            sut.Position = 10;
            sut.Duration = 100;

            File.Exists(sut.Source.LocalPath).Should().BeTrue();
            sut.HasAudio.Should().BeTrue();

            sut.PlayWithTask().Wait();
            ctx.Player.Events.PlayerPositionChanged += Raise.EventWith(new object(), new MediaPlayerPositionChanged(1));
            sut.Pause();

            sut.CanPlay.Should().BeTrue("user can hit play again");
            sut.CanPause.Should().BeFalse();
            sut.CanStop.Should().BeTrue("we are NOT at the starting point");

            sut.IsPlaying.Should().BeFalse();
            sut.IsPaused.Should().BeTrue("<-- this is where we are");
            sut.IsStopped.Should().BeFalse();
        }
示例#3
0
        private static VlcMediaPlayer CreateSut()
        {
            var ctx = new CreationContext();
            var sut = ctx.Create();

            return(sut);
        }
示例#4
0
        public void Transform_Vlc_Length_From_Milliseconds_to_Seconds()
        {
            var ctx = new CreationContext();
            var sut = ctx.Create();

            using (var monitor = sut.Monitor())
            {
                ctx.Player.Events.PlayerLengthChanged += Raise.EventWith(new MediaPlayerLengthChanged(15000));

                sut.Duration.Should().Be(15);
                monitor.Should().RaisePropertyChangeFor(player => player.Duration);
            }
        }
示例#5
0
        public void Change_Relative_Position_If_Duration_Changed_If_Not_Playing()
        {
            var ctx = new CreationContext();
            var sut = ctx.Create();

            sut.Duration = 100;
            sut.Position = 50;

            ctx.Player.Events.PlayerLengthChanged += Raise.EventWith(new MediaPlayerLengthChanged(200000));

            sut.Duration.Should().Be(200);
            //sut.Position.Should().Be(25);
        }
示例#6
0
        public void Handle_Vlc_Error_With_Audio_Excpetion()
        {
            var ctx = new CreationContext();
            var sut = ctx.Create();

            sut.Error.Should().Be(AudioError.NoError);
            sut.Error.HasException.Should().BeFalse();

            ctx.Player.Events.PlayerEncounteredError += Raise.EventWith(new MediaPlayerLengthChanged(15000));

            sut.Error.Should().NotBeNull();
            sut.Error.HasException.Should().BeTrue();
            sut.Error.Should().BeOfType <AudioError>();
            sut.Error.Exception.Should().BeOfType <AudioException>();
        }
示例#7
0
        public void Wrap_media_exceptions_into_AudioException()
        {
            var ctx = new CreationContext();
            var sut = ctx.Create();

            sut.Error.HasException.Should().BeFalse();

            sut.Source = new Uri(new FileInfo(@"c:\does.not.exist.wav").FullName);

            sut.Error.HasException.Should().BeTrue();
            sut.Error.Exception.Should().BeAssignableTo <AudioException>();
            sut.Error.Exception.Message.Should().StartWith("Could not open audio");

            sut.Source = null;
            sut.Error.HasException.Should().BeFalse();
        }
示例#8
0
        public void Initialize_source_with_proper_state()
        {
            var ctx = new CreationContext();
            var sut = ctx.Create();

            sut.Position = 0;
            sut.Duration = 100;

            File.Exists(sut.Source.LocalPath).Should().BeTrue();
            sut.HasAudio.Should().BeTrue();

            sut.CanPlay.Should().BeTrue("we did nothing so far, so the user can hit play");
            sut.CanPause.Should().BeFalse();
            sut.CanStop.Should().BeFalse("because we ARE at the starting point");

            sut.IsPlaying.Should().BeFalse();
            sut.IsPaused.Should().BeFalse();
            sut.IsStopped.Should().BeTrue("<-- this is where we are");
        }
示例#9
0
        public void Raise_PropertyChanged_If_Played()
        {
            var ctx = new CreationContext();
            var sut = ctx.Create();

            sut.Position = 0;
            sut.Duration = 100;

            using (var monitor = sut.Monitor())
            {
                ctx.Player.Events.PlayerPlaying += Raise.Event();

                monitor.Should().RaisePropertyChangeFor(x => x.IsPaused);
                monitor.Should().RaisePropertyChangeFor(x => x.IsStopped);
                monitor.Should().RaisePropertyChangeFor(x => x.CanPause);
                monitor.Should().RaisePropertyChangeFor(x => x.CanStop);
                monitor.Should().RaisePropertyChangeFor(x => x.CanPause);
            }
        }
示例#10
0
        public void Not_invoke_play_if_at_the_end()
        {
            var ctx = new CreationContext();

            ctx.Player.Length.Returns(100000);
            var sut = ctx.Create();

            sut.Position = 10;
            sut.Duration = 100;

            File.Exists(sut.Source.LocalPath).Should().BeTrue();
            sut.HasAudio.Should().BeTrue();

            sut.PlayWithTask().Wait();
            ctx.Player.Events.PlayerPositionChanged += Raise.EventWith(new object(), new MediaPlayerPositionChanged(100));
            sut.Pause();

            ctx.Player.ClearReceivedCalls();
            sut.PlayWithTask().Wait();
            ctx.Player.Received().Play();
        }
示例#11
0
        public void Have_proper_state_after_hitting_play()
        {
            var ctx = new CreationContext();
            var sut = ctx.Create();

            sut.Position = 10;
            sut.Duration = 100;

            sut.PlayWithTask().Wait();

            File.Exists(sut.Source.LocalPath).Should().BeTrue();
            sut.HasAudio.Should().BeTrue();

            sut.CanPlay.Should().BeFalse();
            sut.CanPause.Should().BeTrue();
            sut.CanStop.Should().BeTrue();

            sut.IsPlaying.Should().BeTrue("<-- this is where we are");
            sut.IsPaused.Should().BeFalse();
            sut.IsStopped.Should().BeFalse();
        }
示例#12
0
        public void Automatically_pause_if_at_the_end()
        {
            var ctx = new CreationContext();
            var sut = ctx.Create();

            sut.Position = 10;
            sut.Duration = 100;

            File.Exists(sut.Source.LocalPath).Should().BeTrue();
            sut.HasAudio.Should().BeTrue();

            sut.PlayWithTask().Wait();
            ctx.Player.Events.MediaEnded += Raise.EventWith(new object(), EventArgs.Empty);

            sut.CanPlay.Should().BeTrue();
            sut.CanStop.Should().BeTrue();
            sut.CanPause.Should().BeFalse();

            sut.IsPaused.Should().BeTrue();
            sut.IsPlaying.Should().BeFalse();
            sut.IsStopped.Should().BeFalse();
        }
示例#13
0
        public void Notify_Mute_on_Volume_changed()
        {
            var ctx = new CreationContext();
            var sut = ctx.Create();

            sut.Volume = 0.5;

            var map = new Dictionary <string, int>();

            sut.PropertyChanged += (s, e) =>
            {
                if (map.ContainsKey(e.PropertyName))
                {
                    map[e.PropertyName]++;
                }
                else
                {
                    map[e.PropertyName] = 1;
                }
            };

            var volume = sut.Volume;

            sut.Volume.Should().NotBe(0);
            sut.IsMuted.Should().BeFalse();
            sut.CanMute.Should().BeTrue();

            sut.Volume = 0;
            sut.IsMuted.Should().BeTrue();
            sut.CanMute.Should().BeFalse();

            sut.Volume = volume;

            map["CanMute"].Should().Be(2);
            map["CanUnMute"].Should().Be(2);
            map["IsMuted"].Should().Be(2);
        }
示例#14
0
        public void Initialize_volume_on_setting_source()
        {
            var ctx = new CreationContext();
            var sut = ctx.Create();

            ctx.Player.Volume.Returns(-1);

            sut.Source = null;

            using (var monitor = sut.Monitor())
            {
                sut.Source = DefaultSource;

                monitor.Should().RaisePropertyChangeFor(p => p.Volume);
                monitor.Should().RaisePropertyChangeFor(p => p.CanMute);
                monitor.Should().RaisePropertyChangeFor(p => p.CanUnMute);

                monitor.Should().RaisePropertyChangeFor(p => p.CanFaster);
                monitor.Should().RaisePropertyChangeFor(p => p.CanSlower);
                monitor.Should().RaisePropertyChangeFor(p => p.CanPlay);
                monitor.Should().RaisePropertyChangeFor(p => p.CanPause);
                monitor.Should().RaisePropertyChangeFor(p => p.CanStop);
            }

            sut.Volume.Should().Be(VlcMediaPlayer.DefaultVolume);
            VlcMediaPlayer.DefaultVolume.Should().Be(1.0, "this seems to be VLCs default");

            VlcMediaPlayer.VolumeEps.Should().BeLessOrEqualTo(0.1, "At minimum support 10% volume changes");

            using (var monitor = sut.Monitor())
            {
                sut.Volume = 0.5;
                monitor.Should().RaisePropertyChangeFor(p => p.Volume);
                sut.Volume.Should().Be(0.5);
            }

            using (var monitor = sut.Monitor())
            {
                // check that updating player state/volume notifies the UI
                ctx.Player.Volume.Returns(10);
                sut.PlayWithTask().Wait();
                monitor.Should().RaisePropertyChangeFor(p => p.Volume);
                sut.Volume.Should().Be(0.5);

                sut.Volume = 0.2;
                sut.Volume.Should().Be(0.2);
            }

            using (var monitor = sut.Monitor())
            {
                // check that any play/pause changes notify on Volume
                sut.Pause();
                monitor.Should().RaisePropertyChangeFor(p => p.Volume);
            }

            using (var monitor = sut.Monitor())
            {
                sut.Stop();
                monitor.Should().RaisePropertyChangeFor(p => p.Volume);
            }
        }