Sfoglia il codice sorgente

实现长按屏幕倍数播放,双击屏幕暂停或者播放

onecold 1 anno fa
parent
commit
0cf8944f3a

+ 43 - 0
entry/src/main/ets/pages/SettingPage.ets

@@ -51,6 +51,7 @@ export struct SettingPage {
   static readonly IS_COVER_TOP_BIG: string = 'IS_COVER_TOP_BIG';
   public static THEME_COLOR_KEY: string = 'THEME_COLOR';
   public static TWO_FINGER_TYPE: string = 'twoFingerType';
+  public static LONG_PRESS_SPEED: string = 'longPressSpeed';
   public static THEME_COLOR_LIST: Array<ThemeColorItem> = [
     { name: '玫瑰粉', color: '#FF4081', isVip: false },
     { name: '经典蓝', color: '#0A59F7', isVip: false },
@@ -92,6 +93,7 @@ export struct SettingPage {
   @State isCustomizeBgSheet: boolean = false //自定义背景界面
   @State isShowTitleBar: boolean = true //是否显示分类导航条
   @State isShowAllBar: boolean = true //是否显示播放全部条
+  @State longPressSpeed: number = 3 //长按默认倍数
   @State blurValue: number = 0 //背景模糊
   @State bgBrightness: number = 0 //背景亮度
   @State isGridMusic: boolean = true //是否网格布局
@@ -216,6 +218,7 @@ export struct SettingPage {
     this.isShowPlayPageBack = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_PLAYPAGE_BACK, false)
     this.isShowSingleLineLyric = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_SLLYRIC, false)
     this.isCoverTopBig = PreferencesUtil.getBooleanSync(SettingPage.IS_COVER_TOP_BIG, false)
+    this.longPressSpeed = PreferencesUtil.getNumberSync(SettingPage.LONG_PRESS_SPEED, 3)
     // 只用 themeMode 控制主题
     this.themeMode = PreferencesUtil.getNumberSync(SettingPage.THEME_MODE, 0)
     this.applyThemeMode(this.themeMode)
@@ -891,6 +894,46 @@ export struct SettingPage {
             .height(55)
             .clickEffect({ level: ClickEffectLevel.HEAVY })
 
+
+            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)
+              Select([//倍速
+                { value: '0.25x' },
+                { value: '0.5x' },
+                { value: '0.75x' },
+                { value: '1x' },
+                { value: '1.25x' },
+                { value: '1.5x' },
+                { value: '1.75x' },
+                { value: '2x' },
+                { value: '2.5x' },
+                { value: '3x' }])
+                .font({ size: 15, weight: FontWeight.Medium })
+                .fontColor(Color.Gray)
+                .margin({right:18})
+                .selected(CommonConstants.video_speed_list.indexOf(this.longPressSpeed))
+                .value(Utility.optimizedFormat(this.longPressSpeed))
+                .onSelect(async (_index: number, text?: string | undefined) => {
+                  let speed = parseFloat(text?.replace('x', '') || '1');
+                  if (!CommonConstants.video_speed_list.includes(speed)) {
+                    speed = 1;
+                  }
+                  this.longPressSpeed = speed
+                  PreferencesUtil.put(SettingPage.LONG_PRESS_SPEED, this.longPressSpeed)
+                  this.sendChangeEvent()
+                })
+            }
+            .height(55)
+            .clickEffect({level:ClickEffectLevel.HEAVY})
+
             Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
             // 默认排序模式
             Row() {

+ 67 - 0
entry/src/main/ets/view/LocalMusic.ets

@@ -593,6 +593,7 @@ export struct LocalMusic {
     this.isShowPlayPageBack = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_PLAYPAGE_BACK, false)
     this.isCoverTopBig = PreferencesUtil.getBooleanSync(SettingPage.IS_COVER_TOP_BIG, false)
     this.isShowSingleLineLyric = PreferencesUtil.getBooleanSync(SettingPage.IS_SHOW_SLLYRIC, false)
+    this.longPressSpeed = PreferencesUtil.getNumberSync(SettingPage.LONG_PRESS_SPEED, 3)
     if (this.isSavePlayMode) {
       this.playType = PreferencesUtil.getNumberSync('musicPlayType', 0)
     }
@@ -5480,6 +5481,28 @@ export struct LocalMusic {
     return false
   }
 
+  @State showSpeedDialog:boolean = false
+  @State longPressSpeed: number = 3 //长按默认倍数
+  @Builder
+  SpeedDialog() {
+    Stack() {
+      Column(){
+        Text('已切换至' +this.longPressSpeed + '倍速播放')
+          .fontColor(Color.White)
+          .visibility(Visibility.Hidden)
+      }
+      .backgroundColor(Color.Black)
+      .borderRadius(20)
+      .padding({ top:10,right:20,left:15,bottom:20 })
+      .opacity(0.6)
+
+      Text('已切换至' +this.longPressSpeed + '倍速播放')
+        .fontColor(Color.White)
+    }
+    .transition(TransitionEffect.OPACITY.animation({ duration: 500, curve: Curve.Ease }))
+    .zIndex(5)
+    .margin({ top: 80 })
+  }
 
   @Builder
   IjkMusicPlayerView() {
@@ -5521,6 +5544,50 @@ export struct LocalMusic {
           // .visibility(this.currentBreakpoint !== BreakpointTypeEnum.SM
           //   ?Visibility.Visible:Visibility.Visible)
 
+          if (this.showSpeedDialog) {
+            this.SpeedDialog()
+          }
+
+          Stack(){
+            //手势拖动快进
+            Column()
+              .width(CommonConstants.FULL_PERCENT)
+              .height('100%')
+              .gesture(
+                GestureGroup(GestureMode.Parallel,
+                  // 长按屏幕倍数播放
+                  LongPressGesture({ repeat: true })
+                    .onAction(() => {
+                      if (this.CONTROL_PlayStatus === PlayStatus.PLAY) {
+                        this.showSpeedDialog = true;
+                        this.mIjkMediaPlayer.setSpeed(this.longPressSpeed+'f');
+                      }
+                    })
+                    .onActionEnd(() => {
+                      this.showSpeedDialog = false;
+                      this.mIjkMediaPlayer.setSpeed(this.playSpeed  +'f');
+                    }),
+
+
+                  //双击屏幕暂停或者播放
+                  TapGesture({ count: 2 })
+                    .onAction((event: GestureEvent) => {
+                      if (this.CONTROL_PlayStatus === PlayStatus.PLAY) {
+                        ToastUtil.showToast('已暂停')
+                      }
+                      this.playOrPause()
+
+                    })
+
+                )
+
+
+
+              )
+
+          }
+          .height('65%')
+
           Swiper() {
             this.CoverInfo()
             this.PlayerLyrics()