I am trying to save device information
in my application.
I managed to save as string
to ApplicationData.Current.RoamingSettings
but unable to save as deviceinformation
which I need to use to enumerate my device when the app starts.
I am not sure what is the right approach to do so. Can somebody advise? Thanks.
const string MicDeviceNameKey = "MicDeviceName";
const string MicDeviceIDKey = "MicDeviceID";
IPropertySet settings = ApplicationData.Current.RoamingSettings.Values;
public string MicDeviceName
{
get
{
object setting;
if (settings.TryGetValue(MicDeviceNameKey, out setting))
return (string)setting;
return null;
}
set
{
settings[MicDeviceNameKey] = value;
}
}
public DeviceInformation MicDeviceID
{
get
{
if (settings[MicDeviceIDKey] != null)
return (DeviceInformation)settings[MicDeviceIDKey];
return null;
}
set
{
settings[MicDeviceIDKey] = value;
}
}
Updated
I am using AudioGraph
to route mic input to line output.
Is there anyway to work around where I can load saved Device Information
for Capture
and Render
device to initialize AudioGraphSettings
.
public async Task CreateMicRoute(DeviceInformation output, DeviceInformation input)
{
// ################################################################################################
// Register the Output Source for the Playback
var settings = new AudioGraphSettings(AudioRenderCategory.Media);
settings.QuantumSizeSelectionMode = QuantumSizeSelectionMode.LowestLatency;
settings.PrimaryRenderDevice = output;
var result = await AudioGraph.CreateAsync(settings);
if (result.Status != AudioGraphCreationStatus.Success)
{
// Cannot create graph
//rootPage.NotifyUser(String.Format("AudioGraph Creation Error because {0}", result.Status.ToString()), NotifyType.ErrorMessage);
return;
}
//Create Audio Graph
micAudioGraph = result.Graph;
// ################################################################################################
// Create a device input node
var inProfile = MediaEncodingProfile.CreateWav(AudioEncodingQuality.Medium);
var DeviceInputResult = await micAudioGraph.CreateDeviceInputNodeAsync(MediaCategory.Media, inProfile.Audio, input);
if (DeviceInputResult.Status != AudioDeviceNodeCreationStatus.Success)
{
// Cannot create device input node
return;
}
// Set the Created Audio Input Node to Device Input Node
deviceInputNode = DeviceInputResult.DeviceInputNode;
// Create a device output node
var DeviceOutputResult = await micAudioGraph.CreateDeviceOutputNodeAsync();
if (DeviceOutputResult.Status != AudioDeviceNodeCreationStatus.Success)
{
// Cannot create device output node
return ;
}
// Selected Output device from Audio Graph is set to Device Output Node
deviceOutputNode = DeviceOutputResult.DeviceOutputNode;
// ################################################################################################
if (micAudioGraph == null)
return;
}
Please check document here,
For both
LocalSettings
andRoamingSettings
, the name of each setting can be 255 characters in length at most. Each setting can be up to 8K bytes in size and each composite setting can be up to 64K bytes in size.
The Windows Runtime data types are supported for app settings. But DeviceInformation
is not in the support list. For your scenario, we suggest your save some key value about DeviceInformation
such device id device kind. and get the device with device id.
Update
DeviceInformation
contains CreateFromIdAsync
method, you could store the DeviceInformation's id in to local setting, and retrieve DeviceInformation
with the following code.
DeviceInformation.CreateFromIdAsync("Device ID");