コード例 #1
1
ファイル: MainForm.cs プロジェクト: cboseak/KoPlayer
        public MainForm()
        {
            library = Library.Load();
            if (library == null)
            {
                library = new Library();
                library.Save();
            }
            library.LibraryChanged += library_LibraryChanged;

            settings = Settings.Load(SETTINGSPATH);
            if (settings == null)
                settings = new Settings();

            MMDeviceEnumerator enumerator = new MMDeviceEnumerator();
            defaultAudioDevice = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Console);
            this.musicPlayer.OpenCompleted += equalizerSettings_ShouldSet;

            this.equalizerSettings = EqualizerSettings.Load(EQUALIZERPATH);
            if (this.equalizerSettings == null)
            {
                this.equalizerSettings = new EqualizerSettings();
                this.equalizerSettings.Save(EQUALIZERPATH);
            }
            this.equalizerSettings.ValueChanged += equalizerSettings_ShouldSet;

            SetUpGlobalHotkeys();

            InitializeComponent();
        }
コード例 #2
1
ファイル: MainWindow.cs プロジェクト: hoangduit/cscore
        private void RefreshDevices()
        {
            deviceList.Items.Clear();

            using (var deviceEnumerator = new MMDeviceEnumerator())
            using (var deviceCollection = deviceEnumerator.EnumAudioEndpoints(
                CaptureMode == CaptureMode.Capture ? DataFlow.Capture : DataFlow.Render, DeviceState.Active))
            {
                foreach (var device in deviceCollection)
                {
                    var deviceFormat = WaveFormatFromBlob(device.PropertyStore[
                        new PropertyKey(new Guid(0xf19f064d, 0x82c, 0x4e27, 0xbc, 0x73, 0x68, 0x82, 0xa1, 0xbb, 0x8e, 0x4c), 0)].BlobValue);

                    var item = new ListViewItem(device.FriendlyName) {Tag = device};
                    item.SubItems.Add(deviceFormat.Channels.ToString(CultureInfo.InvariantCulture));

                    deviceList.Items.Add(item);
                }
            }
        }
コード例 #3
1
 private static MMDevice GetDefaultDevice()
 {
     using (var enumerator = new MMDeviceEnumerator())
     {
         try
         {
             return enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
         }
         catch (CoreAudioAPIException)
         {
             return null;
         }
     }
 }
コード例 #4
0
 public void InitManager()
 {
     deviceEnum = new MMDeviceEnumerator();
     deviceEnum.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
     device = deviceEnum.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
     sessionManager = AudioSessionManager2.FromMMDevice(device);
 }
コード例 #5
0
ファイル: MMDeviceEnumerator.cs プロジェクト: opcon/cscore
 /// <summary>
 /// Generates a collection of audio endpoint devices that meet the specified criteria.
 /// </summary>
 /// <param name="dataFlow">The data-flow direction for the endpoint device.</param>
 /// <param name="stateMask">The state or states of the endpoints that are to be included in the collection.</param>
 /// <returns><see cref="MMDeviceCollection"/> which contains the enumerated devices.</returns>
 public static MMDeviceCollection EnumerateDevices(DataFlow dataFlow, DeviceState stateMask)
 {
     using (var enumerator = new MMDeviceEnumerator())
     {
         return enumerator.EnumAudioEndpoints(dataFlow, stateMask);
     }
 }
コード例 #6
0
 public IEnumerable<MMDevice> EnumerateWasapiDevices()
 {
     using (MMDeviceEnumerator enumerator = new MMDeviceEnumerator())
     {
         return enumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active);
     }
 }
コード例 #7
0
        public MMNotificationClient(MMDeviceEnumerator enumerator)
        {
            if (enumerator == null)
                throw new ArgumentNullException("enumerator");

            Initialize(enumerator);
        }
コード例 #8
0
 public MMNotificationClient()
 {
     using (var e = new MMDeviceEnumerator())
     {
         Initialize(e);
     }
 }
コード例 #9
0
 public static MMDevice GetDefaultSoundDevice()
 {
     using (var enumerator = new MMDeviceEnumerator())
     {
         return enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Console);
     }
 }
コード例 #10
0
ファイル: MMDeviceEnumerator.cs プロジェクト: opcon/cscore
 /// <summary>
 /// Returns the default audio endpoint for the specified data-flow direction and role.
 /// </summary>
 /// <param name="dataFlow">The data-flow direction for the endpoint device.</param>
 /// <param name="role">The role of the endpoint device.</param>
 /// <returns><see cref="MMDevice"/> instance of the endpoint object for the default audio endpoint device.</returns>
 public static MMDevice DefaultAudioEndpoint(DataFlow dataFlow, Role role)
 {
     using (var enumerator = new MMDeviceEnumerator())
     {
         return enumerator.GetDefaultAudioEndpoint(dataFlow, role);
     }
 }
コード例 #11
0
        private static AudioSessionManager2 GetDefaultAudioSessionManager2(DataFlow dataFlow)
        {
            using CSCore.CoreAudioAPI.MMDeviceEnumerator enumerator = new CSCore.CoreAudioAPI.MMDeviceEnumerator();
            using var device = enumerator.GetDefaultAudioEndpoint(dataFlow, Role.Multimedia);
            var sessionManager = AudioSessionManager2.FromMMDevice(device);

            return(sessionManager);
        }
コード例 #12
0
ファイル: CsCoreEngine.cs プロジェクト: Artentus/GameUtils
 public CsCoreEngine()
 {
     using (var enumerator = new MMDeviceEnumerator())
     {
         device = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Console);
     }
     endpointVolume = AudioEndpointVolume.FromDevice(device);
 }
コード例 #13
0
 private AudioSessionManager2 GetDefaultAudioSessionManager2(DataFlow dataFlow)
 {
     using (var enumerator = new MMDeviceEnumerator())
     {
         using (var device = enumerator.GetDefaultAudioEndpoint(dataFlow, Role.Multimedia))
         {
             var sessionManager = AudioSessionManager2.FromMMDevice(device);
             return sessionManager;
         }
     }
 }
コード例 #14
0
ファイル: MMDevicesTests.cs プロジェクト: hoangduit/cscore
        public void CanAccessPropertyStore()
        {
            using (var enumerator = new MMDeviceEnumerator())
            using (var collection = enumerator.EnumAudioEndpoints(DataFlow.All, DeviceState.All))
            {
                Utils.DumpCollection(collection);

                enumerator.Dispose();
                collection.Dispose();
            }
        }
コード例 #15
0
ファイル: MMDevicesTests.cs プロジェクト: hoangduit/cscore
 public void CanCreateDeviceNotificationEvent()
 {
     using (var enumerator = new MMDeviceEnumerator())
     using (var notification = new MMNotificationClient(enumerator))
     {
         notification.DefaultDeviceChanged += (s, e) => { };
         notification.DeviceAdded += (s, e) => { };
         notification.DevicePropertyChanged += (s, e) => { };
         notification.DeviceRemoved += (s, e) => { };
         notification.DeviceStateChanged += (s, e) => { };
     }
 }
コード例 #16
0
ファイル: Utils.cs プロジェクト: hoangduit/cscore
 public static AudioClient CreateDefaultRenderClient()
 {
     using (var enumerator = new MMDeviceEnumerator())
     {
         using (var device = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Console))
         {
             var audioClient = AudioClient.FromMMDevice(device);
             Assert.IsNotNull(audioClient);
             return audioClient;
         }
     }
 }
コード例 #17
0
ファイル: MusicPlayer.cs プロジェクト: koaset/KoPlayer
        public MusicPlayer()
        {
            using (var enumerator = new MMDeviceEnumerator())
            {
                device = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);

                using (var client = AudioClient.FromMMDevice(device))
                {
                    client.Initialize(AudioClientShareMode.Shared,
                        AudioClientStreamFlags.None, 1000, 0, client.GetMixFormat(), Guid.Empty);
                }
            }
        }
コード例 #18
0
ファイル: MMDevicesTests.cs プロジェクト: hoangduit/cscore
        public void CanEnumerateCaptureDevices()
        {
            using (var enumerator = new MMDeviceEnumerator())
            using (var collection = enumerator.EnumAudioEndpoints(DataFlow.Capture, DeviceState.All))
            {
                foreach (var item in collection)
                {
                    Debug.WriteLine(item.ToString());
                    item.Dispose();
                }

                enumerator.Dispose();
                collection.Dispose();
            }
        }
コード例 #19
0
 public void CanCreateAudioSessionManager2()
 {
     using (var enumerator = new MMDeviceEnumerator())
     {
         using (var collection = enumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active))
         {
             foreach (var device in collection)
             {
                 using (var sessionManager = AudioSessionManager2.FromMMDevice(device))
                 {
                     Assert.IsNotNull(sessionManager);
                 }
             }
         }
     }
 }
コード例 #20
0
        /// <summary>
        /// Tries the get device associated with the <see cref="DeviceId"/>.
        /// </summary>
        /// <param name="device">The device associated with the <see cref="DeviceId"/>. If the return value is <c>false</c>, the <paramref name="device"/> will be null.</param>
        /// <returns><c>true</c> if the associated device be successfully retrieved; false otherwise.</returns>
        public bool TryGetDevice(out MMDevice device)
        {
            try
            {
                using (var deviceEnumerator = new MMDeviceEnumerator())
                {
                    device = deviceEnumerator.GetDevice(DeviceId);
                }
                return true;
            }
            catch (Exception)
            {
                device = null;
            }

            return false;
        }
コード例 #21
0
ファイル: VolumeHelper.cs プロジェクト: KiKoS0/toastify
 public static float GetSpotifyInstaVolume()
 {
     using (var enumerator = new CSCore.CoreAudioAPI.MMDeviceEnumerator())
         using (var device = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia))
             using (var sessionManager = AudioSessionManager2.FromMMDevice(device))
                 using (var sessionEnumerator = sessionManager.GetSessionEnumerator())
                 {
                     foreach (var session in sessionEnumerator)
                     {
                         using (var audioMeterInformation = session.QueryInterface <AudioMeterInformation>())
                             using (var audioIdInformation = session.QueryInterface <AudioSessionControl2>())
                             {
                                 if (audioIdInformation.SessionIdentifier.Contains("Spotify"))
                                 {
                                     return(audioMeterInformation.GetPeakValue());
                                 }
                             }
                     }
                 }
     return(float.NaN);
 }
コード例 #22
0
ファイル: MMDevicesTests.cs プロジェクト: hoangduit/cscore
 public void GetDefaultRenderEndpoint()
 {
     using (var enumerator = new MMDeviceEnumerator())
     {
         using (var device = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Console))
         {
             Debug.WriteLine(device.ToString());
         }
     }
 }
コード例 #23
0
 private void Initialize(MMDeviceEnumerator enumerator)
 {
     int result = enumerator.RegisterEndpointNotificationCallbackNative(this);
     CoreAudioAPIException.Try(result, "IMMDeviceEnumerator", "RegisterEndpointNotificationCallback");
 }
コード例 #24
0
        private void Initialize(MMDeviceEnumerator enumerator)
        {
            int result = enumerator.RegisterEndpointNotificationCallbackNative(this);

            CoreAudioAPIException.Try(result, "IMMDeviceEnumerator", "RegisterEndpointNotificationCallback");
        }
コード例 #25
0
        private void LoadSoundOutModes()
        {
            SoundOutModes.Clear();
            using (var enumerator = new MMDeviceEnumerator())
            {
                MMDevice defaultDevice;
                try
                {
                    defaultDevice = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
                }
                catch (CoreAudioAPIException)
                {
                    defaultDevice = null;
                }

                if (WasapiOut.IsSupportedOnCurrentPlatform)
                {
                    var wasApiMode = new SoundOutMode("WASAPI", SoundOutType.WasApi, GetWasApiSoundOutDeviceById, GetWasApiSoundOut, new SoundOutDevice("Windows Default", WindowsDefaultId, SoundOutType.WasApi));

                    using (var devices = enumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active))
                    {
                        foreach (var device in devices.Select(x => new SoundOutDevice(x.FriendlyName, x.DeviceID, SoundOutType.WasApi, defaultDevice != null && defaultDevice.DeviceID == x.DeviceID)))
                            wasApiMode.Devices.Add(device);
                    }

                    UpdateWindowsDefault(wasApiMode);
                    SoundOutModes.Add(wasApiMode);
                }

                var directSoundMode = new SoundOutMode("DirectSound", SoundOutType.DirectSound, GetDirectSoundOutDeviceById, GetDirectSoundOut, new SoundOutDevice("Windows Default", WindowsDefaultId, SoundOutType.DirectSound));
                foreach (var device in DirectSoundDeviceEnumerator.EnumerateDevices().Select(x => new SoundOutDevice(x.Description, x.Module, SoundOutType.DirectSound, defaultDevice != null && x.Description == defaultDevice.FriendlyName)))
                   directSoundMode.Devices.Add(device);

                UpdateWindowsDefault(directSoundMode);
                SoundOutModes.Add(directSoundMode);
                CheckCurrentState();
            }
        }
コード例 #26
0
        private static ISoundOut GetWasApiSoundOut(ISoundOutDevice device)
        {
            MMDevice mmDevice = null;
            if (device.Id == WindowsDefaultId)
            {
                mmDevice = GetDefaultDevice();
            }

            if (mmDevice == null)
            {
                using (var enumerator = new MMDeviceEnumerator())
                {
                    using (var devices = enumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active))
                    {
                        if (devices == null || devices.Count == 0)
                            throw new NoDeviceFoundException();

                        mmDevice = devices.FirstOrDefault(x => x.DeviceID == device.Id) ?? GetDefaultDevice() ?? devices.First();
                    }
                }
            }

            return new WasapiOut { Device = mmDevice,UseChannelMixingMatrices = false };
        }
コード例 #27
0
ファイル: Form1.cs プロジェクト: hoangduit/cscore
        private void Form1_Load(object sender, EventArgs e)
        {
            using (var mmdeviceEnumerator = new MMDeviceEnumerator())
            {
                using (
                    var mmdeviceCollection = mmdeviceEnumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active))
                {
                    foreach (var device in mmdeviceCollection)
                    {
                        _devices.Add(device);
                    }
                }
            }

            comboBox1.DataSource = _devices;
            comboBox1.DisplayMember = "FriendlyName";
            comboBox1.ValueMember = "DeviceID";
        }
コード例 #28
0
 private static ISoundOutDevice GetWasApiSoundOutDeviceById(string id)
 {
     using (var mmdeviceEnumerator = new MMDeviceEnumerator())
     {
         using (var device =
             mmdeviceEnumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active)
                 .FirstOrDefault(x => x.DeviceID == id))
         {
             return device == null
                 ? null
                 : new SoundOutDevice(device.FriendlyName, device.DeviceID,
                     SoundOutType.WasApi);
         }
     }
 }
コード例 #29
0
        public void Slider()
        {
            try
            {
                using (var enumerator = new CSCore.CoreAudioAPI.MMDeviceEnumerator())
                {
                    // update volume for first start dynamic icon
                    //volume = (float)(Math.Floor((potVal / 3 * 2.395)) / 100);

                    while (true)
                    {
                        if (contVal != oldContVal)
                        {
                            // update value
                            oldContVal = contVal;
                            if (appEnd != null)
                            {
                                appEnd.Dispose();
                            }
                            appEnd = getProcessAudioEndpoint(enumerator);
                            // notify editing volume on another app
                            if (settings.notifyApp)
                            {
                                nanoSliderTray.appVolume(getApp());
                            }
                        }
                        if (potVal != oldPotVal && (potVal > oldPotVal + 1 || potVal < oldPotVal - 1)) // prevents ghost slides
                        {
                            oldPotVal = potVal;
                            volume    = (float)(Math.Floor((potVal / 3 * 2.395)) / 100);
                            nanoSliderTray.DynamicIcon(volume);

                            if (contVal == defaultOutputSink)
                            {
                                ChangeOutputVolume(volume, enumerator);
                            }
                            else if (contVal == defaultInputSink)
                            {
                                ChangeInputVolume(volume, enumerator);
                            }
                            else
                            {
                                ChangeAppVolume(volume);
                            }
                        }
                        if (nanoID == -1)
                        {
                            // if nano undetected poll slower
                            NanoFind();
                            Thread.Sleep(1000);
                        }
                        else
                        {
                            NanoFind();
                            Thread.Sleep(100);
                        }
                    }
                }
            }
            catch (Exception k)
            {
                Console.WriteLine(k);
            }
        }
コード例 #30
0
        private void UpdateDefaultAudioDevice()
        {
            MMDevice defaultAudioEndpoint;
            using (var enumerator = new MMDeviceEnumerator())
            {
                defaultAudioEndpoint = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
            }

            foreach (var soundOutMode in SoundOutModes)
            {
                foreach (var soundOutDevice in soundOutMode.Devices)
                    soundOutDevice.IsDefault = false;

                var newDefaultDevice = soundOutMode.Devices.FirstOrDefault(x => x.Id == defaultAudioEndpoint.DeviceID);
                if (newDefaultDevice != null)
                    newDefaultDevice.IsDefault = true;
            }
        }
コード例 #31
0
 private CSCore.CoreAudioAPI.AudioSessionManager2 GetDefaultAudioSessionManager2(CSCore.CoreAudioAPI.MMDeviceEnumerator enumerator, CSCore.CoreAudioAPI.DataFlow dataFlow)
 {
     using (var device = enumerator.GetDefaultAudioEndpoint(dataFlow, CSCore.CoreAudioAPI.Role.Multimedia))
     {
         var sessionManager = CSCore.CoreAudioAPI.AudioSessionManager2.FromMMDevice(device);
         return(sessionManager);
     }
 }
コード例 #32
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MMNotificationClient"/> class.
 /// </summary>
 public MMNotificationClient()
 {
     _deviceEnumerator = new MMDeviceEnumerator();
     Initialize(_deviceEnumerator);
 }
コード例 #33
0
ファイル: PolySong.cs プロジェクト: Mistrator/polybeat
 private void ChooseSoundDevice()
 {
     using (MMDeviceEnumerator enumerator = new MMDeviceEnumerator())
     {
         if (soundOut is WasapiOut)
         {
             ((WasapiOut)soundOut).Device = enumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active)[0];
         }
         else
         {
             ((DirectSoundOut)soundOut).Device = DirectSoundDeviceEnumerator.EnumerateDevices().First().Guid;
         }
     }
 }
コード例 #34
0
 private AudioSessionManager2 GetDefaultAudioSessionManager2(DataFlow dataFlow)
 {
     using (var enumerator = new MMDeviceEnumerator())
     {
         using (var device = enumerator.GetDefaultAudioEndpoint(dataFlow, Role.Multimedia))
         {
             Debug.WriteLine("DefaultDevice: " + device.FriendlyName);
             var sessionManager = AudioSessionManager2.FromMMDevice(device);
             return sessionManager;
         }
     }
 }
コード例 #35
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MMNotificationClient"/> class.
 /// </summary>
 public MMNotificationClient()
 {
     _deviceEnumerator = new MMDeviceEnumerator();
     Initialize(_deviceEnumerator);
 }
コード例 #36
-12
 public static List<MMDevice> GetSoundDevices()
 {
     List<MMDevice> devices = new List<MMDevice>();
     using (var mmdeviceEnumerator = new MMDeviceEnumerator())
     {
         using (var mmdeviceCollection = mmdeviceEnumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active))
         {
             foreach (var device in mmdeviceCollection)
             {
                 devices.Add(device);
             }
         }
     }
     return devices;
 }