Пример #1
0
        public void VolumeFieldIsUpdated()
        {
            Context c = new Context();

            c.ConnectAndWait();

            helper.SpawnAplaySinkInput();

            SinkInput aplay = null;

            using (Operation opn = c.EnumerateSinkInputs((SinkInput input, int eol) => {
                if (eol == 0)
                {
                    if (input.Properties[Properties.ApplicationProcessBinary] == "aplay")
                    {
                        aplay = input;
                    }
                }
            })) {
                opn.Wait();
            }

            Volume vol = aplay.Volume;

            vol.Modify(0.1);
            Assert.AreNotEqual(vol, aplay.Volume);
            using (Operation opn = aplay.SetVolume(vol, (_) => {; })) {
                opn.Wait();
            }

            Helper.DrainEventLoop();
            // Wait for volume change events to percolate
            Thread.Sleep(200);
            Helper.DrainEventLoop();
            Thread.Sleep(10);
            Helper.DrainEventLoop();

            try {
                Assert.AreEqual(vol, aplay.Volume);
            } finally {
                //Reset the volume to 100%
                vol.Reset();
                using (Operation opn = aplay.SetVolume(vol, (_) => {; })) {
                    opn.Wait();
                }
            }
        }
Пример #2
0
        public void VolumeChangedEventFires()
        {
            Context c = new Context();

            c.ConnectAndWait();

            helper.SpawnAplaySinkInput();

            SinkInput aplay = null;

            using (Operation opn = c.EnumerateSinkInputs((SinkInput input, int eol) => {
                if (eol == 0)
                {
                    if (input.Properties[Properties.ApplicationProcessBinary] == "aplay")
                    {
                        aplay = input;
                    }
                }
            })) {
                opn.Wait();
            }
            Assert.IsNotNull(aplay, "Testing error: aplay SinkInput not found");

            var volumeChangedEventTriggered = new ManualResetEvent(false);

            aplay.VolumeChanged += delegate(object sender, SinkInput.VolumeChangedEventArgs e) {
                volumeChangedEventTriggered.Set();
            };
            // Ensure the volume changed callback is hooked up.
            Helper.DrainEventLoop();

            Volume vol = aplay.Volume;

            vol.Modify(0.1);

            using (Operation o = aplay.SetVolume(vol, (_) => {; })) {
                o.Wait();
            }

            Helper.RunUntilEventSignal(() => {; }, volumeChangedEventTriggered, "Timeout waiting for VolumeChanged signal");
        }