Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media;
- public sealed class App : Application {
- public App () {
- this.Startup += this.Application_Startup;
- }
- TextBox log;
- private void Application_Startup (object sender, StartupEventArgs e) {
- StackPanel spMain = new StackPanel();
- Button btnStart = new Button() {
- Content = "Start"
- };
- btnStart.Click += new RoutedEventHandler((object s, RoutedEventArgs ev) => {
- if (CaptureDeviceConfiguration.AllowedDeviceAccess || CaptureDeviceConfiguration.RequestDeviceAccess()) {
- CaptureSource captureSource = new CaptureSource() {
- VideoCaptureDevice = null,
- AudioCaptureDevice = CaptureDeviceConfiguration.GetDefaultAudioCaptureDevice()
- };
- captureSource.CaptureFailed += new EventHandler<ExceptionRoutedEventArgs>((object se, ExceptionRoutedEventArgs eve) => {
- log.Dispatcher.BeginInvoke(new Action(() => {
- log.Text += "CaptureFailed\n";
- }));
- });
- SampleAudioSink audioSink = new SampleAudioSink(log) {
- CaptureSource = captureSource
- };
- captureSource.Start();
- }
- });
- spMain.Children.Add(btnStart);
- log = new TextBox() {
- AcceptsReturn = true,
- Height = 600,
- IsReadOnly = true,
- VerticalScrollBarVisibility = ScrollBarVisibility.Auto
- };
- spMain.Children.Add(log);
- this.RootVisual = spMain;
- }
- }
- internal sealed class SampleAudioSink : AudioSink {
- TextBox log;
- int i = 0;
- internal SampleAudioSink (TextBox log) {
- this.log = log;
- }
- protected override void OnCaptureStarted () {
- log.Dispatcher.BeginInvoke(new Action(() => {
- log.Text += "OnCaptureStarted\n";
- }));
- }
- protected override void OnCaptureStopped () {
- log.Dispatcher.BeginInvoke(new Action(() => {
- log.Text += "OnCaptureStopped\n";
- }));
- }
- protected override void OnFormatChange (AudioFormat audioFormat) {
- log.Dispatcher.BeginInvoke(new Action(() => {
- log.Text += "OnFormatChange\n";
- }));
- }
- protected override void OnSamples (long sampleTimeInHundredNanoseconds, long sampleDurationInHundredNanoseconds, byte[] sampleData) {
- log.Dispatcher.BeginInvoke(new Action(() => {
- log.Text += string.Format("OnSamples ({0})\n", ++i);
- }));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement