Browse Source

增加启动时播放 和 记住最后一首进度设置功能

onecold 1 năm trước cách đây
mục cha
commit
eb4a403fca

+ 51 - 2
entry/src/main/ets/pages/SettingPage.ets

@@ -26,6 +26,8 @@ export struct SettingPage {
   @State isMusicMemoryPlay: boolean = false //是否启用记忆播放
   @State isMusicBGCover: boolean = true //播放背景随封面
   @State sortType: number = 4 //默认排序方式
+  @State isStartAutoPlay: boolean = false //启动后自动播放
+  @State isMemoryLastPlay: boolean = false //是否启用应用退出记忆最后一首的播放进度
 
   @State isShowSimi:boolean = false //是否显示私密音频
   @State isShowFAV:boolean = true //是否显示我的收藏
@@ -71,6 +73,9 @@ export struct SettingPage {
   static readonly CUSTOMIZE_BG_BLUR: string = 'customize_bg_blur';
   static readonly BG_BRIGHTNESS: string = 'bg_brightness';
 
+  static readonly iS_START_AUTO_PLAY: string = 'isStartAutoPlay';
+  static readonly iS_MEMORY_LAST_PLAY: string = 'isMemoryLastPlay';
+
   /** 当前断点类型(如大屏/小屏) */
   @StorageProp('currentBreakpoint') currentBreakpoint: string = BreakpointTypeEnum.MD;
 
@@ -166,6 +171,8 @@ export struct SettingPage {
     this.isSavePlayMode = PreferencesUtil.getBooleanSync(SettingPage.iS_SAVE_PLAY_MODE, true)
     this.blurValue = PreferencesUtil.getNumberSync(SettingPage.CUSTOMIZE_BG_BLUR, 0)
     this.bgBrightness = PreferencesUtil.getNumberSync(SettingPage.BG_BRIGHTNESS, 0)
+    this.isStartAutoPlay = PreferencesUtil.getBooleanSync(SettingPage.iS_START_AUTO_PLAY, false)
+    this.isMemoryLastPlay = PreferencesUtil.getBooleanSync(SettingPage.iS_MEMORY_LAST_PLAY, false)
     // 只用 themeMode 控制主题
     this.themeMode = PreferencesUtil.getNumberSync(SettingPage.THEME_MODE, 0)
     this.applyThemeMode(this.themeMode)
@@ -447,6 +454,49 @@ export struct SettingPage {
             }
             .height(48)
             Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
+            // 启动时播放
+            Row() {
+              Text('启动时播放')
+                .margin({ left: 18 })
+                .fontSize(15)
+                .fontColor(Color.Gray)
+                .fontWeight(480)
+                .layoutWeight(1)
+              Toggle({ type: ToggleType.Switch, isOn: this.isStartAutoPlay })
+                .selectedColor($r('app.color.tab_item_bg'))
+                .switchPointColor(Color.White)
+                .margin({ right: 18 })
+                .onChange((checked: boolean) => {
+                  this.isStartAutoPlay = checked;
+                  PreferencesUtil.put(SettingPage.iS_START_AUTO_PLAY, this.isStartAutoPlay)
+                })
+                .width(50)
+                .height(30);
+            }
+            .height(55)
+            Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
+            // 记住播放进度
+            Row() {
+              Text('记住最后一首进度')
+                .margin({ left: 18 })
+                .fontSize(15)
+                .fontColor(Color.Gray)
+                .fontWeight(480)
+                .layoutWeight(1)
+              Toggle({ type: ToggleType.Switch, isOn: this.isMemoryLastPlay })
+                .selectedColor($r('app.color.tab_item_bg'))
+                .switchPointColor(Color.White)
+                .margin({ right: 18 })
+                .onChange((checked: boolean) => {
+                  this.isMemoryLastPlay = checked;
+                  PreferencesUtil.put(SettingPage.iS_MEMORY_LAST_PLAY, this.isMemoryLastPlay)
+                  this.sendChangeEvent()
+                })
+                .width(50)
+                .height(30);
+            }
+            .height(55)
+            Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
             // 记忆播放
             Row() {
               Text('记忆播放')
@@ -462,6 +512,7 @@ export struct SettingPage {
                 .onChange((checked: boolean) => {
                   this.isMusicMemoryPlay = checked;
                   PreferencesUtil.put(SettingPage.iS_MUSIC_MEMORY_PLAY, this.isMusicMemoryPlay)
+                  this.sendChangeEvent()
                 })
                 .width(50)
                 .height(30);
@@ -643,8 +694,6 @@ export struct SettingPage {
               const qqUrl = `mqqapi://card/show_pslcard?src_type=internal&version=1&uin=${CommonConstants.QQ_GROUP}&card_type=group&source=external`;
               let context = this.getUIContext().getHostContext() as common.UIAbilityContext;
               context.openLink(qqUrl, {})
-              // ToastUtil.showToast('复制群号成功!')
-              // Utility.copyText('685109858')
             })
             .justifyContent(FlexAlign.Center)
             .height(55)

+ 24 - 5
entry/src/main/ets/view/LocalMusic.ets

@@ -2,6 +2,7 @@ import TitleBar from './TitleBar'
 import { Animator,
   BuilderNode,
   curves, display,
+  EditableLeftIconType,
   NodeController,
   PiPWindow,
   PromptAction, promptAction, router, SymbolGlyphModifier, window } from '@kit.ArkUI';
@@ -180,6 +181,8 @@ export struct LocalMusic {
   @State isGridMusic: boolean = false //是否网格布局
   @State isScrollHide: boolean = false //是否滚动隐藏
   @State isSameTimePlay: boolean = false //是否和其他app同时播放
+  @State isStartAutoPlay: boolean = false //启动后自动播放
+  @State isMemoryLastPlay: boolean = false //是否启用应用退出记忆最后一首的播放进度
   @State customizeBgPath: string | undefined = '';
   @State isDarkMode: boolean = false
   @State lyricTextWeight: number = 400
@@ -511,6 +514,8 @@ export struct LocalMusic {
     this.isSavePlayMode = PreferencesUtil.getBooleanSync(SettingPage.iS_SAVE_PLAY_MODE, true)
     this.blurValue = PreferencesUtil.getNumberSync(SettingPage.CUSTOMIZE_BG_BLUR, 0)
     this.bgBrightness = PreferencesUtil.getNumberSync(SettingPage.BG_BRIGHTNESS, 0)
+    this.isStartAutoPlay = PreferencesUtil.getBooleanSync(SettingPage.iS_START_AUTO_PLAY, false)
+    this.isMemoryLastPlay = PreferencesUtil.getBooleanSync(SettingPage.iS_MEMORY_LAST_PLAY, false)
     if (this.isSavePlayMode) {
       this.playType = PreferencesUtil.getNumberSync('musicPlayType', 0)
     }
@@ -607,7 +612,7 @@ export struct LocalMusic {
 
 
   }
-
+  @State isFirstStartPlay:boolean = false
   //获取download_path
   async mkDownLoadDir() {
 
@@ -645,14 +650,18 @@ export struct LocalMusic {
         this.curIndex = Utility.getIndexFromList(this.songList, this.currentSong.filePath)
       }
       if (ArrayUtil.isNotEmpty(this.songList)) {
+        this.isFirstStartPlay = true
         this.sonDataSource.pushArrayData(this.songList)
         if (this.currentSong === undefined) {
-
+          this.isFirstStartPlay = false
           this.currentSong = this.songList[0]
         }
         this.videoUrl = this.currentSong.filePath
         this.name = this.currentSong.name
         this.cover = this.currentSong.pixelMapPath
+        if(this.isStartAutoPlay){
+          this.startPlayOrResumePlay()
+        }
 
       } else {
         this.name = '空空如也'
@@ -6812,7 +6821,7 @@ export struct LocalMusic {
           break;
         case 1:
           //判断是不是赞助会员
-          if(PreferencesUtil.getStringSync('COVER_API','')===''){
+          if(PreferencesUtil.getStringSync('LRC_API','')===''){
             this.isLyricSetting = false
             this.showTipsDialog()
             return
@@ -8115,16 +8124,27 @@ export struct LocalMusic {
           } else {
             this.jumpTopTime = 0
             this.jumpEndTime = 0
-            //记忆播放
+            console.error('onecold 最后一首: isFirstStartPlay = ' + this.isFirstStartPlay);
+            console.error('onecold 最后一首: isMemoryLastPlay = ' + this.isMemoryLastPlay);
+            console.error('onecold 最后一首: PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_MEMORY_PLAY, false) = ' + PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_MEMORY_PLAY, false));
+
+            //记忆播放(每一首都会记忆播放)
             if (StrUtil.isNotEmpty(this.videoUrl) && !this.videoUrl.toLowerCase().endsWith('.ts')) {
               setTimeout(() => { //rmvb和flac格式马上记忆播放会报错,会延迟1s在读取记忆播放。
                 if (PreferencesUtil.getBooleanSync(SettingPage.iS_MUSIC_MEMORY_PLAY, false)) {
                   this.restorePlaybackPosition() //读取播放记忆功能
+                }else if(this.isMemoryLastPlay&&this.isFirstStartPlay){
+                  console.error('onecold 最后一首:读取播放记忆功能  = ' + this.isFirstStartPlay);
+                  this.restorePlaybackPosition() //读取播放记忆功能
                 }
+                this.isFirstStartPlay = false
 
               }, timeoutPlay)
 
+            }else{
+              this.isFirstStartPlay = false
             }
+
           }
 
 
@@ -8252,7 +8272,6 @@ export struct LocalMusic {
 
   //保存最后播放的那首歌和已经对应的播放列表
   saveLastPlayList() {
-
     PreferencesUtil.putSync('LastMusicInfo', this.currentSong)
     PreferencesUtil.putSync('LastMusicList', this.songList)