• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import emitter from '@ohos.events.emitter';
17import common from '@ohos.app.ability.common';
18import { BusinessError } from '@ohos.base';
19import Want from '@ohos.app.ability.Want';
20
21@Entry
22@Component
23struct SubWindowPage {
24  SUB_WINDOW_INNER_EVENT_ID: number = 1001;
25  videoController: VideoController = new VideoController();
26
27  async startNewAbility() {
28    let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext
29    let want: Want = {
30      bundleName: 'com.samples.windowratio',
31      abilityName: 'MainAbility',
32    };
33    try {
34      context.startAbility(want)
35        .then((data) => {
36          console.log('startAbility succeed');
37        })
38        .catch((error: BusinessError) => {
39          console.log('startAbility failed, error.code: ' + JSON.stringify(error.code) +
40            ' error.message: ' + JSON.stringify(error.message));
41        });
42    } catch (paramError) {
43      console.log('error.code: ' + JSON.stringify(paramError.code) +
44        ' error.message: ' + JSON.stringify(paramError.message));
45    }
46  }
47
48  build() {
49    Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) {
50      Button($r("app.string.startNewAbility"))
51        .onClick(async () => {
52          await this.startNewAbility();
53        })
54        .backgroundColor('#007dff')
55        .id('startAbility')
56        .fontSize('22px')
57        .width('80%')
58        .height('40px')
59        .borderRadius(15)
60
61      Video({
62        src: $rawfile('video.mp4'),
63        currentProgressRate: PlaybackSpeed.Speed_Forward_1_00_X,
64        controller: this.videoController
65      })
66        .id('smallVideo')
67        .width(320)
68        .layoutWeight(1)
69        .loop(false)
70        .muted(false)
71        .controls(true)
72        .autoPlay(true)
73        .onTouch((event: TouchEvent | undefined) => {
74          if (event !== undefined) {
75            let eventData: emitter.EventData = {
76              data: {
77                x: event.touches[0].displayX,
78                y: event.touches[0].displayY,
79                type: event.type
80              }
81            };
82            let innerEvent: emitter.InnerEvent = {
83              eventId: this.SUB_WINDOW_INNER_EVENT_ID,
84              priority: emitter.EventPriority.HIGH
85            };
86            emitter.emit(innerEvent, eventData);
87          }
88        })
89    }
90    .width('100%').height('100%')
91  }
92}