Created
May 11, 2019 20:20
-
-
Save jambonmcyeah/9f6a3e59373882132beb643b9c802e21 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma comment(lib, "RuntimeObject.lib") | |
#include <windows.h> | |
#include <wrl/client.h> | |
#include <wrl/event.h> | |
#include <wrl/wrappers/corewrappers.h> | |
#include <wrl/implements.h> | |
#include <windows.media.control.h> | |
#include <iostream> | |
using namespace Microsoft::WRL; | |
using namespace Microsoft::WRL::Wrappers; | |
using namespace ABI::Windows::Foundation; | |
using namespace ABI::Windows::Media::Control; | |
using namespace ABI::Windows::Foundation::Collections; | |
using namespace Windows::Foundation; | |
#define RETURN_IF_FAILED(hr) { HRESULT _hrTemp = hr; if (FAILED(_hrTemp)) { return _hrTemp; } } | |
#define RIF(hr) RETURN_IF_FAILED(hr) | |
int main(int argc, char const *argv[]) | |
{ | |
CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); | |
RoInitializeWrapper initialized(RO_INIT_MULTITHREADED); | |
ComPtr<IGlobalSystemMediaTransportControlsSessionManager> global_media_manager; | |
RoGetActivationFactory(HStringReference(RuntimeClass_Windows_Media_Control_GlobalSystemMediaTransportControlsSessionManager).Get(), IID_INS_ARGS(&global_media_manager)); | |
ComPtr<IVectorView<GlobalSystemMediaTransportControlsSession*>> sessions; | |
global_media_manager->GetSessions(&sessions); | |
unsigned int sessions_size; | |
sessions->get_Size(&sessions_size); | |
for (unsigned int i = 0; i < sessions_size; i++) | |
{ | |
ComPtr<IGlobalSystemMediaTransportControlsSession> session; | |
sessions->GetAt(i, &session); | |
ComPtr<IAsyncOperation<bool>> success; | |
session->TryPlayAsync(&success); | |
success->get_Completed( | |
&Callback< | |
Implements< | |
RuntimeClassFlags<ClassicCom>, | |
IAsyncOperationCompletedHandler<bool> | |
> | |
>( | |
[](IAsyncOperation<bool>* result, AsyncStatus status) -> HRESULT{ | |
if (status == AsyncStatus::Completed) | |
{ | |
boolean completed; | |
RIF(result->GetResults(&completed)); | |
std::cout << completed; | |
} | |
return S_OK; | |
} | |
) | |
); | |
} | |
EventRegistrationToken token; | |
global_media_manager->add_SessionsChanged( | |
Callback< | |
Implements< | |
RuntimeClassFlags<ClassicCom>, | |
ITypedEventHandler<GlobalSystemMediaTransportControlsSessionManager*, SessionsChangedEventArgs*> | |
> | |
>( | |
[](IGlobalSystemMediaTransportControlsSessionManager *manager, ISessionsChangedEventArgs* args) -> HRESULT | |
{ | |
std::cout << manager << args; | |
return S_OK; | |
} | |
).Get(), &token | |
); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment