forked from SpriteOvO/AirPodsDesktop
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGlobalMedia_win.h
More file actions
89 lines (73 loc) · 2.47 KB
/
GlobalMedia_win.h
File metadata and controls
89 lines (73 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//
// AirPodsWindows - AirPods Desktop User Experience Enhancement Program.
// Copyright (C) 2021-2022 SpriteOvO
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
#pragma once
#if !defined APD_OS_WIN
#error "This file shouldn't be compiled."
#endif
#include <Windows.h>
#include <mmdeviceapi.h>
#include <audiopolicy.h>
#include <endpointvolume.h>
#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/Windows.Media.Control.h>
#include <mutex>
#include <string>
#include <vector>
#include <memory>
#include <functional>
#include "GlobalMedia_abstract.h"
#include "OS/Windows.h"
namespace Core::GlobalMedia {
namespace Details {
enum class ActionId : uint32_t { Play, Pause };
class MediaProgramAbstract
{
public:
enum class Priority : uint32_t {
Max = 0,
SystemSession = 1,
MusicPlayer = 2,
Min = std::numeric_limits<uint32_t>::max()
};
virtual inline ~MediaProgramAbstract(){};
virtual bool IsAvailable() = 0;
virtual bool IsPlaying() const = 0;
virtual bool Play() = 0;
virtual bool Pause() = 0;
virtual std::wstring GetProgramName() const = 0;
virtual Priority GetPriority() const = 0;
};
} // namespace Details
class Controller final : public Helper::Singleton<Controller>, public Details::ControllerAbstract
{
protected:
Controller() = default;
friend Helper::Singleton<Controller>;
public:
void Play() override;
void Pause() override;
void SetVolume(int percent);
int GetVolume() const;
void ClearVolumeReductionState(); // Explicitly clear saved volume state
private:
std::mutex _mutex;
std::vector<std::unique_ptr<Details::MediaProgramAbstract>> _pausedPrograms;
int _savedVolume{0}; // Saved volume before reduction; 0 means no active reduction
bool _inReductionSession{false}; // Track if we're currently in a volume reduction session
};
} // namespace Core::GlobalMedia