• 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';
18
19@Entry
20@Component
21struct SubWindowPage {
22  SUB_WINDOW_INNER_EVENT_ID: number = 1001
23  videoController: VideoController = new VideoController()
24
25  async startNewAbility() {
26    let context = getContext(this) as common.UIAbilityContext; // UIAbilityContext
27    let want = {
28      bundleName: 'com.samples.windowratio',
29      abilityName: 'MainAbility',
30    };
31    try {
32      context.startAbility(want)
33        .then((data) => {
34          console.log('startAbility succeed');
35        })
36        .catch((error) => {
37          console.log('startAbility failed, error.code: ' + JSON.stringify(error.code) +
38          ' error.message: ' + JSON.stringify(error.message));
39        });
40    } catch (paramError) {
41      console.log('error.code: ' + JSON.stringify(paramError.code) +
42      ' error.message: ' + JSON.stringify(paramError.message));
43    }
44  }
45
46  build() {
47    Column() {
48      Button($r("app.string.startNewAbility")).onClick(async() => {
49        await this.startNewAbility()
50      })
51        .backgroundColor('#007dff')
52        .id('startAbility')
53        .fontSize('22px')
54        .width('80%')
55        .height('40px')
56        .borderRadius(15)
57
58      Video({
59        src: $rawfile('video.mp4'),
60        currentProgressRate: PlaybackSpeed.Speed_Forward_1_00_X,
61        controller: this.videoController
62      })
63        .id('smallVideo')
64        .width(400)
65        .height(250)
66        .margin(5)
67        .loop(false)
68        .muted(false)
69        .controls(true)
70        .autoPlay(true)
71        .onTouch((event: TouchEvent) => {
72          let eventData = {
73            data: {
74              "x": event.touches[0].x,
75              "y": event.touches[0].y,
76            } }
77          let innerEvent = {
78            eventId: this.SUB_WINDOW_INNER_EVENT_ID,
79            priority: emitter.EventPriority.HIGH
80          }
81          emitter.emit(innerEvent, eventData)
82        })
83    }
84    .width('100%').height('100%')
85  }
86}