Skip to content

基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。

better windows external implements

Predidit4f6d9accd925
diff --git a/lib/utils/remote.dart b/lib/utils/remote.dart
index f11e16f1..afbd5a89 100644
--- a/lib/utils/remote.dart
+++ b/lib/utils/remote.dart
@@ -17,11 +17,6 @@ class RemotePlay {
// 而对于 iOS / Mac 设备,由于没有设备,无法进行开发与验证。
// 可行的 iOS / Mac 处理代码,请参见 ios/Runner/AppDelegate.swift 的注释部分。
- // 2024/09/28
- // Windows 外部播放器调用方法更新。
- // 主要问题在于 win32 API 中 shellExecuteEx 需要在网络资源全部缓存到本地后才能进行操作。这导致及其缓慢的启动时间。
- // 这已经是我目前可以找到的最通用的方法,基于 cli 的方法缺乏通用性,不是我们想要的。
-
static const platform = MethodChannel('com.predidit.kazumi/intent');
castVideo(BuildContext context) async {
diff --git a/windows/runner/external_player_utils.cpp b/windows/runner/external_player_utils.cpp
index 06cbaa12..510df60a 100644
--- a/windows/runner/external_player_utils.cpp
+++ b/windows/runner/external_player_utils.cpp
@@ -10,23 +10,46 @@
#include <cstdio>
#include <string>
#include <iostream>
+#include <fstream>
+#include <random>
#include "external_player_utils.h"
void ExternalPlayerUtils::OpenWithPlayer(const char* url) {
- // Convert the URL from char* to wchar_t*
- int urlLength = MultiByteToWideChar(CP_ACP, 0, url, -1, NULL, 0);
- wchar_t* wideUrl = new wchar_t[urlLength];
- MultiByteToWideChar(CP_ACP, 0, url, -1, wideUrl, urlLength);
+ // temp file path
+ wchar_t tempPath[MAX_PATH];
+ GetTempPathW(MAX_PATH, tempPath);
+
+ // Generate a random file name
+ std::wstring randomFileName = L"kazumi_stream_";
+ std::random_device rd;
+ std::mt19937 eng(rd());
+ std::uniform_int_distribution<> distr(10000000, 99999999);
+
+ randomFileName += std::to_wstring(distr(eng)) + L".m3u8";
+
+ wchar_t tempFile[MAX_PATH];
+ wcscpy_s(tempFile, tempPath);
+ wcscat_s(tempFile, randomFileName.c_str());
+
+ // write the URL to the temp file
+ std::wofstream outFile(tempFile);
+ if (outFile.is_open()) {
+ outFile << L"#EXTM3U\n";
+ outFile << std::wstring(url, url + strlen(url));
+ outFile.close();
+ } else {
+ return;
+ }
SHELLEXECUTEINFO execInfo = {0};
execInfo.cbSize = sizeof(SHELLEXECUTEINFO);
execInfo.fMask = SEE_MASK_CLASSNAME;
execInfo.lpVerb = L"open";
- execInfo.lpFile = wideUrl;
+ execInfo.lpFile = tempFile;
execInfo.lpClass = L".m3u8";
execInfo.nShow = SW_SHOWNORMAL;
ShellExecuteEx(&execInfo);
- delete[] wideUrl;
+ // DeleteFileW(tempFile);
}
\ No newline at end of file