• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 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 */
15import router from '@system.router';
16import { DateUtil } from '@ohos/base/src/main/ets/utils/DateUtil';
17import { Log } from '@ohos/base/src/main/ets/utils/Log';
18import { Action } from '../../../common/view/browserOperation/Action'
19import type { MenuOperation } from '@ohos/base/src/main/ets/operation/MenuOperation';
20import { PhotoBrowserActionBar } from './PhotoBrowserActionBar';
21import { Broadcast } from '@ohos/base/src/main/ets/utils/Broadcast';
22import screenManager from '@ohos/base/src/main/ets/manager/ScreenManager';
23import broadcastManager from '@ohos/base/src/main/ets/manager/BroadcastManager';
24import { BroadcastConstants } from '@ohos/base/src/main/ets/constants/BroadcastConstants';
25import { startTrace, finishTrace } from '@ohos/base/src/main/ets/utils/TraceControllerUtils';
26
27@Entry
28@Component
29struct VideoBrowser {
30    private TAG: string = 'VideoBrowser';
31    @Provide('dateTitle') photoDate: string = '';
32    @Provide('timeLocationTitle') timeAndLocation: string = '';
33    @Provide isShowBar: boolean = false;
34    @Provide menuList: Array<Action> = new Array<Action>();
35    @Provide moreMenuList: Array<Action> = new Array<Action>();
36    private broadCast: Broadcast = new Broadcast();
37    private myVideoController: VideoController = new VideoController();
38    private uri = '';
39    private dateAdded = 0;
40    private previewUri = null;
41
42    onBackPress() {
43        Log.info(this.TAG, 'onBackPress');
44        router.back();
45        return true;
46    }
47
48    private onMenuClicked(action: Action) {
49        Log.info(this.TAG, `onMenuClicked, action: ${action.actionID}`);
50        let menuOperation: MenuOperation;
51        switch (action) {
52            case Action.BACK:
53                this.onBackPress();
54                return;
55            default:
56                break;
57        }
58        menuOperation.doAction();
59    }
60
61    aboutToAppear() {
62        startTrace('VideoBrowserAboutToAppear');
63        let param = router.getParams();
64        param.uri && (this.uri = param.uri.toString());
65        this.dateAdded = new Number(param.dateAdded).valueOf() || 0;
66        this.previewUri = param.previewUri;
67        if (this.uri == undefined) {
68            return;
69        }
70        Log.info(this.TAG, `uri is ${this.uri}`);
71        this.photoDate = DateUtil.getLocalizedDate(this.dateAdded);
72        this.timeAndLocation = DateUtil.getLocalizedTime(this.dateAdded);
73        this.onMenuClicked = this.onMenuClicked.bind(this);
74        screenManager.setSystemUi(false);
75        finishTrace('VideoBrowserAboutToAppear');
76    }
77
78    aboutToDisappear(): void {
79        this.myVideoController.stop();
80        screenManager.setSystemUi(true);
81    }
82
83    onPageShow() {
84        this.photoDate = DateUtil.getLocalizedDate(this.dateAdded);
85        this.timeAndLocation = DateUtil.getLocalizedTime(this.dateAdded);
86        broadcastManager.getBroadcast().emit(BroadcastConstants.THIRD_ROUTE_PAGE, []);
87    }
88
89    build() {
90        Stack({ alignContent: Alignment.TopStart }) {
91            Video({ src: this.uri, controller: this.myVideoController })
92                .controls(this.isShowBar)
93                .objectFit(ImageFit.Contain)
94                .onClick(() => {
95                    this.isShowBar = !this.isShowBar;
96                })
97                .onStart(() => {
98                    screenManager.setKeepScreenOn();
99                })
100                .onPause(() => {
101                })
102                .onFinish(() => {
103                    this.isShowBar = true;
104                    screenManager.setKeepScreenOff();
105                })
106                .autoPlay(true)
107
108            PhotoBrowserActionBar({
109                onMenuClicked: this.onMenuClicked, isVideoPage: true
110            })
111        }
112        .width('100%')
113        .height('100%')
114        .backgroundColor($r('app.color.black'))
115    }
116
117    pageTransition() {
118        PageTransitionEnter({ type: RouteType.None, duration: 0 })
119            .opacity(0)
120        PageTransitionExit({ type: RouteType.None, duration: 0 })
121            .opacity(0)
122    }
123}
124
125