Assure an audio device is connected - c#

I have some Bluetooth audio devices paired to my system. These can sometimes be disconnected. If I go into the Sound control panel, look for the device in the Playback devices list, and right click&select "connect", then everything works again.
How do I do that programmatically in C#?
I've tried 32feet and NAudio already, but the State property of their BluetoothDevice and MMDevice classes is read-only.
In a perfect world, I would find a function like this:
BluetoothConnector.Connect("MyBluetoothDevice");

Related

Monitor USB for camera connection

I have a USB microscope camera and I would like to open the Windows 10 camera app automatically if the camera gets connected to a USB port. After checking that this isn't possible with Windows 10 at the settings level, I have decided to write a short C# program that monitors the USB ports for a camera device connection (and runs the camera display app).
As to the monitoring I haven't got a slightest clue where to begin. Needless to say that the monitoring program should be lean with respect to blocking ressources, because it would be running all the time. Can I simply obtain an event notification of USB connection? Do I have to expect problems with permissions?
And of course, suggestions for alternative approaches are welcome, if any. Note that I do not want to capture and display video from the camera myself, unless it is easier to do it that way instead of opening the existing camera app.
assuming the microscope is using the web-camera interface I would look for guides about how to enumerate and connect to web-cameras. I have found a few alternatives:
Media capture API
Aforge
Versatile WebCam
I had most success with versatile webcam, but if you just want to enumerate devices any of them should do. Aforge is probably the easiest to use.
You can then use a timer to check for devices, and do something if the microscope is connected.
If the microscope is not a webcamera you will need to refer to the camera documentation on how to enumerate devices.

Test for audio with no speakers

I am currently debugging some code in C# which plays a noise (in this case a beep) under certain conditions.
The computer I am using has no speakers or working headphone jack, is there any way in which I can detect sound being played without actually being able to hear it?
The code that plays the sound is:
else System.Media.SystemSounds.Exclamation.Play();
If you don't have any device in the device manager, you can install a Realtek Driver. It creates a virtual playback device.
After that, go to sound-playing devices, choose the virtual device and set it as default playback device. Open your app and check whether a sound is played by looking at the volume visualisation next to the device in the device manager.
(source: eightforums.com)
In Windows, I believe (provided the audio drivers are loaded, and Windows thinks there's at least some form of audio output device) - you can open the volume setting (from the system tray) and see the bar bounce up and down when sound is being generated.
Alternatively, if the box is running Windows Professional, RDP to it from a remote device? The audio will be passed over the RDP session and played on the client.
Search "Sound" in Windows (Control Panel), it shows you all your devices with the volume it outputs to that device.
You can see if your sound works by looking the current volume (the bar on the right of each device).
If your PC has no audio out device (I don'think it's the case), maybe you can add "virtual" output devices.

Naudio- Multiple sound device playback and recording issue

i am using WaveOut and WaveInEvent to record sound from multiple usb sound devices and playing it back to them. i am talking about 4-6 external usb sound cards that i have to record and playback at the same time all together.
so it means that for every sound device i have one object of WaveOut with the soundDevice ID and one object of WaveInEvent with the same SoundDevice ID (for record&playback).
my c# project throws mmexeption with explanation :"unspecified problem" when i am calling to the WaveInEvent.startRecording(). sometime it happens in the init of the WaveOut with the stream.
i thought that maybe there is a limitation of opening sound card devices for play&record or maybe naudio cant support it.
so is the limitation exist? or maybe i have to use diffrent object then WaveOut and WaveInEvent when handling multiple sound card device?
tried to play on all devices from Winamp and when I got to the forth sound card it didn't play.
I tried to plug one sound card to a different USB hub of the pc (not different port at the same hub, a new port on a different hub) and suddenly it works! also with Naudio. now i can open all of them to playback and record. I haven't tried massive check yet but its looking good.
it's seems like that the problem was that I overloaded the usb hub. I don't know if it because the usb hub doesn't has enough bandwidth or because something that belongs to voltage issue.

How to continue playing a capture device when the device is replugged in?

OK,I'm now developing a winform app that can capture stream from a video capture device using DirectShow.NET.
And the problem is when I plug the usb capture device out. the image freezes,and after trying to stop , my code hungs on IMediaControl.Stop() method. Thus i can't continue playing. So is there a way to stop the playing progress when device is plugged out? or how to replay after the device replugs in?Thanks.
There is no well-defined behavior for scenario with unplugged device. Eventually this should result in certain error code, however a delay with timeout might be involved. The behavior is dependent on actual implementation on the underlying filter backed by hardware driver.

how to find the main speakers directshow audio device

I am capturing the desktop using VLC and DirectShow an I need to find the main speakers audio device in order to capture all the sound from the desktop, can this be done programmaticly ?
I am using C# in windows XP and 7
You actually cannot capture data from speakers. The real options are:
audio capture from real audio input device, such as microphone
audio capture from loop back device (provided that it is enabled)
Note that loopback capture is different in Vista+ and older systems, also previously discussed here:
Is it possible to record sound played on the sound card?
Get sample of sound from stereo mix in Windows
https://stackoverflow.com/questions/6993186/windows-7-any-audio-libraries-supporting-loopback-audio-capturing-in-c

Categories