I have an problem with muting the mic on an windows 7 machine. But all the code i have found dosen't run ore it's not doing anything the runned. Have is it done for an Windows 7 machine using C# code. I just need an on/off solution.
The DDL file works also with Win x64bit. But i thing that i creates an error another place.
mixers.Recording.Lines.GetMixerFirstLineByComponentType(
MIXERLINE_COMPONENTTYPE.SRC_MICROPHONE).Volume = 0;
if (!mediaElement1.CheckAccess()) mediaElement1.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action)delegate { mediaElement1.Play(); });
if (MessageBox.Show("Incoming Call from: " + string.Format(e.RemoteParticipant), "Video Chat Call", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
mixers.Recording.Lines.GetMixerFirstLineByComponentType(
MIXERLINE_COMPONENTTYPE.SRC_MICROPHONE).Volume = 1;
if (!mediaElement1.CheckAccess()) mediaElement1.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action)delegate { mediaElement1.Stop(); });
_currentConversation.StartVideo();
}'
If error occurs at if (MessageBox.Show("Incoming Call from: " + string.Format(e.RemoteParticipant), "Video Chat Call", MessageBoxButton.YesNo) == MessageBoxResult.Yes) and says {"Arithmetic operation resulted in an overflow."}
http://www.computercabal.com/2010/11/mute-microphone-from-c-on-windows.html -- this gentleman appears to have had a similar problem, and he's provided the source code for a solution.
You can use Audio Switcher Api
https://www.nuget.org/packages/AudioSwitcher.AudioApi.CoreAudio/4.0.0-alpha5
Code is quite simple:
private async void btnMute_ButtonClick(object sender, EventArgs e)
{
var audioController = new CoreAudioController();
var devices = await audioController.GetDevicesAsync(DeviceType.Capture, DeviceState.Active);
var device = devices.FirstOrDefault(x => x.IsDefaultDevice);
if(device != null) {
await device.SetMuteAsync(!device.IsMuted);
}
}
this might help: Windows Mixer Control in C#
Good luck :).
EDIT: It can also mute certain devices if I'm right.
Related
I'm trying to do an UI with C# on Visual Studio (on PC[windows10]) and connect some bluetooth devices.
I'm using Windows.Devices.Radios & Windows.Devices.Bluetooth, but I have some troubles with that. After few steps I try to use the bluetooth when I press a button.
This is the code
private async void btnStart_ClickAsync(object sender, EventArgs e)
{
Repl test = new Repl();
var radio = await Radio.RequestAccessAsync();
if (access != RadioAccessStatus.Allowed)
{
return;
}
BluetoothAdapter adapter = await BluetoothAdapter.GetDefaultAsync();
if (null != adapter)
{
var btRadio = await adapter.GetRadioAsync();
if (bluetoothState)
{
await btRadio.SetStateAsync(RadioState.On);
}
else
{
await btRadio.SetStateAsync(RadioState.Off);
}
}
string connect = $"connect {macRight}\r\n";
//string start = "start\r\n";
await BaseCommands.repl.ParseLine(connect);
}
after the 1st request I'm always in the "return;"
I saw some people saying use x32 or x64 and x86. I already try that but I don't know why it doesn't work for me ...
I also saw some post saying change something in the Manifest, but I don't know where to find it :/
I'm a beginner with C#/.NET so if someone can help me to fix that i will appreciate =)
PS : I have another project which use bluetooth and it work perfectly so I have no ideas to fix my own project ...
I'm developing a c# desktop api with forms where I want to receive ACC data from a BLE server und display them in a chart.
So I'm running in a connection problem and I can't find any solution.
I can find my LE server Device with the watcher.
DevicePairingResult dpr = await device.DeviceInformation.Pairing.PairAsync(DevicePairingProtectionLevel.Encryption);
returns me "AlreadyPaired"
But when I do
device = await BluetoothLEDevice.FromBluetoothAddressAsync(bluetoothAddress: eventArgs.BluetoothAddress);
mGattService = device.GetGattService(MotionService_GUID);
mCharacteristic = mGattService.GetCharacteristics(ACC_Characteristic_GUID)[0];
and then
var con = device.ConnectionStatus;
I receive "Disconnected" in con.
I am bound with de device on windows( I searched for it in Windows and entered the Code) but I am not connected(based on the Status in the windows info center).
I've read in another Thread in the windows c# developer page that it should not be necessary anymore to pair the device manually.
I'm pretty shure that the rest of my code works because sometimes I can get a connection( pretty confusing for me) and see the right Data in my chart.
Right now I just want to reach a stable connection before changing other part of my code.
Anyone any idea how to solve this?
Thx medTech
Edit:
Here is part of the Code:
Scanning for BLE
private void button1_Click(object sender, EventArgs e)
{
// Create Bluetooth Listener
var watcher = new BluetoothLEAdvertisementWatcher();
watcher.ScanningMode = BluetoothLEScanningMode.Active;
// Register callback for when we see an advertisements
watcher.Received += OnAdvertisementReceivedAsync;
// Wait 5 seconds to make sure the device is really out of range
watcher.SignalStrengthFilter.OutOfRangeTimeout = TimeSpan.FromMilliseconds(5000);
watcher.SignalStrengthFilter.SamplingInterval = TimeSpan.FromMilliseconds(2000);
// Starting watching for advertisements
watcher.Start();
}
Connect to Server:
private async void OnAdvertisementReceivedAsync(BluetoothLEAdvertisementWatcher watcher, BluetoothLEAdvertisementReceivedEventArgs eventArgs)
{
// Filter for specific Device
if (eventArgs.Advertisement.LocalName == "MYDEVICE")
{
watcher.Stop();
var MotionService_GUID = new Guid("00002000-0000-1000-8000-00805F9B34FB");
var ACC_Characteristic_GUID = new Guid("00002001-0000-1000-8000-00805F9B34FB");
device = await BluetoothLEDevice.FromBluetoothAddressAsync(bluetoothAddress: eventArgs.BluetoothAddress);
DevicePairingResult dpr = await device.DeviceInformation.Pairing.PairAsync(DevicePairingProtectionLevel.Encryption);
mGattService = device.GetGattService(MotionService_GUID);
mCharacteristic = mGattService.GetCharacteristics(ACC_Characteristic_GUID)[0];
GattDeviceServicesResult result = await device.GetGattServicesAsync();
GattCommunicationStatus status1 = await ReadFromCharacteristicAsync(mCharacteristic);
var con = device.ConnectionStatus;
while (status1 == GattCommunicationStatus.Success)
{
try
{
status1 = await ReadFromCharacteristicAsync(mCharacteristic);
}
catch
{
Console.WriteLine("ERROR");
status1 = GattCommunicationStatus.Unreachable;
}
}
}
}
Read from Characteristic:
async Task ReadFromCharacteristicAsync(GattCharacteristic mCharacteristic)
{
GattReadResult readResult = await mCharacteristic.ReadValueAsync(BluetoothCacheMode.Uncached);
if (readResult.Status == GattCommunicationStatus.Success)
{
byte[] data = new byte[readResult.Value.Length];
DataReader.FromBuffer(readResult.Value).ReadBytes(data);
if (chart1.IsHandleCreated)
{
this.Invoke((MethodInvoker)delegate { updateChart(data); });
}
return readResult.Status;
}
return readResult.Status;
}
Terminate Connection
private async Task<bool> ClearBluetoothLEDeviceAsync()
{
mCharacteristic.Service.Dispose();
mGattService.Dispose();
await device.DeviceInformation.Pairing.UnpairAsync();
device?.Dispose();
device = null;
GC.Collect();
return true;
}
SO now when I connect the first time to the Server, I only receive zeros which shows me that the there might be a authentication Error.
After that I always receive this Error:
"System.ArgumentException" in mscorlib.dll with a notification that there is noch executable Code left because all Threads are doing some asynchronous stuff.
This Error gets thrown when I try to read from the Characteristic.
I never coded in c# before so I am not shure if there is an error in my asynchronous part oder the communication part.
Thanks you
Pairing is not the same as connecting!
I really advise using the BLE-advertisementWatcher to select and connect to your device.
The reason is that many BLE-devices don't save their pairing status.
In windows device-watcher once paired, the device stays paired even if it is switched off or out of reach.
Also many times the connection status is kept, unless the device is unpaired and disposed in code or removed in windows settings.
All BLE-devices that I know of start advertising as soon as there is no connection for some time.
This time depends on the device, but most of the time within seconds.
So don't pair but just connect if the device is advertising.
I have a problem with UWP media capture initilization. My code is below,
private async Task StartPreviewAsync()
{
try
{
//set initilize settings
Settings oneSetting = null;
using (SQLite.Net.SQLiteConnection conn = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), sqlpath))
{
oneSetting = (from p in conn.Table<Settings>()
where p.id == 0
select p).FirstOrDefault();
}
if (oneSetting.camera != null)
{
var settings = new MediaCaptureInitializationSettings();
settings.StreamingCaptureMode = StreamingCaptureMode.Video;
settings.PhotoCaptureSource = PhotoCaptureSource.VideoPreview;
var devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(Windows.Devices.Enumeration.DeviceClass.VideoCapture);
foreach (var device in devices)
{
if ((device.Id).Equals(oneSetting.cameraId))
{
settings.VideoDeviceId = device.Id;
break;
}
}
_mediaCapture = new MediaCapture();
await _mediaCapture.InitializeAsync(settings);
//MediaCapture m = new MediaCapture();
//await m.InitializeAsync();
var focusSettings = new FocusSettings();
focusSettings.AutoFocusRange = AutoFocusRange.FullRange;
focusSettings.Mode = FocusMode.Auto;
focusSettings.WaitForFocus = true;
focusSettings.DisableDriverFallback = false;
_mediaCapture.VideoDeviceController.FocusControl.Configure(focusSettings);
await _mediaCapture.VideoDeviceController.ExposureControl.SetAutoAsync(true);
_mediaCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
_mediaCapture.SetRecordRotation(VideoRotation.Clockwise90Degrees);
capturePreview.Source = _mediaCapture;
await _mediaCapture.StartPreviewAsync();
_isPreviewing = true;
_displayRequest.RequestActive();
DisplayInformation.AutoRotationPreferences = DisplayOrientations.Landscape;
}
}
catch (UnauthorizedAccessException)
{
// This will be thrown if the user denied access to the camera in privacy settings
System.Diagnostics.Debug.WriteLine("The app was denied access to the camera");
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("MediaCapture initialization failed. {0}", ex.Message);
}
}
It returns MediaCapture initialization failed. {0} error. Recently, it runs well. But since this morning it gives the error. Is there anybody who takes the same error?
The full error message is that;
The specified device interface level or feature is not supported on this system.
: Media Capture initialization failed. {0}
The thread 0x1924 has exited with code 0 (0x0).
Same issue here.
After many hours of retries and googling i realize that it was related to the windows 10 anniversary update.
I found the solution here:
https://www.macecraft.com/fix-webcam-issues-windows-10-anniversary-update/
I added the EnableFrameServerMode key in the registry and magically the webcam came back working.
But since this morning it gives the error.
Did you recently update your device OS? On which device did you meet this problem and what is the OS version?
I personally think this is more like a device problem or drive issue. You can try to restart your device and see if this helps. Or you can start the built-in camera app and check if this official app runs well.
I'm writing this answer here because there are too many details need to be confirmed, please leave a comment here to tell us the detail information about your device and your test result based on my suggestion, so can we keep look into this issue.
I am using Geoposition and a Postition changed event to grab Coordinates of the device location.
private async void StartGpsMonitoring()
{
if (locator == null)
{
locator = new Geolocator();
}
if (locator.LocationStatus == PositionStatus.Disabled)
{
//throw new Exception();
MessageDialog noGpsDialog = new MessageDialog("Location services are disabled, please enable location services");
noGpsDialog.Commands.Add(new UICommand("Location Settings", new UICommandInvokedHandler(this.CommandInvokedHandler), 0));
noGpsDialog.Commands.Add(new UICommand("Cancel", new UICommandInvokedHandler(this.CommandInvokedHandler), 1));
await noGpsDialog.ShowAsync();
}
if (locator != null)
{
//locator.MovementThreshold = 3;
locator.ReportInterval = 1;
locator.DesiredAccuracy = PositionAccuracy.High;
locator.PositionChanged +=
new TypedEventHandler<Geolocator,
PositionChangedEventArgs>(locator_PositionChanged);
}
}
private async void locator_PositionChanged(Geolocator sender, PositionChangedEventArgs e)
{
string speed = string.Empty;
await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
Geoposition geoPosition = e.Position;
if (e.Position.Coordinate.Speed != null)
{
speed = e.Position.Coordinate.Speed.Value.ToString(); // always 5.8
}
geolocation = geoPosition.Coordinate.Point.Position.Latitude.ToString() + " " +
geoPosition.Coordinate.Point.Position.Longitude.ToString() + "Speed = " +
speed;
var textBlockStatus =
ControlHelper.FindChildControl<TextBlock>(JourneyTrackerSection, "TextBlockStatus") as TextBlock;
textBlockStatus.Text = geolocation;
});
}
I am also trying to get the speed value. But when using the emulator I am always getting 5.8 regardless of if I have speed limit/walking/biking set on the emulator, and still get 5.8 from a static position.
Can anybody shed some light as to why? Is it just the emulator? Would I get an accurate result if I used a real device?
Its hard to develop a location speed application where I have to run out side every time I want to debug/run it.
Any help much appreciated.
Thought I would post some details as to what I have managed to find out in case anyone comes across this in the future. Looks like this is because it is running on the emulator. Managed to come across some limited details about using the geopositioning code and some details about it being hardware specific. After I have managed to get hold of a windows phone for testing the emulator cannot do the speed. Works perfect on an actual device.
This is extremely annoying by Microsoft. means that every time I need to test my app I have to go out driving. Rendering the GPS emulator completely useless!
hi there :) il get right to it.
Problem :
when i try to instanciate LiveConnectClient and then try to access the event : GetCompleted
which supose to be in the LiveConnectClient is not showing and on all the examples i been looking at even those on here are using it. this is not the only class this is happening on it is also happening on LiveAuthClient as well no events even the post on the net says there should be.
i tried to reinstall Vs2012 and sdk wp8 and live sdk from scratch but have not solved it
for refrence i using this example to see if i can it to work :
//event triggered when Skydrive sign in status is changed
private void btnSignIn_SessionChanged(object sender, Microsoft.Live.Controls.LiveConnectSessionChangedEventArgs e)
{
//if the user is signed in
if (e.Status == LiveConnectSessionStatus.Connected)
{
session = e.Session;
client = new LiveConnectClient(e.Session);
infoTextBlock.Text = "Accessing SkyDrive...";
//get the folders in their skydrive
client.GetCompleted +=
new EventHandler<LiveOperationCompletedEventArgs>(btnSignin_GetCompleted);
client.GetAsync("me/skydrive/files?filter=folders,albums");
}
//otherwise the user isn't signed in
else
{
infoTextBlock.Text = "Not signed in.";
client = null;
}
}
i got no luck solving it and running out of ideas. So im hoping one of u boys out there can shed some light on it or lend a hand with dew wise words :)
thanks in advance. and i do apologies if this is to long a post.
regards jens
Indeed, it seems like those events have been removed in the latest versions of the SDK. You don't need them though, thanks to the async/await keywords. First, mark your method as async, then call the GetAsync method with the await keyword. And place afterward the code you would normally put in the GetCompleted event:
private async void btnSignIn_SessionChanged(object sender, Microsoft.Live.Controls.LiveConnectSessionChangedEventArgs e)
{
//if the user is signed in
if (e.Status == LiveConnectSessionStatus.Connected)
{
session = e.Session;
client = new LiveConnectClient(e.Session);
infoTextBlock.Text = "Accessing SkyDrive...";
//get the folders in their skydrive
var result = await client.GetAsync("me/skydrive/files?filter=folders,albums");
// Do here what you would normally do in btnSignin_GetCompleted
}
//otherwise the user isn't signed in
else
{
infoTextBlock.Text = "Not signed in.";
client = null;
}
}