#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
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進店門推励,熙熙樓的掌柜王于貴愁眉苦臉地迎上來肉迫,“玉大人,你說我怎么就攤上這事喊衫。” “怎么了壳贪?”我有些...
- 文/不壞的土叔 我叫張陵寝杖,是天一觀的道長。 經(jīng)常有香客問我瑟幕,道長,這世上最難降的妖魔是什么只盹? 我笑而不...
- 正文 為了忘掉前任鹿霸,我火速辦了婚禮秆乳,結(jié)果婚禮上懦鼠,老公的妹妹穿的比我還像新娘。我一直安慰自己街氢,他們只是感情好睦袖,可當(dāng)我...
- 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著馅笙,像睡著了一般。 火紅的嫁衣襯著肌膚如雪烈和。 梳的紋絲不亂的頭發(fā)上皿淋,一...
- 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼吏祸!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起蹈矮,我...
- 正文 年R本政府宣布,位于F島的核電站溉知,受9級特大地震影響腕够,放射性物質(zhì)發(fā)生泄漏级乍。R本人自食惡果不足惜帚湘,卻給世界環(huán)境...
- 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望捅厂。 院中可真熱鬧资柔,春花似錦焙贷、人聲如沸贿堰。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至契吉,卻和暖如春诡渴,著一層夾襖步出監(jiān)牢的瞬間捐晶,已是汗流浹背妄辩。 一陣腳步聲響...
推薦閱讀更多精彩內(nèi)容
- 《企業(yè)文明》 國家級知網(wǎng)月刊 ISSN:1006-5989 CN:50-1014/G2 【收稿方向】企業(yè)管理虐杯、經(jīng)濟...
- 國慶節(jié)的夜晚與平時的夜晚并無什么特別的不同丰辣。路燈照射下明亮的街面,來來往往的車輛笙什,行色匆匆的人流……。偶然的念起:...
- 這幾天看《易經(jīng)的奧秘》 曾仕強老師的 744也在看芽隆,他看2,我看1胚吁。 今天起來有氣數(shù)不夠的感覺鸿吆。 少說話囤采,不動氣惩淳。...