The following code works well
AudioManager am = (AudioManager)this.GetSystemService(Context.AudioService);
am.RingerMode = RingerMode.Vibrate;
So after running it the ring volume gets to 0, but I would want to set it to a custom value like for instance "57".
To do this I used the following code:
AudioManager am = (AudioManager)this.GetSystemService(Context.AudioService);
am.SetStreamVolume(Stream.Ring, 57, 0);
After this code runs nothing changed to my ring volume, I expected that it will change to a "57" value.
I am using latest Xamarin libraries on a Android 7.0 version. I need to implement this only for Android.
Is this custom ring volume set a limitation ?
What should this am.SetStreamVolume(Stream.Ring, 57, 0); actually do (if it is not changing the ring volume of the phone).
You could use GetStreamMaxVolume firstly to get the maximum value for a particular stream, then set a proper number smaller than the maximum value.
Related
I'm using NTwain to scan documents into memory and I have it all working except for one part: When trying to set the size of the page to scan, it scans the entire width and height, rather than just the specified size.
I went and examined the details of NTwain's capabilities on the current source, and found the the ICapSupportedSizes was not supported for any action.
Here's how I'm setting the capabilities (this is on an open, valid source)
_twain.CurrentSource.Capabilities.ICapXResolution.SetValue(new TWFix32() { Whole = 600 });
_twain.CurrentSource.Capabilities.ICapYResolution.SetValue(new TWFix32() { Whole = 600 });
_twain.CurrentSource.Capabilities.ICapPixelType.SetValue(PixelType.BlackWhite);
_twain.CurrentSource.Capabilities.ICapSupportedSizes.SetValue(SupportedSize.USLegal);
_twain.CurrentSource.Capabilities.CapDuplexEnabled.SetValue(BoolType.False);
UPDATE:
I've found out that none of the settings are actually working. I set it as black and white, even if it shows black and white in the settings, it displays in color. Doesn't matter what DPI I set it at either as it defaults to 300 no matter what. I've updated it to grab out the source and use that to change the settings and call Enable, but it still doesn't work.
Any help is appreciated.
Thanks!
Enviornment Information
.NET Framework 4.6.1
Win Forms
C#
NTwain
Scanner: Canon Flatbed Scanner Unit 102
You will need to use the DGImage.ImageLayout property to set the page size in a generally-supported way.
For example:
var ds = _twain.CurrentSource;
ds.Capabilities.ICapUnits.SetValue(Unit.Inches);
ds.DGImage.ImageLayout.Get(out TWImageLayout imageLayout);
imageLayout.Frame = new TWFrame
{
Left = 0,
Right = pageWidthInInches,
Top = 0,
Bottom = pageHeightInInches
};
ds.DGImage.ImageLayout.Set(imageLayout);
My system has two graphics cards installed: a Quadro FX 1500, which supports up to DirectX 9, and a Quadro 600, which supports up to DirectX 11. I'm writing a C# application (using the SharpDX wrapper library) against DirectX 11, so I want to make sure that I'm always choosing the Quadro 600 as my device. Will DirectX 11 select the correct device/graphics card by default, or if not, is there a way I can enumerate the devices on my system and choose the one that supports DirectX 11?
Right now my device initialization code looks like this:
//which device do we get?
SharpDX.Direct3D11.Device defaultDevice = new SharpDX.Direct3D11.Device(DriverType.Hardware, DeviceCreationFlags.Debug);
Thanks!
In order to create a device for a specific adapter, you need to pass it as argument in the device constructor.
First get the device index that you need :
SharpDX.DXGI.Factory f = new SharpDX.DXGI.Factory1();
SharpDX.DXGI.Adapter a = f.GetAdapter(adapterindex);
FeatureLevel[] levels = new FeatureLevel[]
{
#if DIRECTX11_1
FeatureLevel.Level_11_1,
#endif
FeatureLevel.Level_11_0,
FeatureLevel.Level_10_1,
FeatureLevel.Level_10_0,
FeatureLevel.Level_9_3
};
DeviceCreationFlags flags = DeviceCreationFlags.BgraSupport;
var dev = new Device(a, flags, levels);
To find the right adapter, you can loop GetAdapter function, and use Description to find the one you need.
Please note that you should not use the Hardware flag in case you specify a device manually. BgraSupport is common practice.
So I have some code that takes a photo in a UWP app (running on windows desktops and phones) using this code.
await _mediaCapture.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateJpeg(), stream);
And it works great but it always takes the image at the full resolution of the device... (so 44 megapixels on a Lumia 1020) which is too big for me. I want to limit the resolution to a fixed size (say around 16 megapixel).
So is there a way of setting the camera capture resolution or will I have to capture it at full resolution and downscale it myself?
You should be able to change resolution of MediaCapture element by setting MediaStreamProperties just after initialization:
// initialization here
// get available resolutions
var resolutions = captureManager.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo).ToList();
// set used resolution
await captureManager.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, resolutions[1]);
I'm trying to control the volume of an AVPlayer in my iPhone app.
I seem to receive an "unrecognized selector sent to instance" error when trying to simply get the volume value, or even set it, from the AVPlayer.Volume property -
AVPlayer myAVPlayer = new AVPlayer();
var volume = myAVPlayer.Volume;
Any ideas how to make this work?
That's likely because you're using an older device (or simulator) version of iOS. The Volume property was added in iOS7.
There are other ways to set the volume - but you'll need to tell us more about what you're trying to accomplish.
I wanted to know, what would the coding be if I wanted to toggle mute/unmute of my microphone. I am making a program that can run in the background and pickup a keypress event and toggle mute/unmute of the mic. Any help with any of that coding would be very helpful. I am pretty new to C#, and this is just a really simple program I wanted to make. That is all it does, is it will listen for keypress of the spacebar, even when the program is in the background, then when the spacebar is pressed it will mute/unmute the mic.
Thank you for any and all help!
For Windows Vista and newer, you can no longer use the Media Control Interface, Microsoft has a new Core Audio API that you must access to interface with audio hardware in these newer operating systems.
Ray Molenkamp wrote a nice managed wrapper for interfacing with the Core Audio API here:
Vista Core Audio API Master Volume Control
Since I needed to be able to mute the microphone from XP, Vista and Windows 7 I wrote a little Windows Microphone Mute Library which uses Ray's library on the newer operating systems and parts of Gustavo Franco's MixerNative library for Windows XP and older.
You can download the source of a whole application which has muting the microphone, selecting it as a recording device, etc.
http://www.codeguru.com/csharp/csharp/cs_graphics/sound/article.php/c10931/
you can use MCI (Media Control Interface) to access mics and change their volume system wise. Check the code below it should be setting volume to 0 for all system microphones. Code is in c; check pinvoke for details on how to translate this code to c#
#include "mmsystem.h"
...
void MuteAllMics()
{
HMIXER hmx;
mixerOpen(&hmx, 0, 0, 0, 0);
// Get the line info for the wave in destination line
MIXERLINE mxl;
mxl.cbStruct = sizeof(mxl);
mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN;
mixerGetLineInfo((HMIXEROBJ)hmx, &mxl, MIXER_GETLINEINFOF_COMPONENTTYPE);
// find the microphone source line connected to this wave in destination
DWORD cConnections = mxl.cConnections;
for (DWORD j=0; j<cConnections; j++)
{
mxl.dwSource = j;
mixerGetLineInfo((HMIXEROBJ)hmx, &mxl, MIXER_GETLINEINFOF_SOURCE);
if (MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE == mxl.dwComponentType)
{
// Find a volume control, if any, of the microphone line
LPMIXERCONTROL pmxctrl = (LPMIXERCONTROL)malloc(sizeof MIXERCONTROL);
MIXERLINECONTROLS mxlctrl =
{
sizeof mxlctrl,
mxl.dwLineID,
MIXERCONTROL_CONTROLTYPE_VOLUME,
1,
sizeof MIXERCONTROL,
pmxctrl
};
if (!mixerGetLineControls((HMIXEROBJ) hmx, &mxlctrl, MIXER_GETLINECONTROLSF_ONEBYTYPE))
{
DWORD cChannels = mxl.cChannels;
if (MIXERCONTROL_CONTROLF_UNIFORM & pmxctrl->fdwControl)
cChannels = 1;
LPMIXERCONTROLDETAILS_UNSIGNED pUnsigned = (LPMIXERCONTROLDETAILS_UNSIGNED)
malloc(cChannels * sizeof MIXERCONTROLDETAILS_UNSIGNED);
MIXERCONTROLDETAILS mxcd =
{
sizeof(mxcd),
pmxctrl->dwControlID,
cChannels,
(HWND)0,
sizeof MIXERCONTROLDETAILS_UNSIGNED,
(LPVOID) pUnsigned
};
mixerGetControlDetails((HMIXEROBJ)hmx, &mxcd, MIXER_SETCONTROLDETAILSF_VALUE);
// Set the volume to the middle (for both channels as needed)
//pUnsigned[0].dwValue = pUnsigned[cChannels - 1].dwValue = (pmxctrl->Bounds.dwMinimum+pmxctrl->Bounds.dwMaximum)/2;
// Mute
pUnsigned[0].dwValue = pUnsigned[cChannels - 1].dwValue = 0;
mixerSetControlDetails((HMIXEROBJ)hmx, &mxcd, MIXER_SETCONTROLDETAILSF_VALUE);
free(pmxctrl);
free(pUnsigned);
}
else
{
free(pmxctrl);
}
}
}
mixerClose(hmx);
}
here you can find more code on this topic
hope this helps, regards
I have several microphones in win7 and class WindowsMicrophoneMuteLibrary.CoreAudioMicMute is incorrect in this case.
so I change the code and works great because now his cup Whistle all microphones and not just in the last recognized by win7.
I am attaching the new class to put in place.
http://www.developpez.net/forums/d1145354/dotnet/langages/csharp/couper-micro-sous-win7/