#include <windows.h>
#include <flutter/method_channel.h>
#include <flutter/plugin_registrar_windows.h>
#include <flutter/standard_method_codec.h>
#include <wmp.h>
#include <memory>
#include <string>
class VideoWindow {
public:
static void RegisterWithRegistrar(flutter::PluginRegistrarWindows *registrar);
private:
VideoWindow();
~VideoWindow();
void CreateVideoWindow(const std::string &video_url);
flutter::PluginRegistrarWindows *registrar_;
HWND hwnd_;
CComPtr<IWMPPlayer> player_;
};
void VideoWindow::RegisterWithRegistrar(flutter::PluginRegistrarWindows *registrar) {
auto channel = std::make_unique<flutter::MethodChannel<flutter::EncodableValue>>(
registrar->messenger(), "video_window_channel",
&flutter::StandardMethodCodec::GetInstance());
auto plugin = std::make_unique<VideoWindow>();
channel->SetMethodCallHandler(
[plugin_pointer = plugin.get()](const auto &call, auto result) {
if (call.method_name().compare("createVideoWindow") == 0) {
const auto *arguments = std::get_if<flutter::EncodableMap>(call.arguments());
if (arguments) {
auto video_url_it = arguments->find(flutter::EncodableValue("videoUrl"));
if (video_url_it != arguments->end()) {
std::string video_url = std::get<std::string>(video_url_it->second);
plugin_pointer->CreateVideoWindow(video_url);
result->Success();
return;
}
}
result->Error("Invalid arguments", "Expected videoUrl");
} else {
result->NotImplemented();
}
});
registrar->AddPlugin(std::move(plugin));
}
VideoWindow::VideoWindow() : registrar_(nullptr), hwnd_(nullptr) {}
VideoWindow::~VideoWindow() {
if (player_) {
player_->close();
}
}
void VideoWindow::CreateVideoWindow(const std::string &video_url) {
if (!hwnd_) {
hwnd_ = CreateWindowEx(0, L"STATIC", L"Video Player", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, nullptr, nullptr,
GetModuleHandle(nullptr), nullptr);
ShowWindow(hwnd_, SW_SHOW);
}
if (!player_) {
CoInitialize(nullptr);
player_.CoCreateInstance(CLSID_WindowsMediaPlayer, nullptr, CLSCTX_INPROC_SERVER);
CComPtr<IWMPPlayer4> player4;
player_.QueryInterface(&player4);
player4->put_uiMode(CComBSTR(L"none"));
player4->put_windowlessVideo(VARIANT_TRUE);
player4->put_stretchToFit(VARIANT_TRUE);
player4->put_URL(CComBSTR(video_url.c_str()));
player4->put_windowlessVideo(VARIANT_TRUE);
player4->put_stretchToFit(VARIANT_TRUE);
player4->put_windowlessVideoParent(hwnd_);
}
player_->controls->play();
}
2024-10-08
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 《企业文明》 国家级知网月刊 ISSN:1006-5989 CN:50-1014/G2 【收稿方向】企业管理、经济...