-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
71 lines (48 loc) · 2.04 KB
/
main.cpp
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
// main.cpp
#include "pch.h"
#include "./libs/json/single_include/nlohmann/json.hpp"
using namespace winrt;
using namespace Windows::Media::Playback;
using namespace Windows::Foundation;
using namespace Windows::Media::Control;
int getSecondsFromTimeSpan(TimeSpan timeInput)
{
std::chrono::seconds seconds = std::chrono::duration_cast<std::chrono::seconds>(timeInput);
return static_cast<int>(seconds.count());
}
int main()
{
nlohmann::json data;
init_apartment();
GlobalSystemMediaTransportControlsSessionManager sessionManager = GlobalSystemMediaTransportControlsSessionManager::RequestAsync().get();
if (sessionManager)
{
GlobalSystemMediaTransportControlsSession session = sessionManager.GetCurrentSession();
if (session)
{
auto mediaProperties = session.TryGetMediaPropertiesAsync().get();
if (mediaProperties)
{
hstring title = mediaProperties.Title();
hstring artist = mediaProperties.Artist();
hstring album = mediaProperties.AlbumTitle();
data["title"] = title.c_str();
data["artist"] = artist.c_str();
data["album"] = album.c_str();
}
GlobalSystemMediaTransportControlsSessionPlaybackInfo playbackInfo = session.GetPlaybackInfo();
if (playbackInfo.PlaybackStatus() == GlobalSystemMediaTransportControlsSessionPlaybackStatus::Playing)
{
GlobalSystemMediaTransportControlsSessionTimelineProperties timelineInfo = session.GetTimelineProperties();
// Get the playback position
TimeSpan currentPosition = timelineInfo.Position();
TimeSpan trackLength = timelineInfo.MaxSeekTime();
data["currentPosition"] = getSecondsFromTimeSpan(currentPosition);
data["trackLength"] = getSecondsFromTimeSpan(trackLength);
}
}
}
std::string jsonString = data.dump();
std::cout << jsonString << std::endl;
return 0;
}