Exemplo n.º 1
0
        private void FillWASAPIDeviceList()
        {
            _WASAPIDevices.Clear();
            BassPlayerSettings settings = Controller.GetSettings();

            BASS_WASAPI_DEVICEINFO[] deviceDescriptions = BassWasapi.BASS_WASAPI_GetDeviceInfos();
            for (int i = 0; i < deviceDescriptions.Length; i++)
            {
                // Skip input devices, they have same name as output devices.
                BASS_WASAPI_DEVICEINFO deviceInfo = deviceDescriptions[i];
                bool skip = !WASAPIOutputDevice.IsValidDevice(deviceInfo);

                ServiceRegistration.Get <ILogger>().Debug("{5} WASAPI Device {0}: '{1}' Flags: {2} Device path: [{3}] Ch: {4}", i, deviceInfo.name, deviceInfo.flags, deviceInfo.id, deviceInfo.mixchans,
                                                          skip ? "Skip" : "Use ");
                if (skip)
                {
                    continue;
                }

                ListItem deviceItem = new ListItem(Consts.KEY_NAME, deviceInfo.name)
                {
                    Selected = deviceInfo.name == settings.WASAPIDevice
                };
                deviceItem.SelectedProperty.Attach(delegate
                {
                    var selected = _WASAPIDevices.FirstOrDefault(d => d.Selected);
                    WASAPIDevice = selected != null ? selected.Labels[Consts.KEY_NAME].ToString() : string.Empty;
                });
                deviceItem.SetLabel(KEY_GROUP, "WASAPI");
                _WASAPIDevices.Add(deviceItem);
            }
            _WASAPIDevices.FireChange();
        }
        /// <summary>
        /// Creates an IOutputDevice object based on usersettings.
        /// </summary>
        /// <returns></returns>
        public IOutputDevice CreateOutputDevice()
        {
            IOutputDevice      outputDevice;
            BassPlayerSettings settings = Controller.GetSettings();

            switch (settings.OutputMode)
            {
            case OutputMode.DirectSound:
                outputDevice = new DirectXOutputDevice(_controller);
                break;

            case OutputMode.WASAPI:
                outputDevice = new WASAPIOutputDevice(_controller);
                break;

            default:
                throw new BassPlayerException(String.Format("Unimplemented audio output mode {0}", settings.OutputMode));
            }
            return(outputDevice);
        }