|
|
@@ -10,7 +10,7 @@ import MediaTable from '../common/util/MediaTable'
|
|
|
import { VideoItem } from '../viewmodel/VideoItem'
|
|
|
import Logger from '../common/util/Logger'
|
|
|
import { CommonConstants, STR_LOCK_VIDEO } from '../common/constants/CommonConstants'
|
|
|
-import { emitter } from '@kit.BasicServicesKit'
|
|
|
+import { BusinessError, emitter } from '@kit.BasicServicesKit'
|
|
|
import { BreakpointTypeEnum } from '../common/util/BreakpointSystem'
|
|
|
import { resourceManager } from '@kit.LocalizationKit'
|
|
|
import { common, ConfigurationConstant } from '@kit.AbilityKit'
|
|
|
@@ -21,6 +21,10 @@ import { DialogHelper } from '@pura/harmony-dialog'
|
|
|
// @Entry
|
|
|
@Component
|
|
|
export struct ScanFilePage{
|
|
|
+ // 新增状态变量
|
|
|
+ @State currentInsertCount: number = 0 // 当前已扫描并插入的歌曲数量
|
|
|
+ @State currentFilePath: string = '' // 当前正在处理的文件路径
|
|
|
+
|
|
|
context = this.getUIContext().getHostContext() as common.UIAbilityContext
|
|
|
// @StorageProp('mediaKuList') mediaKuList: Array<VideoItem> = []; //媒体库文件
|
|
|
@State rootPath:string = '' //音频根目录
|
|
|
@@ -152,15 +156,30 @@ export struct ScanFilePage{
|
|
|
this.watchStatus(true)
|
|
|
this.initState(isOnekey)
|
|
|
const task = new taskpool.Task(scanDirectoryTask, this.context, this.rootPath,
|
|
|
- this.lockPath,PreferencesUtil.getStringSync('COVER_API',''),PreferencesUtil.getBooleanSync('autoParseMusicName', true));
|
|
|
+ this.lockPath,PreferencesUtil.getStringSync('COVER_API',''),
|
|
|
+ PreferencesUtil.getBooleanSync('autoParseMusicName', true));
|
|
|
+ task.onReceiveData((path: string, count: number) => {
|
|
|
+ this.currentFilePath = path
|
|
|
+ this.currentInsertCount = count
|
|
|
+ console.info( "onecold onReceiveData path = "+path);
|
|
|
+ console.info( "onecold onReceiveData count = "+count);
|
|
|
+ })
|
|
|
taskpool.execute(task, taskpool.Priority.HIGH).then(()=>{
|
|
|
this.endScan(isOnekey)
|
|
|
+ // taskpool.terminateTask(task);
|
|
|
}).catch((e:object)=>{
|
|
|
console.info("onecold task1 catch e: " + JSON.stringify(e));
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
+ // 更新进度回调函数
|
|
|
+ private updateProgress = (path: string, count: number) => {
|
|
|
+ this.currentFilePath = path
|
|
|
+ this.currentInsertCount = count
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
build() {
|
|
|
Column() {
|
|
|
@@ -222,15 +241,25 @@ export struct ScanFilePage{
|
|
|
this.mainCanvasRenderingContext.imageSmoothingQuality = 'medium'
|
|
|
})
|
|
|
}
|
|
|
+ .margin({top:10})
|
|
|
.transition(TransitionEffect.move(TransitionEdge.END)
|
|
|
.animation({ duration: 380, curve: Curve.Ease,delay:300 }))
|
|
|
|
|
|
- Text(this.strText)
|
|
|
- .height(50)
|
|
|
+ Text(`${this.currentInsertCount}首歌`)
|
|
|
+ .height(38)
|
|
|
.fontSize(16)
|
|
|
.fontColor($r('app.color.text_color'))
|
|
|
.fontWeight(480)
|
|
|
.visibility(this.textVisi)
|
|
|
+ Text(this.currentFilePath)
|
|
|
+ .height(38)
|
|
|
+ .fontSize(12)
|
|
|
+ .maxLines(3)
|
|
|
+ .margin({bottom:6})
|
|
|
+ .width('86%')
|
|
|
+ .fontColor($r('app.color.text_color'))
|
|
|
+ .fontWeight(480)
|
|
|
+ .visibility(this.textVisi)
|
|
|
|
|
|
Button({ type: ButtonType.Capsule, stateEffect: true }) {
|
|
|
Row(){
|
|
|
@@ -369,31 +398,7 @@ export struct ScanFilePage{
|
|
|
})
|
|
|
.alignSelf(ItemAlign.Center)
|
|
|
|
|
|
- Button({ type: ButtonType.Capsule, stateEffect: true }) {
|
|
|
- Row(){
|
|
|
- SymbolGlyph($r('sys.symbol.arrow_counterclockwise'))
|
|
|
- .fontSize(19)
|
|
|
- .fontColor([Color.White])
|
|
|
- Text($r('app.string.sync_data'))
|
|
|
- .margin({ left: 4 })
|
|
|
- .fontSize(15)
|
|
|
- .fontColor(Color.White)
|
|
|
- .fontWeight(480)
|
|
|
- .textAlign(TextAlign.Center)
|
|
|
- }
|
|
|
- .justifyContent(FlexAlign.Center)
|
|
|
- }
|
|
|
- .width(150)
|
|
|
- .height(55)
|
|
|
- .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
|
|
|
- .margin({ top: 10, bottom: 10,right:10 })
|
|
|
- .backgroundColor(this.themeColor)
|
|
|
- .enabled(this.isStartSync ?false:true)
|
|
|
- .onClick(() => {
|
|
|
- this.doSyncData()
|
|
|
|
|
|
- })
|
|
|
- .alignSelf(ItemAlign.Center)
|
|
|
|
|
|
|
|
|
}
|
|
|
@@ -412,23 +417,7 @@ export struct ScanFilePage{
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- doSyncData() {
|
|
|
- // this.watchStatus(true)
|
|
|
- // this.initLottie(this.path,true)
|
|
|
- // this.isStartSync = true
|
|
|
- // this.textVisi = Visibility.Visible
|
|
|
- // this.strText = Utility.resourceToString(getContext(this),$r('app.string.sync_dataing'))
|
|
|
- // lottie.play()
|
|
|
- // // 仅提取 filePath 列表
|
|
|
- // const filePaths = this.mediaKuList.map(item => item.filePath);
|
|
|
- // Logger.info('xiaozheng 校正数据开始 this.filePaths length= ' + filePaths.length)
|
|
|
- // const task2 = new taskpool.Task(syncDataTask, getContext(this), filePaths);
|
|
|
- // taskpool.execute(task2, taskpool.Priority.HIGH).then(()=>{
|
|
|
- // this.endScan(false)
|
|
|
- // }).catch((e:object)=>{
|
|
|
- // console.info("task2 catch e: " + e);
|
|
|
- // })
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
showTipsDialog() {
|
|
|
DialogHelper.showCustomContentDialog({
|
|
|
@@ -522,6 +511,7 @@ async function scanDirectoryTask(context: Context, dirPath: string,
|
|
|
lockPath: string,cover_api:string,autoParseMusicName:boolean) {
|
|
|
const stack: string[] = [dirPath];
|
|
|
const table: MediaTable = new MediaTable(context);
|
|
|
+ let insertCount = 0
|
|
|
while (stack.length > 0) {
|
|
|
const currentPath = stack.pop()!;
|
|
|
const files = FileUtil.listFileSync(currentPath);
|
|
|
@@ -534,12 +524,22 @@ async function scanDirectoryTask(context: Context, dirPath: string,
|
|
|
if (FileUtil.isDirectory(fPath)) {
|
|
|
stack.push(fPath); // 使用栈结构代替递归
|
|
|
} else {
|
|
|
- if (fPath.endsWith('.lrc') || fPath.endsWith('.srt')) return;
|
|
|
- console.info('onecold scanDirectoryTask fPath2 = ' + fPath)
|
|
|
+ if (fPath.endsWith('.lrc') || fPath.endsWith('.srt')|| fPath.endsWith('.cue')) return;
|
|
|
+ // console.info('onecold scanDirectoryTask fPath2 = ' + fPath)
|
|
|
if (Utility.isMeidaByExtension(fPath)) {
|
|
|
const mediaItem = await Utility.uriGetMusicAssetsFromFile(
|
|
|
context, fPath, CommonConstants.TYPE_LOCAL, autoParseMusicName
|
|
|
);
|
|
|
+ insertCount++
|
|
|
+
|
|
|
+ try {
|
|
|
+ console.info('onecold scanDirectoryTask fPath = ' + fPath)
|
|
|
+ console.info('onecold scanDirectoryTask insertCount = ' + insertCount)
|
|
|
+ taskpool.Task.sendData(fPath,insertCount);
|
|
|
+ } catch (error) {
|
|
|
+ let err = error as BusinessError;
|
|
|
+ // hilog.warn(0x000, 'testTag', `sendData failed, code=${err.code}, message=${err.message}`);
|
|
|
+ }
|
|
|
table.insert(mediaItem, (id: number) => {
|
|
|
|
|
|
},cover_api);
|