Răsfoiți Sursa

播放模式增加 连续播放但是不循环 playType==4

onecold 5 luni în urmă
părinte
comite
bd6608fa0c

+ 58 - 9
entry/src/main/ets/view/LocalMusic.ets

@@ -10127,7 +10127,7 @@ export struct LocalMusic {
   @State isHide: boolean = false; //是否因此播放器的按钮,默认是进入横屏模式隐藏,点击视频的时候显示
   @State name: string = '';
   // @State loop: boolean = false;
-  @State playType: number = 0; //0:连续播放  1:单片重复播放 2:正常播放 3:随机播放
+  @State playType: number = 0; //0:连续循环播放  1:单片重复播放 2:正常播放 3:随机播放 4:连续播放不循环
   @State multiple: string = '1.0X';
   xcomponentController: XComponentController = new XComponentController()
   private panOptionBright: PanGestureOptions =
@@ -11128,6 +11128,11 @@ export struct LocalMusic {
           .width(26)
           .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
           .aspectRatio(CommonConstants.ASPECT_RATIO)
+      } else if (this.playType === 4) {
+        Image($r('app.media.noloop'))
+          .width(26)
+          .clickEffect({level:ClickEffectLevel.LIGHT, scale: 0.5})
+          .aspectRatio(CommonConstants.ASPECT_RATIO)
       }
     }
   }
@@ -14119,7 +14124,7 @@ export struct LocalMusic {
           if(this.playType == 1){//跳过尾部如果是单曲循环就选择单曲循环
             this.CONTROL_PlayStatus = PlayStatus.INIT
             this.startPlayOrResumePlay();
-          }else if (this.playType == 2) { //2:正常播放,单播完
+          }else if (this.playType == 2) { //2:正常播放,单播完
 
             this.showRePlay();
             this.currentTime = this.stringForTime(this.mIjkMediaPlayer.getDuration());
@@ -14127,6 +14132,23 @@ export struct LocalMusic {
             this.slideEnable = false;
             this.stop();
             // ToastUtil.showToast('开始重新播放')
+          }else if (this.playType == 4) { //4:连续播放不循环
+            // 检查是否是最后一首
+            if (this.curIndex >= this.songList.length - 1) {
+              // 已经是最后一首,停止播放
+              Logger.info('heanup setProgress', '连续播放不循环模式:已到达最后一首,停止播放');
+              ToastUtil.showToast('已经是最后一首了');
+              this.showRePlay();
+              this.currentTime = this.stringForTime(this.mIjkMediaPlayer.getDuration());
+              this.progressValue = this.PROGRESS_MAX_VALUE;
+              this.slideEnable = false;
+              this.stop();
+            } else {
+              // 不是最后一首,继续播放下一首
+              this.playNext().catch(() => {
+                Logger.error('heanup setProgress playNext', `播放下一首失败`);
+              });
+            }
           }else{
             this.playNext().catch(() => {
               Logger.error('heanup setProgress playNext', `播放下一首失败`);
@@ -14624,7 +14646,7 @@ export struct LocalMusic {
       () => {
 
         LogUtils.getInstance().LOGI("OnCompletionListener-->go")
-        if (this.playType == 0) { //0:连续播放  1:单片重复播放 2:正常播放
+        if (this.playType == 0) { //0:连续循环播放  1:单片重复播放 2:正常播放 4:连续播放不循环
           // 异步调用playNext
           this.playNext().catch(() => {
             Logger.error('heanup OnCompletionListener playNext', `播放下一首失败`);
@@ -14646,7 +14668,11 @@ export struct LocalMusic {
           this.randomPlay().catch(() => {
             Logger.error('heanup OnCompletionListener randomPlay', `随机播放失败`);
           });
-
+        } else if (this.playType == 4) { //4:连续播放不循环
+          // 异步调用playNext
+          this.playNext().catch(() => {
+            Logger.error('heanup OnCompletionListener playNext', `播放下一首失败`);
+          });
         }
 
 
@@ -14831,9 +14857,9 @@ export struct LocalMusic {
 
   setLoopMode() {
     let itype = this.playType + 1
-    if (itype >= 4) {
+    if (itype >= 5) {
       this.playType = 0
-      ToastUtil.showToast('连续播放')
+      ToastUtil.showToast('连续循环播放')
     } else if (itype === 1) {
       this.playType = 1
       ToastUtil.showToast('单曲循环')
@@ -14843,9 +14869,12 @@ export struct LocalMusic {
     } else if (itype === 3) {
       this.playType = 3
       ToastUtil.showToast('随机播放')
+    } else if (itype === 4) {
+      this.playType = 4
+      ToastUtil.showToast('连续播放不循环')
     } else if (itype === 0) {
       this.playType = 0
-      ToastUtil.showToast('连续播放')
+      ToastUtil.showToast('连续循环播放')
     }
     PreferencesUtil.putSync('musicPlayType', this.playType)
     this.setCurrentPlayMode()
@@ -14870,7 +14899,10 @@ export struct LocalMusic {
         ToastUtil.showToast('随机播放')
       } else if (hmPlayMode === 2) {
         this.playType = 0
-        ToastUtil.showToast('连续播放')
+        ToastUtil.showToast('连续循环播放')
+      } else if (hmPlayMode === 4) {
+        this.playType = 4
+        ToastUtil.showToast('连续播放不循环')
       }
       PreferencesUtil.putSync('musicPlayType', this.playType)
       // 应用收到设置循环模式的指令后,应用自定下一个模式,切换完毕后通过AVPlaybackState上报切换后的LoopMode。
@@ -14893,7 +14925,7 @@ export struct LocalMusic {
     let mLoopMode = 0
     switch (this.playType) {
       case 0:
-        mLoopMode = avSession.LoopMode.LOOP_MODE_LIST //连续播放
+        mLoopMode = avSession.LoopMode.LOOP_MODE_LIST //连续循环播放
         break;
       case 1:
         mLoopMode = avSession.LoopMode.LOOP_MODE_SINGLE //单曲
@@ -14904,6 +14936,9 @@ export struct LocalMusic {
       case 3:
         mLoopMode = avSession.LoopMode.LOOP_MODE_SHUFFLE //随机播放
         break;
+      case 4:
+        mLoopMode = avSession.LoopMode.LOOP_MODE_CUSTOM //连续播放不循环
+        break;
     }
     // 应用启动时/内部切换循环模式,需要把应用内的当前的循环模式设置给AVSession。
     let playBState: avSession.AVPlaybackState = {
@@ -15763,9 +15798,23 @@ export struct LocalMusic {
 
     if (ArrayUtil.isNotEmpty(this.songList)) {
       if (this.curIndex >= this.songList.length - 1) {
+        // playType=0 或 3: 尝试加载更多或循环
+        // playType=4: 不循环,检查是否是最后一首
+        if (this.playType == 4) {
+          // 连续播放不循环模式:到达最后一首时停止播放
+          Logger.info('heanup playNext', '连续播放不循环模式:已到达最后一首,停止播放');
+          ToastUtil.showToast('已经是最后一首了');
+          this.showRePlay();
+          this.currentTime = this.stringForTime(this.mIjkMediaPlayer.getDuration());
+          this.progressValue = this.PROGRESS_MAX_VALUE;
+          this.slideEnable = false;
+          this.stop();
+          return;
+        }
         await this.tryLoadNextPageForPlayback();
       }
       if (this.curIndex >= this.songList.length - 1) {
+        // playType=4 不应该执行到这里,因为上面已经return了
         this.curIndex = 0;
       } else {
         this.curIndex++;

+ 1 - 0
entry/src/main/resources/base/media/noloop.svg

@@ -0,0 +1 @@
+<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1771923455026" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="13346" xmlns:xlink="http://www.w3.org/1999/xlink" width="64" height="64"><path d="M235.318857 582.747429l41.362286 41.362285-59.757714 59.776h206.116571l-28.544 58.514286h-177.572571l59.757714 59.776-41.362286 41.362286-109.714286-109.714286a29.257143 29.257143 0 0 1-1.901714-39.277714l1.901714-2.084572 109.714286-109.714285zM906.971429 493.714286c0 135.570286-108.434286 245.577143-242.980572 248.612571L658.285714 742.4H459.593143l28.544-58.514286H658.285714c103.186286 0 187.373714-82.285714 190.098286-185.014857L848.457143 493.714286h58.514286zM619.245714 281.6l-28.544 58.514286H365.714286c-103.186286 0-187.373714 82.285714-190.098286 185.014857L175.542857 530.285714H117.028571c0-135.570286 108.434286-245.577143 242.980572-248.612571L365.714286 281.6h253.531428z m169.435429-101.138286l109.714286 109.714286a29.257143 29.257143 0 0 1 1.901714 39.277714l-1.901714 2.084572-109.714286 109.714285-41.362286-41.362285 59.757714-59.794286h-151.259428l28.525714-58.514286h122.733714l-59.757714-59.757714L788.662857 180.48z" fill="#ffffff" p-id="13347"></path><path d="M626.614857 154.038857l52.589714 25.654857-336.676571 690.285715-52.589714-25.673143z" fill="#ffffff" p-id="13348"></path></svg>

+ 1 - 1
lib/src/main/ets/view/LyricView2.ets

@@ -394,7 +394,7 @@ export struct LyricView2 {
         // 非高亮行或无效数据,返回透明
         if (index !== this.currentIndex || !word || !word.word) {
             //console.info('heanup', `getWordByWordLyricLyricItemLinearGradient - 非高亮行或无效word: index=${index}, currentIndex=${this.currentIndex}`)
-            return [[Color.White, 0.0], [Color.White, 1.0]]
+            return [[Color.Transparent, 0.0], [Color.Transparent, 1.0]]
         }
 
         // 计算该字的播放进度