示例#1
0
        private void StartRadioPlayerNew()
        {
            if (waveOut != null)
            {
                waveOut.Stop();
            }

            tokenSource.Cancel();
            tokenSource.Dispose();
            Console.WriteLine("AudioThread.Wait(); start");

            AudioThread.Wait();



            Console.WriteLine("AudioThread.Wait(); end");

            AudioThread.Dispose();

            bufferedWaveProvider = null;
            waveOut = null;

            tokenSource = new CancellationTokenSource();
            AudioThread = new Task(() =>
            {
                StreamMp3(tokenSource.Token);
            }, tokenSource.Token);

            AudioThread.Start();
        }
示例#2
0
        public void TestThreads()
        {
            var a         = new AudioThread();
            var latency   = 10;
            var cpuUsage  = 1.0f;
            var underRuns = 1;

            var output = a.Update(TestHelper.Silence(1), out latency, out cpuUsage, out underRuns, false);

            float[] buf = new float[256];
            Thread.Sleep(200);
            Assert.IsNotNull(output);
            Assert.IsTrue(a.PlayBuffer.BufferedSamples > 0);
            output.Read(buf, 0, buf.Length);
            Assert.AreEqual(TestHelper.GenerateBuffer(new[] { 1.0f }, 256), buf);

            output = a.Update(null, out latency, out cpuUsage, out underRuns, false);
            Thread.Sleep(200);
            Assert.IsNotNull(output);
            Assert.IsTrue(a.PlayBuffer.BufferedSamples == 0);
            output.Read(buf, 0, buf.Length);
            Assert.AreEqual(TestHelper.GenerateBuffer(new[] { 0.0f }, 256), buf);

            var input = TestHelper.Silence(2);

            output = a.Update(input, out latency, out cpuUsage, out underRuns, true);
            Thread.Sleep(200);
            Assert.IsNull(output);
            Assert.IsTrue(a.PlayBuffer.BufferedSamples > 0);
            Assert.IsTrue(((LevelProcessor)input.Processor).ReadPos > 0);

            Thread.Sleep(200);
            a.Dispose();
        }
示例#3
0
 protected override void Dispose(bool Managed)
 {
     if (!Managed)
     {
         return;
     }
     VideoThread?.Dispose();
     AudioThread?.Dispose();
     base.Dispose(Managed);
 }