如何适配网页内播放器全屏
============

在工程中的module.json5配置文件中添加网络访问权限ohos.permission.INTERNET。

具体实现可参考如下代码

import { mediaquery, window } from '@kit.ArkUI';
import { common } from '@kit.AbilityKit';
import { webview } from '@kit.ArkWeb';

@Entry
@Component
struct WebPlayerFullScreen {
  @State color: string = '#DB7093';
  @State text: string = 'Portrait';
  @State portraitFunc: mediaquery.MediaQueryResult | void | null = null;
 _ // Full-screen exit processor, used to control the exit in full-screen state_
  handler: FullScreenExitHandler | null = null;
 _ // The condition is met when the device is in landscape mode_
  listener: mediaquery.MediaQueryListener = this.getUIContext().getMediaQuery().matchMediaSync('(orientation: landscape)');
  controller: webview.WebviewController = new webview.WebviewController();

  onPortrait(mediaQueryResult: mediaquery.MediaQueryResult) {
   _ // If the device is in landscape mode, change the corresponding page layout_
    if (mediaQueryResult.matches as boolean) {
      this.color = '#FFD700';
      this.text = 'Landscape';
    } else {
      this.color = '#DB7093';
      this.text = 'Portrait';
    }
  }

  aboutToAppear() {
  _  // Bind the current application instance_
    _// Bind callback function_
    this.listener.on('change', (mediaQueryResult: mediaquery.MediaQueryResult) => {
      this.onPortrait(mediaQueryResult);
    });
  }

 _ // Change the horizontal and vertical screen status function of the device_
  private changeOrientation(isLandscape: boolean) {
  _  // Retrieve contextual information for UIAbility instances_
    let context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext;
   _ // Call this interface to manually change the device's horizontal and vertical screen status_
    window.getLastWindow(context).then((lastWindow) => {
      lastWindow.setPreferredOrientation(isLandscape ? window.Orientation.LANDSCAPE : window.Orientation.PORTRAIT);
    });
  }

  build() {
    Column() {
      Web({ src: 'https://developer.huawei.com/consumer/cn/design/', controller: this.controller })
        .javaScriptAccess(true)
        .domStorageAccess(true)
        .onFullScreenEnter((event) => {
          this.handler = event.handler;
          this.changeOrientation(true);
        })
        .onFullScreenExit(() => {
          if (this.handler) {
            this.handler.exitFullScreen();
            this.changeOrientation(false);
          }
        })
    }
    .width('100%')
    .height('100%')
  }
}