|
|
@@ -11716,46 +11716,39 @@ export struct LocalMusic {
|
|
|
|
|
|
//设置视频源
|
|
|
this.mIjkMediaPlayer.setDataSource(url);
|
|
|
- //设置视频源http请求头
|
|
|
- let headers = new Map([
|
|
|
- ["user_agent", "Mozilla/5.0 BiliDroid/7.30.0 (ttmusic)"],
|
|
|
- ["referer", "https://www.bilibili.com"]
|
|
|
- ]);
|
|
|
+ // 构建规范的HTTP请求头(统一一次性设置,避免未带认证提前发起连接)
|
|
|
+ const headers = new Map<string, string>();
|
|
|
+ headers.set("User-Agent", "TTMusic-WebDAV/1.0");
|
|
|
+ headers.set("Accept", "*/*");
|
|
|
+ headers.set("Range", "bytes=0-");
|
|
|
if (this.currentSong&&StrUtil.isEmpty(this.currentSong.pixelMapPath)
|
|
|
&&PreferencesUtil.getStringSync('COVER_API', '') != '') {
|
|
|
//如果封面为空,则搜索封面
|
|
|
this.searchCover(this.currentSong, this.currentSong.name, this.currentSong.artist||'')
|
|
|
}
|
|
|
|
|
|
- // 如果是WebDAV网络音频,使用webdav_account_id获取认证信息
|
|
|
- if (this.currentSong&&this.currentSong.type === CommonConstants.TYPE_WEBDAV) {
|
|
|
+ // 如果是WebDAV网络音频,使用webdav_account_id获取认证信息(等待完成后再设置一次性头部)
|
|
|
+ if (this.currentSong && this.currentSong.type === CommonConstants.TYPE_WEBDAV) {
|
|
|
Logger.info(`heanup WebDAV歌曲认证 - 歌曲名: ${this.currentSong.name}, webdav_account_id: ${this.currentSong.webdav_account_id || '未设置'}`);
|
|
|
-
|
|
|
- // 使用webdav_account_id查询认证信息
|
|
|
if (this.currentSong.webdav_account_id) {
|
|
|
- const webdavManager = WebdavManager.getInstance();
|
|
|
- webdavManager.buildHttpHeadersWithAccountId(this.currentSong, this.videoUrl)
|
|
|
- .then(webDavHeaders => {
|
|
|
- if (webDavHeaders && webDavHeaders.size > 0) {
|
|
|
- // 合并WebDAV认证头到基础请求头
|
|
|
- webDavHeaders.forEach((value, key) => {
|
|
|
- headers.set(key, value);
|
|
|
- });
|
|
|
- Logger.info(`heanup 成功通过webdav_account_id获取并设置WebDAV认证头`);
|
|
|
- // 重新设置带认证的请求头
|
|
|
- this.mIjkMediaPlayer.setDataSourceHeader(headers);
|
|
|
- } else {
|
|
|
- Logger.warn(`heanup 通过webdav_account_id获取认证头失败,播放可能无法继续`);
|
|
|
- }
|
|
|
- })
|
|
|
- .catch((error: Error) => {
|
|
|
- Logger.error(`heanup 获取WebDAV认证头时出错: ${error.message}`);
|
|
|
- });
|
|
|
+ try {
|
|
|
+ const webdavManager = WebdavManager.getInstance();
|
|
|
+ const webDavHeaders = await webdavManager.buildHttpHeadersWithAccountId(this.currentSong, this.videoUrl);
|
|
|
+ if (webDavHeaders && webDavHeaders.size > 0) {
|
|
|
+ webDavHeaders.forEach((value, key) => headers.set(key, value));
|
|
|
+ Logger.info(`heanup 成功通过webdav_account_id获取并合并WebDAV认证头`);
|
|
|
+ } else {
|
|
|
+ Logger.warn(`heanup 通过webdav_account_id获取认证头失败,播放可能无法继续`);
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ const err = error as Error;
|
|
|
+ Logger.error(`heanup 获取WebDAV认证头时出错: ${err.message}`);
|
|
|
+ }
|
|
|
} else {
|
|
|
Logger.error(`heanup WebDAV歌曲 "${this.currentSong.name}" 缺少webdav_account_id,无法进行认证`);
|
|
|
- Logger.error(`heanup 请重新扫描WebDAV账户以修复此问题`);
|
|
|
}
|
|
|
}
|
|
|
+ // 统一设置带认证的请求头
|
|
|
this.mIjkMediaPlayer.setDataSourceHeader(headers);
|
|
|
if (this.currentSong&&this.currentSong.type === CommonConstants.TYPE_WEBDAV) {
|
|
|
console.log(`heanup 为WebDAV播放设置IjkPlayer选项`);
|
|
|
@@ -13695,4 +13688,4 @@ async function scanCurrentDirectoryTask(context: Context, dirPath: string, lockP
|
|
|
} catch (error) {
|
|
|
console.error(' 扫描当前目录失败:', error);
|
|
|
}
|
|
|
-}
|
|
|
+}
|