#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)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
相關(guān)閱讀更多精彩內(nèi)容
- 面對(duì)有意為難你的人,不要退縮,要勇敢面對(duì)。 一次校會(huì),主持人大喊:“下面有請(qǐng)成績(jī)最差的學(xué)生家長(zhǎng)上臺(tái)講話。” 一位男...
- 《企業(yè)文明》 國(guó)家級(jí)知網(wǎng)月刊 ISSN:1006-5989 CN:50-1014/G2 【收稿方向】企業(yè)管理、經(jīng)濟(jì)...
- 從今天開(kāi)始,你將涅槃重生,逆風(fēng)翻盤,這局是必勝局,你將會(huì)有越來(lái)越多的錢,越來(lái)越多的財(cái)富。你將有無(wú)限可能。 從今天開(kāi)...
- 國(guó)慶節(jié)的夜晚與平時(shí)的夜晚并無(wú)什么特別的不同。路燈照射下明亮的街面,來(lái)來(lái)往往的車輛,行色匆匆的人流……。偶然的念起:...
- 這幾天看《易經(jīng)的奧秘》 曾仕強(qiáng)老師的 744也在看,他看2,我看1。 今天起來(lái)有氣數(shù)不夠的感覺(jué)。 少說(shuō)話,不動(dòng)氣。...