Comments (4)
Hmmm, that's a little weird.
Can you post a sample of the code so I can take a look?
from audioswitcher.
.NET Framework 4.8.1
4.0.0-Alpha5
To test, I had a slightly modified version of this running at the same time as this version was running. That one changed the volume and muted the audio every 3 seconds. Both in separate instances of Visual Studio 2022 and both run in DEBUG mode.
#define CHECKDEVICE
#define CONTINUOUS
using System;
using System.Collections;
using System.Diagnostics;
using System.Text;
using AudioSwitcher;
using AudioSwitcher.AudioApi;
using AudioSwitcher.AudioApi.CoreAudio;
#if CONTINUOUS
using System.Threading;
#endif
namespace SetSpeaker
{
internal class Program
{
static void Main(string[] args)
{
#if CONTINUOUS
do
{
#endif
Debug.WriteLine(DateTime.Now.ToString("hh:mm:ss.fffff"));
const double StandardAudioVolume = 100.0f; // Max volume
#if CHECKDEVICE
const string TARGETOUTPUT = "Crestron";
CoreAudioDevice itemTarget = null;
CoreAudioDevice itemCurrentDefault = null;
#endif
try
{
#if CHECKDEVICE
var devices = new CoreAudioController().GetPlaybackDevices(); // Get all playback devices
IEnumerator enumerator = devices.GetEnumerator();
while (enumerator.MoveNext())
{
CoreAudioDevice currDev = (CoreAudioDevice)enumerator.Current; // Get current indexed device
Debug.WriteLine($"FullName={currDev.FullName}, Default={currDev.IsDefaultDevice}");
//Console.WriteLine($"FullName={currDev.FullName}, Default={currDev.IsDefaultDevice}");
if (currDev.FullName.Contains("Speaker") || currDev.FullName.Contains("Display Audio"))
{
if (currDev.IsDefaultDevice)
{
// Save the address of the Default playback device
itemCurrentDefault = currDev;
}
if (currDev.FullName.Contains(TARGETOUTPUT))
{
// Save the address of the Target playback device
itemTarget = currDev;
}
}
}
if (itemTarget is null)
{
// If the Target playback device was not found, don't chnage the default playback device
}
else
{
// If the Target sound device is already the default, do nothing.
if (!ReferenceEquals(itemTarget, itemCurrentDefault))
{
itemTarget.SetAsDefault();
Debug.WriteLine($"{itemTarget.FullName} Set As Default");
//Console.WriteLine($"{itemTarget.FullName} Set As Default");
}
}
if (itemTarget is null)
{
// If the Target playback device was not found, don't change volume settings
}
else
{
#endif
CoreAudioDevice defaultDevice = new CoreAudioController().DefaultPlaybackDevice;
if (defaultDevice.Volume != StandardAudioVolume)
{
defaultDevice.SetVolumeAsync(StandardAudioVolume);
}
if (defaultDevice.IsMuted)
{
defaultDevice.ToggleMuteAsync();
}
#if CHECKDEVICE
if (itemTarget.Volume != StandardAudioVolume)
{
itemTarget.SetVolumeAsync(StandardAudioVolume);
}
if (itemTarget.IsMuted)
{
itemTarget.ToggleMuteAsync();
}
}
#endif
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
Debug.WriteLine(DateTime.Now.ToString("hh:mm:ss.fffff"));
#if CONTINUOUS
Thread.Sleep(4500);
} while (true);
#endif
}
}
}
from audioswitcher.
You are creating a CoreAudioController
controller many, many times.
This should only be created once per application (ideally, but a few times here and there is also fine)
It should also be disposed after use
I'd move the creation of the controller outside of your main loop, it should solve the task issue
from audioswitcher.
from audioswitcher.
Related Issues (20)
- NullReferenceException triggered from other process HOT 10
- OutOfMemoryException HOT 5
- hotkey to cycle the audio devices
- How to check for disconnected devices? HOT 7
- Remote desktop connection causes memory overflow?
- Add support for Enabling/Disabling Audio Devices HOT 1
- Is possible to make +100% volume? HOT 1
- Changing CoreAudio Name property HOT 5
- Setting default audio device return s false HOT 6
- CoreAudioController not working HOT 1
- When can we expect a new realease? HOT 3
- CoreAudioController constructor results in method access exception - Unity3D HOT 1
- Error with Activator.CreateInstance() Type.GetTypeFromCLSID(new Guid(ComInterfaceIds.DEVICE_ENUMERATOR_CID)); HOT 1
- CoreAudio 3.0.1 depends on AudioApi 3.0.0-beta5 in Nuget HOT 3
- System.Windows.Forms.Control.CreateHandle error at launch
- Any chance of a new release? HOT 2
- Allow loading properties for NotPresent devices HOT 2
- The CoreAudioController slow at InnerEnumerator.EnumAudioEndpoints HOT 2
- Some audio sessions don't showing
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from audioswitcher.