Selaa lähdekoodia

修复歌词模块的get Property index out of bounds的报错

onecold 1 vuosi sitten
vanhempi
sitoutus
65f6b4ac25
2 muutettua tiedostoa jossa 17 lisäystä ja 7 poistoa
  1. 2 2
      entry/src/main/ets/pages/NewIndex.ets
  2. 15 5
      lib/src/main/ets/view/LyricView2.ets

+ 2 - 2
entry/src/main/ets/pages/NewIndex.ets

@@ -429,7 +429,7 @@ struct NewIndex {
             .borderRadius('50%')
             .clip(true)
             // .fillColor(this.themeColor)
-            .backgroundColor(this.isDarkMode ? Color.Black : Color.White)
+            // .backgroundColor(this.isDarkMode ? Color.Black : Color.White)
           Column() {
             Text('VIP')
               .fontSize(9)
@@ -451,7 +451,7 @@ struct NewIndex {
             Text(this.isLogin ? this.userName : '未登录用户')
               .fontSize(14)
               // .fontWeight(FontWeight.Bold)
-              .fontColor(this.isDarkMode ? Color.White : Color.Black)
+              // .fontColor(this.isDarkMode ? Color.White : Color.Black)
               .textAlign(TextAlign.Start)
               .maxLines(1)
               .width(110)

+ 15 - 5
lib/src/main/ets/view/LyricView2.ets

@@ -332,14 +332,24 @@ export struct LyricView2 {
     isTopBottomLine(index:number){
         return  index === 0 || index === this.listAdapter.totalCount()  - 1;
     }
-
+    //修复get Property index out of bounds
     private handleSeekAction() {
         clearTimeout(this.seekUiHideTimeout);
-        let targetPosition = this.listAdapter.getData(this.seekIndex).beginTime;
-        let isPlayerHandled = this.onSeekAction(targetPosition);
-        if (!isPlayerHandled) {
-            this.animateToIndex(this.currentIndex);
+
+        let itemCount = this.listAdapter.totalCount(); // 获取数据项的总数
+
+        // 确保 seekIndex 在有效范围内
+        if (this.seekIndex >= 0 && this.seekIndex < itemCount) {
+            let targetPosition = this.listAdapter.getData(this.seekIndex).beginTime;
+            let isPlayerHandled = this.onSeekAction(targetPosition);
+            if (!isPlayerHandled) {
+                this.animateToIndex(this.currentIndex);
+            }
+        } else {
+            console.error("Seek index out of bounds:", this.seekIndex);
+            // 处理超出范围的情况,比如设定默认值或抛出错误
         }
+
         this.isUserTouching = false;
     }