|
@@ -23,8 +23,9 @@ import { fileUri } from '@kit.CoreFileKit';
|
|
|
import { VideoItem } from '../viewmodel/VideoItem';
|
|
import { VideoItem } from '../viewmodel/VideoItem';
|
|
|
import { RemoteDriveManager } from '../common/util/RemoteDriveManager';
|
|
import { RemoteDriveManager } from '../common/util/RemoteDriveManager';
|
|
|
import { RemoteCacheManager } from '../common/network/RemoteCacheManager';
|
|
import { RemoteCacheManager } from '../common/network/RemoteCacheManager';
|
|
|
-import { RemoteCacheType } from '../common/network/RemoteSongCache';
|
|
|
|
|
|
|
+import { RemoteCacheType, resolveCacheFilePath } from '../common/network/RemoteSongCache';
|
|
|
import { extractFtpRelativePath, extractSmbRelativePath, isFtpType, isSmbType } from '../common/util/RemotePlayerUtil';
|
|
import { extractFtpRelativePath, extractSmbRelativePath, isFtpType, isSmbType } from '../common/util/RemotePlayerUtil';
|
|
|
|
|
+import FileManager from '../common/util/FileManager';
|
|
|
|
|
|
|
|
const TAG = 'heanup CastController';
|
|
const TAG = 'heanup CastController';
|
|
|
|
|
|
|
@@ -174,10 +175,12 @@ export class CastController {
|
|
|
if (isSmbType(songItem.type)) {
|
|
if (isSmbType(songItem.type)) {
|
|
|
const relative = extractSmbRelativePath(songItem, account.smbShare);
|
|
const relative = extractSmbRelativePath(songItem, account.smbShare);
|
|
|
if (relative) {
|
|
if (relative) {
|
|
|
- localCachePath = await RemoteCacheManager.ensureCached(RemoteCacheType.SMB, {
|
|
|
|
|
- account,
|
|
|
|
|
- remotePath: relative
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ const cacheInfo = await resolveCacheFilePath(
|
|
|
|
|
+ RemoteCacheType.SMB,
|
|
|
|
|
+ account.id?.toString(),
|
|
|
|
|
+ relative
|
|
|
|
|
+ );
|
|
|
|
|
+ localCachePath = await this.waitForCachePathReady(cacheInfo.cachePath);
|
|
|
}
|
|
}
|
|
|
} else if (isFtpType(songItem.type)) {
|
|
} else if (isFtpType(songItem.type)) {
|
|
|
const relative = extractFtpRelativePath(songItem);
|
|
const relative = extractFtpRelativePath(songItem);
|
|
@@ -285,6 +288,30 @@ export class CastController {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private async waitForCachePathReady(cachePath: string): Promise<string | undefined> {
|
|
|
|
|
+ if (!cachePath) {
|
|
|
|
|
+ return undefined;
|
|
|
|
|
+ }
|
|
|
|
|
+ const exists = await FileManager.isExist(cachePath);
|
|
|
|
|
+ if (exists) {
|
|
|
|
|
+ const size = await FileManager.getFileSize(cachePath);
|
|
|
|
|
+ if (size > 0) {
|
|
|
|
|
+ return cachePath;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ const maxAttempts = 20;
|
|
|
|
|
+ for (let i = 0; i < maxAttempts; i++) {
|
|
|
|
|
+ await new Promise<void>((resolve) => setTimeout(resolve, 100));
|
|
|
|
|
+ if (await FileManager.isExist(cachePath)) {
|
|
|
|
|
+ const size = await FileManager.getFileSize(cachePath);
|
|
|
|
|
+ if (size > 0) {
|
|
|
|
|
+ return cachePath;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return undefined;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 设置投播状态变化监听器
|
|
* 设置投播状态变化监听器
|
|
|
*/
|
|
*/
|