HarmonyOS鸿蒙Next中全屏播放与小窗播放的切换方式是什么?

HarmonyOS鸿蒙Next中全屏播放与小窗播放的切换方式是什么? 全屏播放与小窗播放的切换方式是什么?

Video组件如何支持全屏播放?在用户切换到全屏或小窗播放时,是否需要开发者手动控制,还是通过属性或事件来自动实现?

3 回复
  1. 首先设置窗口方向,通过window的setPreferredOrientation接口来设置屏幕方向,接口文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-window-0000001815246534-V5#ZH-CN_TOPIC_0000001881258981__setpreferredorientation9

  2. 设置沉浸式窗口,为了使视屏能充斥整个屏幕,防止屏幕上下两边的任务栏等区域影响全屏观看效果,通过window的setWindowLayoutFullScreen接口设置窗口沉浸式,接口文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-window-0000001815246534-V5#ZH-CN_TOPIC_0000001881258981__setwindowlayoutfullscreen9

  3. 必须通过显隐控制控制其他listItrem是否展示,在本案例里除了展示的XC以外,其他的所有的组件理应不展示,通过参数isLayoutFullScreen以及当前选中的index来判断,并且同样根据isLayoutFullScreen来调整全屏前全屏后的XC的宽高。

核心代码

// 设置窗口方向
function setR(orientation: number) {
  window.getLastWindow(getContext(this)).then(win => {
    win.setPreferredOrientation(orientation).then(data => {
      console.log('setWindowOrientation: ' + orientation + ' Succeeded. Data: ' + JSON.stringify(data));
    }).catch(err => {
      console.log('setWindowOrientation: Failed. Cause: ' + JSON.stringify(err));
    });
  }).catch(err => {
    console.log('setWindowOrientation: Failed to obtain the top window. Cause: ' + JSON.stringify(err));
  });
}
// 设置沉浸式窗口
function setFullScreen(isLayoutFullScreen: boolean) {
  window.getLastWindow(getContext(this)).then(win => {
    win.setWindowLayoutFullScreen(isLayoutFullScreen, err => {
      const errCode: number = err.code;
      if (errCode) {
        console.error('Failed to set the window layout to full-screen mode. Cause:' + JSON.stringify(err));
        return;
      }
      console.info('Succeeded in setting the window layout to full-screen mode.');
    });
  }).catch(err => {
    console.log('setWindowOrientation: Failed to obtain the top window. Cause: ' + JSON.stringify(err));
  });
}
// 通过显隐控制控制其他listItrem是否展示
function Column() {
  Text(this.item.text)
    .visibility(this.isLayoutFullScreen === false ? Visibility.Visible : Visibility.None)
  
  Stack() {
    XComponent({ id: 'video_player_id', type: XComponentType.SURFACE, controller: this.mXComponentController })
      .onLoad(() => {
        this.player = new AVPlayerDemo();
        this.player.setSurfaceID(this.mXComponentController.getXComponentSurfaceId());
        this.player_changed = !this.player_changed;
        this.player.avPlayerLiveDemo(0, this.item.url)
      })
    
    Row() {
      Button("点击全屏")
        .onClick(() => {
          this.fangDaIndex = this.index
          this.setR(4)
          this.isLayoutFullScreen = true;
          this.setFullScreen(this.isLayoutFullScreen)
        })
        .backgroundColor(this.bkColor)
      
      Button("退出全屏")
        .onClick(() => {
          this.setR(1)
          this.isLayoutFullScreen = false;
          this.setFullScreen(this.isLayoutFullScreen)
        })
        .backgroundColor(this.bkColor)
      
      Button("跳转页面")
        .onClick(() => {
          router.pushUrl({
            url : "pages/VideoXCDemo",
            params : {
              "surfaceId" : this.mXComponentController.getXComponentSurfaceId(),
              "videoSour" : this.item
            }
          })
        })
        .backgroundColor(this.bkColor)
    }
  }
  .height(this.isLayoutFullScreen ? "100%" : 200)
}

.width('100%')

更多关于HarmonyOS鸿蒙Next中全屏播放与小窗播放的切换方式是什么?的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


在HarmonyOS鸿蒙Next中,全屏播放与小窗播放的切换可以通过以下方式实现:

  1. 全屏播放切换到小窗播放:在全屏播放模式下,用户可以通过点击屏幕右上角的“小窗”按钮,将播放窗口缩小为小窗模式。小窗会浮动在当前应用界面上,用户可以自由拖动小窗的位置。

  2. 小窗播放切换到全屏播放:在小窗播放模式下,用户可以通过点击小窗右上角的“全屏”按钮,将小窗恢复到全屏播放模式。全屏播放会占据整个屏幕,提供更沉浸的观看体验。

  3. 手势操作:部分设备支持通过手势操作进行切换。例如,在小窗播放模式下,用户可以通过双指捏合手势将小窗放大至全屏;在全屏播放模式下,用户可以通过双指展开手势将全屏缩小为小窗。

  4. 系统控制中心:用户还可以通过系统控制中心进行切换。在控制中心中,找到正在播放的媒体卡片,点击对应的按钮即可在全屏和小窗之间切换。

这些切换方式在HarmonyOS鸿蒙Next中提供了灵活的多任务处理体验,用户可以根据需要随时调整播放窗口的大小和位置。

在HarmonyOS鸿蒙Next中,全屏播放与小窗播放的切换方式如下:

  1. 全屏切换小窗:在全屏播放状态下,点击屏幕右上角的“小窗”图标,视频将自动切换为小窗模式,并悬浮在屏幕的其他应用之上。

  2. 小窗切换全屏:在小窗播放状态下,点击小窗右下角的“全屏”图标,视频将自动切换回全屏模式,占据整个屏幕。

这种设计方便用户在多任务处理时快速切换视频播放模式,提升操作便捷性。

回到顶部