Эх сурвалжийг харах

点击歌单改为去Localmusic去获取歌单歌曲数据,不然会卡着等worker执行完才响应,缺少做缓存和显示进度条的功能

onecold 10 сар өмнө
parent
commit
06419d9620

+ 19 - 26
entry/src/main/ets/pages/NewIndex.ets

@@ -15,7 +15,7 @@ import { common } from '@kit.AbilityKit';
 //   CSJAdCreator,
 //   CSJAdSdk, CSJNativeExpressAd, NativeExpressAdListener } from '@csj/openadsdk';
 import { PrintBiddingTokenUtils } from '../common/util/PrintBiddintTokenUtils';
-import { ArrayList } from '@kit.ArkTS';
+import { ArrayList, JSON, taskpool } from '@kit.ArkTS';
 import { CSJUtil } from '../common/util/CSJUtil';
 import { StreamContent } from '../view/StreamContent';
 import { AvSessionController } from '../controller/AvSessionController';
@@ -41,9 +41,10 @@ import OnlineUpdateLog from '../dialog/OnlineUpdateLog';
 import { LocalMusic } from '../view/LocalMusic';
 import { ChartsCount } from './ChartsCount';
 import { image } from '@kit.ImageKit';
-import { Playlist } from '../viewmodel/Playlist';
+import { Playlist, PlaylistSong } from '../viewmodel/Playlist';
 import PlaylistTable from '../common/util/PlaylistTable';
 import { convertPlaylistSongsToVideoItems } from './PlaylistDetailPage';
+import MediaTable from '../common/util/MediaTable';
 
 // import { FFmpeg, FFProgressMessageParser } from '@sj/ffmpeg';
 
@@ -1082,22 +1083,13 @@ struct NewIndex {
         .backgroundColor(Color.Transparent)
         .clickEffect({ level: ClickEffectLevel.MIDDLE, scale: 0.6 })
         .onClick(async () => {
-          if (!this.playlistTable) {
-            ToastUtil.showToast('歌单功能初始化中,请稍后再试')
-            return
-          }
-          // 加载歌单歌曲
-          const playlistSongs = await this.playlistTable.queryPlaylistSongs(playlist.id)
-          if(ArrayUtil.isEmpty(playlistSongs)){
-            this.openPlaylist(playlist)//如果为空进入编辑歌单
-          }else{
-            this.currentSongList = await convertPlaylistSongsToVideoItems(this.context,playlistSongs)
-            this.currentSongListName= playlist.name
-            this.currentSongListID = playlist.id
-            this.modeType = 4//切换到歌单模式
-          }
+          this.currentSongListName = playlist.name;
+          this.currentSongListID = playlist.id;
+          this.mType === 0
+          this.modeType = 4
+          this.doShowDrawer();
+
 
-          this.doShowDrawer()
         })
         .bindContextMenu(this.MenuBuilder(playlist), ResponseType.LongPress,
           {
@@ -1231,7 +1223,7 @@ struct NewIndex {
   async initPlaylistTable() {
     try {
       this.playlistTable = new PlaylistTable(this.context)
-      console.info('歌单数据库初始化成功')
+      console.info('onecold 歌单数据库初始化成功')
 
       // 等待数据库初始化完成后再加载数据
       setTimeout(async () => {
@@ -1251,12 +1243,12 @@ struct NewIndex {
         const playlists = await this.playlistTable.queryAllPlaylists()
         this.playlistList = playlists
         console.info(`onecold 成功加载 ${playlists.length} 个歌单`)
-        if(ArrayUtil.isNotEmpty(this.playlistList)){
-          const playlistSongs = await this.playlistTable.queryPlaylistSongs(this.playlistList[0].id)
-          this.currentSongList = await convertPlaylistSongsToVideoItems(this.context,playlistSongs)
-          this.currentSongListName= this.playlistList[0].name
-          this.currentSongListID = this.playlistList[0].id
-        }
+        // if(ArrayUtil.isNotEmpty(this.playlistList)){
+        //   const playlistSongs = await this.playlistTable.queryPlaylistSongs(this.playlistList[0].id)
+        //   this.currentSongList = await convertPlaylistSongsToVideoItems(this.context,playlistSongs)
+        //   this.currentSongListName= this.playlistList[0].name
+        //   this.currentSongListID = this.playlistList[0].id
+        // }
 
       } else {
         console.warn('onecold 歌单表未初始化')
@@ -1282,7 +1274,8 @@ function themeColorWithAlpha(themeColor: string, alpha: number, isDarkMode: bool
 
 // 定义接口
 interface HiCarAspectRatio {
-  ratio: number;
-  name: string;
+  context: Context;
+  playlistId: string;
 }
 
+

+ 20 - 2
entry/src/main/ets/view/LocalMusic.ets

@@ -1,7 +1,6 @@
 import TitleBar from './TitleBar'
 import { curves, display, PiPWindow, promptAction, router, SymbolGlyphModifier, window } from '@kit.ArkUI';
 import { VideoItem } from '../viewmodel/VideoItem';
-import { Playlist } from '../viewmodel/Playlist';
 import {  LengthMetrics, SegmentButton,borderRadiuses, SegmentButtonOptions } from '@kit.ArkUI';
 import {
   AppUtil,
@@ -91,6 +90,8 @@ import { CueComptent } from '../view/CueComptent';
 import PlaylistTable from '../common/util/PlaylistTable';
 import { showAddToPlaylistDialog } from '../dialog/AddToPlaylistDialog';
 import { showCreatePlaylistDialog } from '../dialog/PlaylistDialog';
+import { convertPlaylistSongsToVideoItems } from '../pages/PlaylistDetailPage';
+import { Playlist, PlaylistSong } from '../viewmodel/Playlist';
 const TAG = 'LocalMusic';
 
 /**
@@ -303,17 +304,33 @@ export struct LocalMusic {
   //歌单id发生变化的时候回调
   onIDChange(){
     if(this.modeType==4){
+
       this.titleBarModel.setLeftIconMainNoAnimate($r('app.media.menu'))
       this.updateListData(this.currentSongList, true)
       this.titleBarModel.setTitleName(this.currentSongListName)
       this.isShowTitleBar = false
+      console.log('歌单id发生变化')
+      this.doSongListTask()//获取歌单信息
     }
 
   }
 
+  async  doSongListTask() {
+    // 初始化歌单数据库
+    const playlistTable = new PlaylistTable(this.context);
+    // 查询歌单中的所有歌曲
+    const playlistSongs: PlaylistSong[] = await playlistTable.queryPlaylistSongs(this.currentSongListID);
+    if (ArrayUtil.isEmpty(playlistSongs)) {
+        ToastUtil.showToast('当前歌单为空')
+    } else {
+      this.currentSongList = await convertPlaylistSongsToVideoItems(this.context, playlistSongs);
+      this.updateListData(this.currentSongList, true)
+    }
+  }
+
   onModeChange() {
     this.isFavMusic = false
-    if (this.modeType === 2 || this.modeType === 3) {
+    if (this.modeType === 2 || this.modeType === 3|| this.modeType === 4) {
       this.titleBarModel.setRightIcon(null)
     } else {
       this.titleBarModel.setRightIcon(($r('app.media.add')))
@@ -345,6 +362,7 @@ export struct LocalMusic {
         this.updateListData(this.currentSongList, true)
         this.titleBarModel.setTitleName(this.currentSongListName)
         this.isShowTitleBar = false
+        this.doSongListTask()//获取歌单信息
         break
     }
   }

+ 2 - 2
entry/src/main/ets/view/RotatingCover.ets

@@ -52,8 +52,8 @@ export struct RotatingCover {
   build() {
     Column() {
       Image(this.songLabel === undefined ||StrUtil.isEmpty(this.songLabel)? $r('app.media.music_red') : this.songLabel)
-        .height(48)
-        .width(48)
+        .height(42)
+        .width(42)
         .alt( $r('app.media.music_red'))
         .fillColor(this.themeColor)
         .borderRadius('100%')