|
@@ -1,615 +0,0 @@
|
|
|
-/*
|
|
|
|
|
- * Copyright (c) 2023 Huawei Device Co., Ltd.
|
|
|
|
|
- * Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
- * you may not use this file except in compliance with the License.
|
|
|
|
|
- * You may obtain a copy of the License at
|
|
|
|
|
- *
|
|
|
|
|
- * http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
- *
|
|
|
|
|
- * Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
- * distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
- * See the License for the specific language governing permissions and
|
|
|
|
|
- * limitations under the License.
|
|
|
|
|
- */
|
|
|
|
|
-
|
|
|
|
|
-import { media } from '@kit.MediaKit';
|
|
|
|
|
-import { promptAction } from '@kit.ArkUI';
|
|
|
|
|
-import { window } from '@kit.ArkUI';
|
|
|
|
|
-import { resourceManager } from '@kit.LocalizationKit';
|
|
|
|
|
-import Logger from '../common/util/Logger';
|
|
|
|
|
-import DateFormatUtil from '../common/util/DateFormatUtil';
|
|
|
|
|
-import { CommonConstants, AvplayerStatus, Events, SliderMode } from '../common/constants/CommonConstants';
|
|
|
|
|
-import { PlayConstants } from '../common/constants/PlayConstants';
|
|
|
|
|
-import { GlobalContext } from '../common/util/GlobalContext';
|
|
|
|
|
-import { VideoItem } from '../viewmodel/VideoItem';
|
|
|
|
|
-import { PlayerModel } from '../common/model/PlayerModel';
|
|
|
|
|
-import { BackgroundUtil } from '../common/util/BackgroundUtil';
|
|
|
|
|
-import { common, wantAgent } from '@kit.AbilityKit';
|
|
|
|
|
-import { avSession } from '@kit.AVSessionKit';
|
|
|
|
|
-import { BusinessError } from '@kit.BasicServicesKit';
|
|
|
|
|
-import { Utility } from '../common/util/Utility';
|
|
|
|
|
-
|
|
|
|
|
-const TAG = 'VideoController';
|
|
|
|
|
-@Observed
|
|
|
|
|
-export class VideoController {
|
|
|
|
|
- private context: common.UIAbilityContext | undefined = AppStorage.get('context');
|
|
|
|
|
- // private context: common.UIAbilityContext | undefined = undefined;
|
|
|
|
|
- public playerModel: PlayerModel;
|
|
|
|
|
- private avPlayer: media.AVPlayer | null = null;
|
|
|
|
|
- private duration: number = 0;
|
|
|
|
|
- private status: number = -1;
|
|
|
|
|
- private loop: boolean = false;
|
|
|
|
|
- private index: number = 0;
|
|
|
|
|
- private url?: string='';
|
|
|
|
|
- private name:string='';
|
|
|
|
|
- private iUrl: string = '';
|
|
|
|
|
- private surfaceId: string = '';
|
|
|
|
|
- private session?: avSession.AVSession;
|
|
|
|
|
- private isLandscape:boolean = false
|
|
|
|
|
- private globalVideoList:Array<VideoItem> = []
|
|
|
|
|
- private seekTime: number = PlayConstants.PROGRESS_SEEK_TIME;
|
|
|
|
|
- private positionX: number = PlayConstants.POSITION_X;
|
|
|
|
|
- private positionY: number = PlayConstants.POSITION_Y;
|
|
|
|
|
- public onPlayCompleted?: (name:string) => void
|
|
|
|
|
-
|
|
|
|
|
- private screenWidth: number =0
|
|
|
|
|
- private screenHeight: number =0
|
|
|
|
|
- private statusBarHeight: number =0
|
|
|
|
|
- private isYesFull: boolean = false
|
|
|
|
|
- private callBack: Function = () => {
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- constructor() {
|
|
|
|
|
- this.playerModel = new PlayerModel();
|
|
|
|
|
- this.createAVPlayer();
|
|
|
|
|
- window.getLastWindow(getContext(this))
|
|
|
|
|
- .then((windowClass: window.Window) => {
|
|
|
|
|
- let area = windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM);
|
|
|
|
|
- this.screenWidth = px2fp(windowClass.getWindowProperties().windowRect.width);
|
|
|
|
|
- this.screenHeight = px2fp(windowClass.getWindowProperties().windowRect.height);
|
|
|
|
|
- this.statusBarHeight = px2fp(area.topRect.height);
|
|
|
|
|
- })
|
|
|
|
|
- .catch((error: Error) => {
|
|
|
|
|
- Logger.error('[ScreenUtil] Failed to obtain the window size. Cause: ' + JSON.stringify(error));
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public getcurrentName():string {
|
|
|
|
|
- return this.name
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
- /**
|
|
|
|
|
- * Creates a videoPlayer object.
|
|
|
|
|
- */
|
|
|
|
|
- async createAVPlayer() {
|
|
|
|
|
- let avPlayer: media.AVPlayer = await media.createAVPlayer();
|
|
|
|
|
- this.avPlayer = avPlayer;
|
|
|
|
|
- this.bindState();
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- async createSession() {
|
|
|
|
|
- if (!this.context) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- this.session = await avSession.createAVSession(this.context, 'SESSION_NAME', 'audio');
|
|
|
|
|
- this.session.activate();
|
|
|
|
|
- Logger.info(TAG, `session create done : sessionId : ${this.session.sessionId}`);
|
|
|
|
|
- this.setAVMetadata();
|
|
|
|
|
- let wantAgentInfo: wantAgent.WantAgentInfo = {
|
|
|
|
|
- wants: [
|
|
|
|
|
- {
|
|
|
|
|
- bundleName: this.context.abilityInfo.bundleName,
|
|
|
|
|
- abilityName: this.context.abilityInfo.name
|
|
|
|
|
- }
|
|
|
|
|
- ],
|
|
|
|
|
- operationType: wantAgent.OperationType.START_ABILITIES,
|
|
|
|
|
- requestCode: 0,
|
|
|
|
|
- wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
|
|
|
|
|
- }
|
|
|
|
|
- wantAgent.getWantAgent(wantAgentInfo).then((agent) => {
|
|
|
|
|
- if (this.session) {
|
|
|
|
|
- this.session.setLaunchAbility(agent);
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
- this.setListenerForMesFromController();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- async setAVMetadata() {
|
|
|
|
|
- let id = this.index;
|
|
|
|
|
- try {
|
|
|
|
|
- if (this.context) {
|
|
|
|
|
-
|
|
|
|
|
- let metadata: avSession.AVMetadata = {
|
|
|
|
|
- assetId: `${id}`,
|
|
|
|
|
- title: this.name,
|
|
|
|
|
- artist: '',
|
|
|
|
|
- duration: this.duration
|
|
|
|
|
- };
|
|
|
|
|
- if (this.session) {
|
|
|
|
|
- this.session.setAVMetadata(metadata).then(() => {
|
|
|
|
|
- Logger.info(TAG, 'SetAVMetadata successfully');
|
|
|
|
|
- }).catch((err: BusinessError) => {
|
|
|
|
|
- Logger.error(TAG, `SetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- } catch (error) {
|
|
|
|
|
- Logger.error(TAG, `SetAVMetadata try: code: ${(error as BusinessError).code},
|
|
|
|
|
- message: ${(error as BusinessError).message}`);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- async setListenerForMesFromController() {
|
|
|
|
|
- if (!this.session) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- this.session.on('play', this.playCall);
|
|
|
|
|
- this.session.on('pause', this.pauseCall);
|
|
|
|
|
- this.session.on('playNext', this.playNextCall);
|
|
|
|
|
- this.session.on('playPrevious', this.playPreviousCall);
|
|
|
|
|
- }
|
|
|
|
|
- private playCall: () =>void = () => {
|
|
|
|
|
- Logger.info(TAG, `on play , do play task`);
|
|
|
|
|
- if (this.avPlayer !== null) {
|
|
|
|
|
- this.avPlayer.play();
|
|
|
|
|
- }
|
|
|
|
|
- };
|
|
|
|
|
- private pauseCall: () =>void = () => {
|
|
|
|
|
- Logger.info(TAG, `on pause , do pause task`);
|
|
|
|
|
- this.pause();
|
|
|
|
|
- };
|
|
|
|
|
- private playNextCall: () =>void = () => {
|
|
|
|
|
- Logger.info(TAG, `on playNext , do playNext task`);
|
|
|
|
|
- this.nextVideo()
|
|
|
|
|
- };
|
|
|
|
|
- private playPreviousCall: () =>void = () => {
|
|
|
|
|
- Logger.info(TAG, `on playPrevious , do playPrevious task`);
|
|
|
|
|
- this.previousVideo()
|
|
|
|
|
- };
|
|
|
|
|
- async unregisterSessionListener() {
|
|
|
|
|
- if (!this.session) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- this.session.off('play');
|
|
|
|
|
- this.session.off('pause');
|
|
|
|
|
- this.session.off('playNext');
|
|
|
|
|
- this.session.off('playPrevious');
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- setIsLandscape(isLand:boolean){
|
|
|
|
|
- this.isLandscape = isLand
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * AVPlayer binding event.
|
|
|
|
|
- */
|
|
|
|
|
- async bindState() {
|
|
|
|
|
- if (this.avPlayer === null) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- this.avPlayer.on(Events.STATE_CHANGE, async (state: media.AVPlayerState) => {
|
|
|
|
|
- let avplayerStatus: string = state;
|
|
|
|
|
- if (this.avPlayer === null) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- switch (avplayerStatus) {
|
|
|
|
|
- case AvplayerStatus.IDLE:
|
|
|
|
|
- this.resetProgress();
|
|
|
|
|
-
|
|
|
|
|
- this.avPlayer.url = this.url;
|
|
|
|
|
-
|
|
|
|
|
- break;
|
|
|
|
|
- case AvplayerStatus.INITIALIZED:
|
|
|
|
|
- this.avPlayer.surfaceId = this.surfaceId;
|
|
|
|
|
- this.avPlayer.prepare();
|
|
|
|
|
- break;
|
|
|
|
|
- case AvplayerStatus.PREPARED:
|
|
|
|
|
- this.avPlayer.videoScaleType = 0;
|
|
|
|
|
- this.setVideoSize();
|
|
|
|
|
- this.avPlayer.play();
|
|
|
|
|
- this.duration = this.avPlayer.duration;
|
|
|
|
|
- // if(Utility.isMusicByExtension(this.name)){
|
|
|
|
|
- // this.createSession();
|
|
|
|
|
- // }
|
|
|
|
|
- break;
|
|
|
|
|
- case AvplayerStatus.PLAYING:
|
|
|
|
|
- this.avPlayer.setVolume(this.playerModel.volume);
|
|
|
|
|
- this.setBright();
|
|
|
|
|
- this.status = CommonConstants.STATUS_START;
|
|
|
|
|
- this.watchStatus();
|
|
|
|
|
- // BackgroundUtil.startContinuousTask(this.context);
|
|
|
|
|
- break;
|
|
|
|
|
- case AvplayerStatus.PAUSED://暂停
|
|
|
|
|
- this.status = CommonConstants.STATUS_PAUSE;
|
|
|
|
|
- this.watchStatus();
|
|
|
|
|
- break;
|
|
|
|
|
- case AvplayerStatus.COMPLETED:///播放完成
|
|
|
|
|
- this.playerModel.playSpeed = PlayConstants.PLAY_SPEED;
|
|
|
|
|
- this.duration = PlayConstants.PLAYER_DURATION;
|
|
|
|
|
- if (!this.loop) {
|
|
|
|
|
- let curIndex = this.index + PlayConstants.PLAYER_NEXT;
|
|
|
|
|
- // let globalVideoList = GlobalContext.getContext().getObject('globalVideoList') as VideoItem[];
|
|
|
|
|
- this.index = (curIndex === this.globalVideoList.length) ?
|
|
|
|
|
- PlayConstants.PLAYER_FIRST : curIndex;
|
|
|
|
|
-
|
|
|
|
|
- this.url = this.globalVideoList[this.index].src;
|
|
|
|
|
- this.name = this.globalVideoList[this.index].name
|
|
|
|
|
- this.onPlayCompleted?.(this.name)//播放完成的接口回调,在播放界面的title更新下一首的音乐或者视频名称
|
|
|
|
|
- }
|
|
|
|
|
- this.avPlayer.reset();
|
|
|
|
|
- break;
|
|
|
|
|
- case AvplayerStatus.RELEASED:
|
|
|
|
|
- this.avPlayer.release();
|
|
|
|
|
- this.status = CommonConstants.STATUS_STOP;
|
|
|
|
|
- BackgroundUtil.stopContinuousTask(this.context);
|
|
|
|
|
- this.watchStatus();
|
|
|
|
|
- Logger.info('[PlayVideoModel] state released called');
|
|
|
|
|
-
|
|
|
|
|
- break;
|
|
|
|
|
- default:
|
|
|
|
|
- Logger.info('[PlayVideoModel] unKnown state: ' + state);
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- this.avPlayer.on(Events.TIME_UPDATE, (time: number) => {
|
|
|
|
|
- this.initProgress(time);
|
|
|
|
|
- });
|
|
|
|
|
- this.avPlayer.on(Events.ERROR, () => {
|
|
|
|
|
- this.playError();
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- // get video height and width
|
|
|
|
|
- this.avPlayer.on('videoSizeChange', (width: number, height: number) => {
|
|
|
|
|
- Logger.info('videoSizeChange called,and width is:' + width + ', height is :' + height);
|
|
|
|
|
- this.callBack(height / width);
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * This method is triggered when the video playback page is displayed on the video list page.
|
|
|
|
|
- */
|
|
|
|
|
- async firstPlay(index: number, url:string, iUrl: string, surfaceId: string,globalVideoList:VideoItem[], callBack?: Function) {
|
|
|
|
|
- this.index = index;
|
|
|
|
|
- this.url = url;
|
|
|
|
|
- this.iUrl = iUrl;
|
|
|
|
|
- this.surfaceId = surfaceId;
|
|
|
|
|
- this.globalVideoList = globalVideoList;
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- this.callBack = this.callBack
|
|
|
|
|
- if (this.avPlayer === null) {
|
|
|
|
|
- await this.createAVPlayer();
|
|
|
|
|
- }
|
|
|
|
|
- if (this.avPlayer !== null) {
|
|
|
|
|
-
|
|
|
|
|
- this.avPlayer.url = this.url;
|
|
|
|
|
- this.name = this.globalVideoList[index].name
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Release the video player.
|
|
|
|
|
- */
|
|
|
|
|
- release() {
|
|
|
|
|
- if (this.avPlayer !== null) {
|
|
|
|
|
- this.avPlayer.release();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Pause Playing.
|
|
|
|
|
- */
|
|
|
|
|
- pause() {
|
|
|
|
|
- if (this.avPlayer !== null) {
|
|
|
|
|
- this.avPlayer.pause();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Playback mode. The options are as follows: true: playing a single video; false: playing a cyclic video.
|
|
|
|
|
- */
|
|
|
|
|
- setLoop() {
|
|
|
|
|
- this.loop = !this.loop;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Set the playback speed.
|
|
|
|
|
- *
|
|
|
|
|
- * @param playSpeed Current playback speed.
|
|
|
|
|
- */
|
|
|
|
|
- setSpeed(playSpeed: number) {
|
|
|
|
|
- if (this.avPlayer === null) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- if (CommonConstants.OPERATE_STATE.indexOf(this.avPlayer.state) === -1) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- this.playerModel.playSpeed = playSpeed;
|
|
|
|
|
- this.avPlayer.setSpeed(this.playerModel.playSpeed);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Previous video.
|
|
|
|
|
- */
|
|
|
|
|
- previousVideo() {
|
|
|
|
|
- if (this.avPlayer === null) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- if (CommonConstants.OPERATE_STATE.indexOf(this.avPlayer.state) === -1) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- this.playerModel.playSpeed = PlayConstants.PLAY_SPEED;
|
|
|
|
|
- // let globalVideoList = GlobalContext.getContext().getObject('globalVideoList') as VideoItem[];
|
|
|
|
|
- let curIndex = this.index - PlayConstants.CONTROL_NEXT;
|
|
|
|
|
- this.index = (curIndex === -PlayConstants.CONTROL_NEXT) ?
|
|
|
|
|
- (this.globalVideoList.length - PlayConstants.CONTROL_NEXT) : curIndex;
|
|
|
|
|
-
|
|
|
|
|
- this.url = this.globalVideoList[this.index].src;
|
|
|
|
|
- this.name = this.globalVideoList[this.index].name
|
|
|
|
|
-
|
|
|
|
|
- this.avPlayer.reset();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Next video.
|
|
|
|
|
- */
|
|
|
|
|
- nextVideo() {
|
|
|
|
|
- if (this.avPlayer === null) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- if (CommonConstants.OPERATE_STATE.indexOf(this.avPlayer.state) === -1) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- this.playerModel.playSpeed = PlayConstants.PLAY_SPEED;
|
|
|
|
|
- // let globalVideoList = GlobalContext.getContext().getObject('globalVideoList') as VideoItem[];
|
|
|
|
|
- let curIndex = this.index + PlayConstants.CONTROL_NEXT;
|
|
|
|
|
-
|
|
|
|
|
- this.index = (curIndex === this.globalVideoList.length) ? PlayConstants.CONTROL_FIRST : curIndex;
|
|
|
|
|
-
|
|
|
|
|
- this.url = this.globalVideoList[this.index].src;
|
|
|
|
|
- this.name = this.globalVideoList[this.index].name
|
|
|
|
|
-
|
|
|
|
|
- this.avPlayer.reset();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Switching Between Video Play and Pause.
|
|
|
|
|
- */
|
|
|
|
|
- switchPlayOrPause() {
|
|
|
|
|
- if (this.avPlayer === null) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- if (this.status === CommonConstants.STATUS_START) {
|
|
|
|
|
- this.avPlayer.pause();
|
|
|
|
|
- } else {
|
|
|
|
|
- this.avPlayer.play();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Slide the progress bar to set the playback progress.
|
|
|
|
|
- *
|
|
|
|
|
- * @param value Value of the slider component.
|
|
|
|
|
- * @param mode Slider component change event.
|
|
|
|
|
- */
|
|
|
|
|
- setSeekTime(value: number, mode: SliderChangeMode) {
|
|
|
|
|
- if (mode === Number(SliderMode.MOVING)) {
|
|
|
|
|
- this.playerModel.progressVal = value;
|
|
|
|
|
- this.playerModel.currentTime = DateFormatUtil.secondToTime(Math.floor(value * this.duration /
|
|
|
|
|
- CommonConstants.ONE_HUNDRED / CommonConstants.A_THOUSAND));
|
|
|
|
|
- }
|
|
|
|
|
- if (mode === Number(SliderMode.END) || mode === Number(SliderMode.CLICK)) {
|
|
|
|
|
- this.seekTime = value * this.duration / CommonConstants.ONE_HUNDRED;
|
|
|
|
|
- if (this.avPlayer !== null) {
|
|
|
|
|
- this.avPlayer.seek(this.seekTime, media.SeekMode.SEEK_PREV_SYNC);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Setting the brightness.
|
|
|
|
|
- */
|
|
|
|
|
- setBright() {
|
|
|
|
|
- let windowClass = GlobalContext.getContext().getObject('windowClass') as window.Window;
|
|
|
|
|
- windowClass.setWindowBrightness(this.playerModel.bright);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Obtains the current video playing status.
|
|
|
|
|
- */
|
|
|
|
|
- getStatus() {
|
|
|
|
|
- return this.status;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Initialization progress bar.
|
|
|
|
|
- *
|
|
|
|
|
- * @param time Current video playback time.
|
|
|
|
|
- */
|
|
|
|
|
- initProgress(time: number) {
|
|
|
|
|
- let nowSeconds = Math.floor(time / CommonConstants.A_THOUSAND);
|
|
|
|
|
- let totalSeconds = Math.floor(this.duration / CommonConstants.A_THOUSAND);
|
|
|
|
|
- this.playerModel.currentTime = DateFormatUtil.secondToTime(nowSeconds);
|
|
|
|
|
- this.playerModel.totalTime = DateFormatUtil.secondToTime(totalSeconds);
|
|
|
|
|
- this.playerModel.progressVal = Math.floor(nowSeconds * CommonConstants.ONE_HUNDRED / totalSeconds);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Reset progress bar data.
|
|
|
|
|
- */
|
|
|
|
|
- resetProgress() {
|
|
|
|
|
- this.seekTime = PlayConstants.PROGRESS_SEEK_TIME;
|
|
|
|
|
- this.playerModel.currentTime = PlayConstants.PROGRESS_CURRENT_TIME;
|
|
|
|
|
- this.playerModel.progressVal = PlayConstants.PROGRESS_PROGRESS_VAL;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Volume gesture method onActionStart.
|
|
|
|
|
- *
|
|
|
|
|
- * @param event Gesture event.
|
|
|
|
|
- */
|
|
|
|
|
- onVolumeActionStart(event?: GestureEvent) {
|
|
|
|
|
- if (!event) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- this.positionX = event.offsetX;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Bright gesture method onActionStart.
|
|
|
|
|
- *
|
|
|
|
|
- * @param event Gesture event.
|
|
|
|
|
- */
|
|
|
|
|
- onBrightActionStart(event?: GestureEvent) {
|
|
|
|
|
- if (!event) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- this.positionY = event.offsetY;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Gesture method onActionUpdate.
|
|
|
|
|
- *
|
|
|
|
|
- * @param event Gesture event.
|
|
|
|
|
- */
|
|
|
|
|
- onVolumeActionUpdate(event?: GestureEvent) {
|
|
|
|
|
- if (!event) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- if (this.avPlayer === null) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- if (CommonConstants.OPERATE_STATE.indexOf(this.avPlayer.state) === -1) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- if (this.playerModel.brightShow === false) {
|
|
|
|
|
- this.playerModel.volumeShow = true;
|
|
|
|
|
- let screenWidth = GlobalContext.getContext().getObject('screenWidth') as number;
|
|
|
|
|
- let changeVolume = (event.offsetX - this.positionX) / screenWidth;
|
|
|
|
|
- let volume: number = this.playerModel.volume;
|
|
|
|
|
- let currentVolume = volume + changeVolume;
|
|
|
|
|
- let volumeMinFlag = currentVolume <= PlayConstants.MIN_VALUE;
|
|
|
|
|
- let volumeMaxFlag = currentVolume > PlayConstants.MAX_VALUE;
|
|
|
|
|
- this.playerModel.volume = volumeMinFlag ? PlayConstants.MIN_VALUE :
|
|
|
|
|
- (volumeMaxFlag ? PlayConstants.MAX_VALUE : currentVolume);
|
|
|
|
|
- this.avPlayer.setVolume(this.playerModel.volume);
|
|
|
|
|
- this.positionX = event.offsetX;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Gesture method onActionUpdate.
|
|
|
|
|
- *
|
|
|
|
|
- * @param event Gesture event.
|
|
|
|
|
- */
|
|
|
|
|
- onBrightActionUpdate(event?: GestureEvent) {
|
|
|
|
|
- if (!event) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- if (this.playerModel.volumeShow === false) {
|
|
|
|
|
- this.playerModel.brightShow = true;
|
|
|
|
|
- let screenHeight = GlobalContext.getContext().getObject('screenHeight') as number;
|
|
|
|
|
- let changeBright = (this.positionY - event.offsetY) / screenHeight;
|
|
|
|
|
- let bright: number = this.playerModel.bright;
|
|
|
|
|
- let currentBright = bright + changeBright;
|
|
|
|
|
- let brightMinFlag = currentBright <= PlayConstants.MIN_VALUE;
|
|
|
|
|
- let brightMaxFlag = currentBright > PlayConstants.MAX_VALUE;
|
|
|
|
|
- this.playerModel.bright = brightMinFlag ? PlayConstants.MIN_VALUE :
|
|
|
|
|
- (brightMaxFlag ? PlayConstants.MAX_VALUE : currentBright);
|
|
|
|
|
- Logger.info('onecold this.bright = ' + this.playerModel.bright)
|
|
|
|
|
- this.setBright();
|
|
|
|
|
- this.positionY = event.offsetY;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Gesture method onActionEnd.
|
|
|
|
|
- */
|
|
|
|
|
- onActionEnd() {
|
|
|
|
|
- setTimeout(() => {
|
|
|
|
|
- this.playerModel.volumeShow = false;
|
|
|
|
|
- this.playerModel.brightShow = false;
|
|
|
|
|
- this.positionX = PlayConstants.POSITION_X;
|
|
|
|
|
- this.positionY = PlayConstants.POSITION_Y;
|
|
|
|
|
- }, PlayConstants.DISAPPEAR_TIME);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Sets whether the screen is a constant based on the playback status.
|
|
|
|
|
- */
|
|
|
|
|
- watchStatus() {
|
|
|
|
|
- let windowClass = GlobalContext.getContext().getObject('windowClass') as window.Window;
|
|
|
|
|
- if (this.status === CommonConstants.STATUS_START) {
|
|
|
|
|
- windowClass.setWindowKeepScreenOn(true);
|
|
|
|
|
- } else {
|
|
|
|
|
- windowClass.setWindowKeepScreenOn(false);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * Sets the playback page size based on the video size.
|
|
|
|
|
- */
|
|
|
|
|
- setVideoSize() {
|
|
|
|
|
- if (this.avPlayer === null) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- let VideoWidth = this.avPlayer.width;
|
|
|
|
|
- let VideoHeight = this.avPlayer.height;
|
|
|
|
|
- let scale = VideoHeight/VideoWidth//视频的长高比例
|
|
|
|
|
-
|
|
|
|
|
- let screenScale = this.screenHeight/ this.screenWidth//屏幕的长高比例
|
|
|
|
|
- let screenScale2 = (this.screenHeight-this.statusBarHeight)/ this.screenWidth//屏幕的长高比例:竖屏模式下用这个screenScale2 有去掉状态栏高度
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- if(VideoHeight > VideoWidth){//竖屏视频
|
|
|
|
|
-
|
|
|
|
|
- if(this.isLandscape){
|
|
|
|
|
- this.playerModel.videoWidth = (1/(screenScale*scale))*100+'%';
|
|
|
|
|
- // this.videoWidth = '26.5%';
|
|
|
|
|
- this.playerModel.videoHeight = CommonConstants.FULL_PERCENT;;
|
|
|
|
|
- }else{
|
|
|
|
|
- this.playerModel.videoWidth = CommonConstants.FULL_PERCENT;
|
|
|
|
|
- this.playerModel.videoHeight = CommonConstants.FULL_PERCENT;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- }else{//横屏视频
|
|
|
|
|
- if(this.isLandscape){
|
|
|
|
|
- if(this.isYesFull){
|
|
|
|
|
- this.playerModel.videoWidth = '100%';
|
|
|
|
|
- this.playerModel.videoHeight = '100%';
|
|
|
|
|
- }else{
|
|
|
|
|
- // this.videoWidth = '85.8%';
|
|
|
|
|
- this.playerModel.videoWidth = (1/(screenScale*scale))*100+'%';
|
|
|
|
|
- this.playerModel.videoHeight = '100%';
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- }else{
|
|
|
|
|
- this.playerModel.videoWidth = '100%';
|
|
|
|
|
- // this.videoHeight = '27.5%';
|
|
|
|
|
- this.playerModel.videoHeight = (scale/screenScale2)*100+'%';
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * An error is reported during network video playback.
|
|
|
|
|
- */
|
|
|
|
|
- playError() {
|
|
|
|
|
- promptAction.showToast({
|
|
|
|
|
- duration: PlayConstants.PLAY_ERROR_TIME,
|
|
|
|
|
- message: $r('app.string.link_check_address_internet')
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|