示例#1
0
        /// <summary>
        /// Create an audio track source using a local audio capture device (microphone).
        /// </summary>
        /// <param name="initConfig">Optional configuration to initialize the audio capture on the device.</param>
        /// <returns>The newly create audio track source.</returns>
        /// <seealso cref="LocalAudioTrack.CreateFromSource(AudioTrackSource, LocalAudioTrackInitConfig)"/>
        public static Task <DeviceAudioTrackSource> CreateAsync(LocalAudioDeviceInitConfig initConfig = null)
        {
            return(Task.Run(() =>
            {
                // On UWP this cannot be called from the main UI thread, so always call it from
                // a background worker thread.

                var config = new DeviceAudioTrackSourceInterop.LocalAudioDeviceMarshalInitConfig(initConfig);
                uint ret = DeviceAudioTrackSourceInterop.DeviceAudioTrackSource_Create(in config, out DeviceAudioTrackSourceHandle handle);
                Utils.ThrowOnErrorCode(ret);
                return new DeviceAudioTrackSource(handle);
            }));
        }
示例#2
0
        /// <summary>
        /// Create an audio track source using a local audio capture device (microphone).
        /// </summary>
        /// <param name="initConfig">Optional configuration to initialize the audio capture on the device.</param>
        /// <returns>The newly create audio track source.</returns>
        /// <seealso cref="LocalAudioTrack.CreateFromSource(AudioTrackSource, LocalAudioTrackInitConfig)"/>
        public static Task <DeviceAudioTrackSource> CreateAsync(LocalAudioDeviceInitConfig initConfig = null)
        {
            // Ensure the logging system is ready before using PInvoke.
            MainEventSource.Log.Initialize();

            return(Task.Run(() =>
            {
                // On UWP this cannot be called from the main UI thread, so always call it from
                // a background worker thread.

                var config = new DeviceAudioTrackSourceInterop.LocalAudioDeviceMarshalInitConfig(initConfig);
                uint ret = DeviceAudioTrackSourceInterop.DeviceAudioTrackSource_Create(in config, out DeviceAudioTrackSourceHandle handle);
                Utils.ThrowOnErrorCode(ret);
                return new DeviceAudioTrackSource(handle);
            }));
        }