/// <summary>
        /// フェードアウトを実行するタスク
        /// </summary>
        private void FadeOutThread()
        {
            //自分自身のプロセスを取得する
            System.Diagnostics.Process p = System.Diagnostics.Process.GetCurrentProcess();
            int pid = p.Id;

            MMDevice device = null;

            try
            {
                using (MMDeviceEnumerator DevEnum = new MMDeviceEnumerator())
                {
                    device = DevEnum.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia);
                }
                AudioSessionManager sessionManager = device.AudioSessionManager;
                for (float i = 100; i >= 0; i -= 1f)
                {
                    foreach (var item in sessionManager.Sessions)
                    {
                        if (item.ProcessID != (uint)pid)
                        {
                            item.SimpleAudioVolume.MasterVolume = (i / 100.0f);
                        }
                    }
                    Thread.Sleep(100);
                }
            }
            finally
            {
                if (device != null)
                {
                    device.Dispose();
                }
            }
        }
Exemple #2
0
        public void UnmuteSpotify()
        {
            using (MMDeviceEnumerator mde = new MMDeviceEnumerator())
            {
                using (MMDevice device = mde.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia))
                {
                    AudioSessionManager asm = device.AudioSessionManager;
                    SessionCollection   sc  = asm.Sessions;

                    for (int i = 0; i < sc.Count; i++)
                    {
                        string name = sc[i].GetSessionIdentifier;
                        if (name.IndexOf("spotify.exe", StringComparison.OrdinalIgnoreCase) != -1)
                        {
                            if (sc[i].SimpleAudioVolume.Mute)
                            {
                                sc[i].SimpleAudioVolume.Mute = false;
                            }

                            _previousLevel = sc[i].SimpleAudioVolume.Volume;
                            sc[i].SimpleAudioVolume.Volume = _previousLevel == -1 ? 1.0f : _previousLevel;
                            break;
                        }
                    }
                }
            }
        }
        /// <summary>
        /// 开启程序时就执行
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form1_Load(object sender, EventArgs e)
        {
            //初始化设备
            MMDeviceEnumerator devEnum = new MMDeviceEnumerator();

            device = devEnum.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia);

            //label1.Text = "当前音量:" + Convert.ToInt32(device.AudioEndpointVolume.MasterVolumeLevelScalar * 100.0f);


            //获取所有程序声音的管理器
            audioSessionManager = device.AudioSessionManager;
            sessions            = audioSessionManager.Sessions;

            //显示所有程序的SessionIdentifier
            label1.Text = "当前应用音量的个数" + audioSessionManager.Sessions.Count +
                          "。当前所有音频程序的SessionIdentifier:\n";
            for (int i = 0; i < audioSessionManager.Sessions.Count; i++)
            {
                AudioSessionControl app = sessions[i];
                string sIdentifier      = app.SessionIdentifier;
                label1.Text += app.SessionIdentifier + "\n";
            }


            Thread a = new Thread(CheckTxT);

            a.IsBackground = true;
            a.Start();
            //CheckTxT();
        }
Exemple #4
0
 public void Refresh()
 {
     deviceEnumerator = new MMDeviceEnumerator();
     try
     {
         render = deviceEnumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
         renderAudioSessionManager = render.AudioSessionManager;
         renderSessions            = renderAudioSessionManager.Sessions;
     }
     catch
     {
         // no available speaker device
     }
     try
     {
         capture = deviceEnumerator.GetDefaultAudioEndpoint(DataFlow.Capture, Role.Multimedia);
         captureAudioSessionManager = capture.AudioSessionManager;
         captureSessions            = captureAudioSessionManager.Sessions;
     }
     catch
     {
         // no available recording device
     }
     deviceEnumerator.Dispose();
 }
Exemple #5
0
        /// <summary>
        /// ウマ娘ウィンドウの音量が0になって再び0以上になるまで待機します。
        /// </summary>
        /// <param name="timeOutMillisecond">タイムアウト時間ミリ秒</param>
        private void WaitUmaWindowAvailable(Process process, int timeOutMillisecond)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            MMDevice device = null;

            try
            {
                //ウマ娘セッションの検索
                AudioSessionControl umamusumeSession = null;
                while (umamusumeSession == null)
                {
                    using (MMDeviceEnumerator DevEnum = new MMDeviceEnumerator())
                    {
                        device?.Dispose();
                        device = DevEnum.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
                    }
                    AudioSessionManager sessionManager = device.AudioSessionManager;
                    var sessions = sessionManager.Sessions;
                    for (int j = 0; j < sessions.Count; j++)
                    {
                        if (sessions[j].GetProcessID == process.Id)
                        {
                            umamusumeSession = sessions[j];
                            break;
                        }
                    }
                }

                //0になるまで待機(0以外の間ループ)
                while (umamusumeSession.AudioMeterInformation.MasterPeakValue > 0.005)
                {
                    Thread.Sleep(10);
                    if (stopwatch.ElapsedMilliseconds > timeOutMillisecond)
                    {
                        return;
                    }
                }

                //0以上になるまで待機(0の間ループ)
                while (umamusumeSession.AudioMeterInformation.MasterPeakValue < 0.1)
                {
                    Thread.Sleep(10);
                    if (stopwatch.ElapsedMilliseconds > timeOutMillisecond)
                    {
                        return;
                    }
                }
            }
            finally
            {
                if (device != null)
                {
                    device.Dispose();
                }
            }
        }
Exemple #6
0
        public Game()
        {
            AudioSessionManager.Setup();
            UIApplication.SharedApplication.StatusBarHidden = true;

            // TODO: What is the correct startup state for Window?
            this.Window = new GameWindow();
            var bounds = UIScreen.MainScreen.Bounds;

            Window.DoClientSizeChange(new Rectangle(0, 0, (int)bounds.Width, (int)bounds.Height));

            this.Content = new ContentManager(services);
        }
Exemple #7
0
 public Sound()
 {
     RecordingSourceProcessName = "";
     AudioSessions = new List <AudioSession>();
     aMMDevices    = new MMDeviceEnumerator();
     DefaultAudioEndPointDevice = aMMDevices.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
     DefaultAudioEndPointDevice.AudioEndpointVolume.OnVolumeNotification += AudioEndpointVolumeDelegate;
     oSessionDefaultAudioEndPointDevice   = DefaultAudioEndPointDevice.AudioSessionManager;
     coSessionsDefaultAudioEndPointDevice = oSessionDefaultAudioEndPointDevice.Sessions;
     oSessionDefaultAudioEndPointDevice.OnSessionCreated += AudioSessionCreatedDelegate;
     DefaultAudioDeviceVolume = (int)(DefaultAudioEndPointDevice.AudioEndpointVolume.MasterVolumeLevelScalar * 100);
     LoadAudioSessions();
 }
Exemple #8
0
        //private List<Session> SS = new List<Session>();
        private void GetSs()
        {
            DW(2000);
            if (ASM == null && L.MMD != null)
            {
                ASM = L.MMD.AudioSessionManager;
            }
            ASM.OnSessionCreated += ASM_OnSessionCreated;;

            for (int i = 0; i < ASM.Sessions.Count; i++)
            {
                AddNewSession((IAudioSessionControl)ASM.Sessions[i]);
            }
        }
        static void Main(string[] args)
        {
            //自分自身のプロセスを取得する
            System.Diagnostics.Process p = System.Diagnostics.Process.GetCurrentProcess();
            int pid = p.Id;

            MMDevice device = null;

            try
            {
                using (MMDeviceEnumerator DevEnum = new MMDeviceEnumerator())
                {
                    device = DevEnum.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia);
                }
                float MasterVolumeLevel            = device.AudioEndpointVolume.MasterVolumeLevelScalar;
                AudioSessionManager sessionManager = device.AudioSessionManager;
                for (float i = 100; i >= 0; i -= 1f)
                {
                    foreach (var item in sessionManager.Sessions)
                    {
                        if (item.ProcessID != (uint)pid)
                        {
                            item.SimpleAudioVolume.MasterVolume = ((float)i / 100.0f);
                        }
                    }
                    System.Threading.Thread.Sleep(50);
                }
                //元の音量に戻す
                foreach (var item in sessionManager.Sessions)
                {
                    if (item.ProcessID != (uint)pid)
                    {
                        item.SimpleAudioVolume.MasterVolume = ((float)100 / 100.0f);
                    }
                }
                device.AudioEndpointVolume.MasterVolumeLevelScalar = MasterVolumeLevel;
            }
            finally
            {
                //後処理
                if (device != null)
                {
                    device.Dispose();
                }
            }
        }
        static VolumeChannel()
        {
            _device = _enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Console);

            _sessManager = _device.AudioSessionManager;

            //sessManager.AudioSessionControl.RegisterEventClient(this);
            _sessManager.OnSessionCreated += new AudioSessionManager.SessionCreatedDelegate(OnSessionCreated);

            for (int i = 0; i < 10; i++)
            {
                ledThresholds[i]   = (float)(Math.Pow(1.2, i - 10));
                timesToLowerPip[i] = (150 - (9 - i) * (9 - i)) / 5;
                if (i > 0 && timesToLowerPip[i] <= timesToLowerPip[i - 1])
                {
                    timesToLowerPip[i] = timesToLowerPip[i - 1] + 1;
                }
            }
            ledThresholds[0] = 0;
        }
        static void Main(string[] args)
        {
            MMDevice device = null;

            try
            {
                //ウマ娘セッションの検索
                using (MMDeviceEnumerator DevEnum = new MMDeviceEnumerator())
                {
                    device = DevEnum.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
                }
                //master情報
                Console.WriteLine("FriendlyName:" + device.FriendlyName);
                Console.WriteLine("DeviceFriendlyName:" + device.DeviceFriendlyName);
                Console.WriteLine("IconPathRaw:" + Environment.ExpandEnvironmentVariables(device.IconPath));

                //アイコンパス文字列の取得
                string[] iconPathSplited = device.IconPath.Split(',');
                if (iconPathSplited.Length >= 2)
                {
                    string expandPath = Environment.ExpandEnvironmentVariables(iconPathSplited.First());
                    int    IDraw      = int.Parse(iconPathSplited.Last());
                    uint   ID         = (uint)Math.Abs(IDraw);
                    Console.WriteLine("IconPath:" + GetStringFromDll(expandPath, ID));
                    int err = Marshal.GetLastWin32Error();
                }

                Console.WriteLine("");

                AudioSessionManager sessionManager = device.AudioSessionManager;
                var sessions = sessionManager.Sessions;
                for (int j = 0; j < sessions.Count; j++)
                {
                    if (string.IsNullOrEmpty(sessions[j].DisplayName))
                    {
                        AudioSessionControl aaa = sessions[j];
                        continue;
                    }
                    if (sessions[j].DisplayName.First() == '@')
                    {
                        string[] displayNameSplited = sessions[j].DisplayName.Split(',');
                        string   expandPath         = Environment.ExpandEnvironmentVariables(displayNameSplited.First().Substring(1));
                        int      IDraw = int.Parse(displayNameSplited.Last());
                        uint     ID    = (uint)Math.Abs(IDraw);
                        Console.WriteLine("DisplayName:" + GetStringFromDll(expandPath, ID));
                        int err = Marshal.GetLastWin32Error();
                    }
                    else
                    {
                        Console.WriteLine("DisplayName:" + sessions[j].DisplayName);
                    }

                    Console.WriteLine("IconPath:" + sessions[j].IconPath);
                    Console.WriteLine("");
                }
            }
            finally
            {
                if (device != null)
                {
                    device.Dispose();
                }
            }

            Console.Read();
        }