コード例 #1
0
        public void RemoveOutgoingConnection(IOutputAudioDevice audioDevice)
        {
            var playbackDevice = audioDevice.AsPlayback();

            var splitterChannel = OutputChannels.Single(c => c.Device == playbackDevice);

            OutputChannels.Remove(splitterChannel);

            foreach (var outputChannel in OutputChannels)
            {
                ManagedBass.Bass.ChannelRemoveLink(splitterChannel.Handle, outputChannel.Handle);
                ManagedBass.Bass.ChannelRemoveLink(outputChannel.Handle, splitterChannel.Handle);
            }

            OutgoingConnections.Remove(audioDevice);

            splitterChannel.Dispose();
        }
コード例 #2
0
        public void AddOutgoingConnection(IOutputAudioDevice audioDevice)
        {
            var playbackDevice = audioDevice.AsPlayback();

            playbackDevice.Init();

            var splitterChannel = new SplitChannel(SourceChannel)
            {
                Device = playbackDevice,
                Volume = Volume
            };

            if (splitterChannel.Device != playbackDevice)
            {
                splitterChannel.Dispose();

                throw new InvalidOperationException($"Cannot set outgoing connection for device {audioDevice}");
            }

            foreach (var outputChannel in OutputChannels)
            {
                outputChannel.Link(splitterChannel.Handle);
                splitterChannel.Link(outputChannel.Handle);
            }

            OutputChannels.Add(splitterChannel);

            OutgoingConnections.Add(audioDevice);

            if (IsPlaying)
            {
                foreach (var outputChannel in OutputChannels)
                {
                    Logger.Debug("AddOutgoingConnection: Before pause for outputChannel device {device} position = {position}", outputChannel.Device, outputChannel.Position);

                    outputChannel.Pause();

                    Logger.Debug("AddOutgoingConnection: After pause for outputChannel device {device} position = {position}", outputChannel.Device, outputChannel.Position);
                }

                var position = OutputChannels.Min(c => c.Position);

                Logger.Debug("AddOutgoingConnection: MinPosition = {position}", position);

                foreach (var outputChannel in OutputChannels)
                {
                    Logger.Debug("AddOutgoingConnection: Before updating position for outputChannel device {device} position = {position}", outputChannel.Device, outputChannel.Position);

                    // Set position few times, because sometimes once isn't working
                    var i = 5;
                    while (i-- > 0)
                    {
                        outputChannel.Position = position;
                    }

                    Logger.Debug("AddOutgoingConnection: After updating position for outputChannel device {device} position = {position}", outputChannel.Device, outputChannel.Position);
                }

                Play();
            }
        }