2020-02-20 15:04:12 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef WIDGET_WINDOWS_WINDOWSSTMCPROVIDER_H_
|
|
|
|
#define WIDGET_WINDOWS_WINDOWSSTMCPROVIDER_H_
|
|
|
|
|
|
|
|
#ifndef __MINGW32__
|
|
|
|
|
|
|
|
# include <functional>
|
|
|
|
# include <Windows.Media.h>
|
|
|
|
# include <wrl.h>
|
|
|
|
|
|
|
|
# include "mozilla\dom\MediaController.h"
|
2020-06-09 05:59:57 +03:00
|
|
|
# include "mozilla\dom\MediaControlKeySource.h"
|
2020-02-20 15:04:12 +03:00
|
|
|
# include "mozilla\Maybe.h"
|
|
|
|
|
|
|
|
using ISMTC = ABI::Windows::Media::ISystemMediaTransportControls;
|
|
|
|
using SMTCProperty = ABI::Windows::Media::SystemMediaTransportControlsProperty;
|
2020-06-19 03:20:23 +03:00
|
|
|
using ISMTCDisplayUpdater =
|
2020-02-20 15:04:12 +03:00
|
|
|
ABI::Windows::Media::ISystemMediaTransportControlsDisplayUpdater;
|
|
|
|
|
|
|
|
struct SMTCControlAttributes {
|
|
|
|
bool mEnabled;
|
|
|
|
bool mPlayPauseEnabled;
|
|
|
|
bool mNextEnabled;
|
|
|
|
bool mPreviousEnabled;
|
|
|
|
|
|
|
|
static constexpr SMTCControlAttributes EnableAll() {
|
|
|
|
return {true, true, true, true};
|
|
|
|
}
|
|
|
|
static constexpr SMTCControlAttributes DisableAll() {
|
|
|
|
return {false, false, false, false};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-06-09 05:59:57 +03:00
|
|
|
class WindowsSMTCProvider final : public mozilla::dom::MediaControlKeySource {
|
2020-02-20 15:04:12 +03:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(WindowsSMTCProvider, override)
|
|
|
|
|
|
|
|
public:
|
|
|
|
WindowsSMTCProvider();
|
|
|
|
|
|
|
|
bool IsOpened() const override;
|
|
|
|
bool Open() override;
|
|
|
|
void Close() override;
|
|
|
|
|
|
|
|
// Sets the state of the UI Panel (enabled, can use PlayPause, Next, Previous
|
|
|
|
// Buttons)
|
|
|
|
bool SetControlAttributes(SMTCControlAttributes aAttributes);
|
|
|
|
|
2020-03-17 03:03:55 +03:00
|
|
|
void SetPlaybackState(
|
|
|
|
mozilla::dom::MediaSessionPlaybackState aState) override;
|
2020-02-20 15:04:12 +03:00
|
|
|
|
|
|
|
// Sets the Thumbnail for the currently playing media to the given URL.
|
|
|
|
// Note: This method does not call update(), you need to do that manually.
|
|
|
|
bool SetThumbnail(const wchar_t* aUrl);
|
|
|
|
|
|
|
|
// Sets the Metadata for the currently playing media and sets the playback
|
|
|
|
// type to "MUSIC" Note: This method does not call update(), you need to do
|
|
|
|
// that manually.
|
2020-06-19 03:19:48 +03:00
|
|
|
bool SetMusicMetadata(const wchar_t* aArtist, const wchar_t* aTitle,
|
|
|
|
const wchar_t* aAlbumArtist);
|
2020-02-20 15:04:12 +03:00
|
|
|
|
2020-03-17 04:23:43 +03:00
|
|
|
void SetMediaMetadata(
|
|
|
|
const mozilla::dom::MediaMetadataBase& aMetadata) override;
|
|
|
|
|
2020-06-09 05:23:35 +03:00
|
|
|
// TODO : modify the virtual control interface based on the supported keys
|
|
|
|
void SetSupportedMediaKeys(const MediaKeysArray& aSupportedKeys) override {}
|
|
|
|
|
2020-02-20 15:04:12 +03:00
|
|
|
private:
|
|
|
|
~WindowsSMTCProvider();
|
|
|
|
void UnregisterEvents();
|
|
|
|
bool RegisterEvents();
|
|
|
|
bool InitDisplayAndControls();
|
2020-06-09 05:59:57 +03:00
|
|
|
void OnButtonPressed(mozilla::dom::MediaControlKey aKey);
|
2020-02-20 15:04:12 +03:00
|
|
|
|
|
|
|
// This method flushes the changed Media Metadata to the OS.
|
|
|
|
bool Update();
|
|
|
|
|
|
|
|
bool mInitialized = false;
|
|
|
|
Microsoft::WRL::ComPtr<ISMTC> mControls;
|
2020-06-19 03:20:23 +03:00
|
|
|
Microsoft::WRL::ComPtr<ISMTCDisplayUpdater> mDisplay;
|
2020-02-20 15:04:12 +03:00
|
|
|
HWND mWindow; // handle to the invisible window
|
|
|
|
|
|
|
|
// EventRegistrationTokens are used to have a handle on a callback (to remove
|
|
|
|
// it again)
|
|
|
|
EventRegistrationToken mButtonPressedToken;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // __MINGW32__
|
|
|
|
#endif // WIDGET_WINDOWS_WINDOWSSTMCPROVIDER_H_
|