diff --git a/fluentbloglibrary/src/main/ets/component/NewPlayComponent.ets b/fluentbloglibrary/src/main/ets/component/NewPlayComponent.ets index 3e625544f0a6589f15205bfed0ff5de733553db1..13e35a462620d4beda34b53ae37dc3b13c6ab307 100644 --- a/fluentbloglibrary/src/main/ets/component/NewPlayComponent.ets +++ b/fluentbloglibrary/src/main/ets/component/NewPlayComponent.ets @@ -13,7 +13,6 @@ * limitations under the License. */ -import { displaySync } from '@kit.ArkGraphics2D'; import { BreakpointType, BreakpointTypeEnum } from '../utils/BreakpointSystem'; import { Constants } from '../common/Constants'; @@ -21,43 +20,9 @@ import { Constants } from '../common/Constants'; export struct NewPlayComponent { @State rotateAngle: number = 0; @StorageLink(Constants.KEY_PREFIX + 'CurrentBreakpoint') curBp: string = BreakpointTypeEnum.SM; - private backDisplaySync: displaySync.DisplaySync | undefined = undefined; controller: VideoController = new VideoController(); @Consume('NavPathStack') pageStack: NavPathStack; - aboutToAppear(): void { - if (this.backDisplaySync === undefined) { - this.CreateDisplaySync(); - } - if (this.backDisplaySync) { - this.backDisplaySync.start(); - } - } - - aboutToDisappear() { - if (this.backDisplaySync) { - this.backDisplaySync.stop(); - this.backDisplaySync = undefined; - } - } - - CreateDisplaySync() { - let range: ExpectedFrameRateRange = { - expected: 30, - min: 0, - max: 120 - }; - let draw = () => { - if (this.rotateAngle === 360) { - this.rotateAngle = 0; - } - this.rotateAngle += 15; - }; - this.backDisplaySync = displaySync.create(); - this.backDisplaySync.setExpectedFrameRateRange(range); - this.backDisplaySync.on('frame', draw); - } - build() { NavDestination() { Column() { diff --git a/fluentbloglibrary/src/main/ets/utils/AVPlayerUtil.ets b/fluentbloglibrary/src/main/ets/utils/AVPlayerUtil.ets deleted file mode 100644 index 08943d67f481d021618f1c13a6792b5318454958..0000000000000000000000000000000000000000 --- a/fluentbloglibrary/src/main/ets/utils/AVPlayerUtil.ets +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2024 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 { common } from '@kit.AbilityKit'; -import { media } from '@kit.MediaKit'; -import Logger from './Logger'; - -const TAG: string = '[AVPlayerItem]' - -// Video name -const VIDEO_NAME = 'videoTest.mp4'; - -@Observed -export class AVPlayerUtil { - public avPlayer: media.AVPlayer | null = null; - public count: number = 0; - public surfaceID: string = ''; - public isSeek: boolean = false; - public totalTime: number = 0; - public curTime: number = 0; - public sliderValue: number = 0; - - private setAVPlayerCallback(avPlayer: media.AVPlayer): void { - avPlayer.on('timeUpdate', () => { - this.curTime = avPlayer.currentTime / 1000; - }) - avPlayer.on('stateChange', async (state: string) => { - switch (state) { - case 'idle': - avPlayer.release(); - break; - case 'initialized': - avPlayer.surfaceId = this.surfaceID; - avPlayer.prepare(); - avPlayer.pause(); - break; - case 'prepared': - avPlayer.play(); - this.totalTime = avPlayer.duration / 1000; - break; - case 'paused': - avPlayer.play(); - break; - case 'completed': - avPlayer.seek(0); - avPlayer.pause(); - break; - case 'stopped': - this.curTime = 0; - avPlayer.reset(); - break; - case 'released': - break; - default: - break; - } - }) - } - - async avPlayerPlay(uiContext: UIContext): Promise { - try { - this.avPlayer = await media.createAVPlayer(); - this.avPlayer.setSpeed(media.PlaybackSpeed.SPEED_FORWARD_1_00_X); - this.setAVPlayerCallback(this.avPlayer); - let context = uiContext.getHostContext() as common.UIAbilityContext; - let fileDescriptor = await context.resourceManager.getRawFd(VIDEO_NAME); - this.totalTime = fileDescriptor.length; - this.curTime = fileDescriptor.offset; - let avFileDescriptor: media.AVFileDescriptor = { - fd: fileDescriptor.fd, - offset: fileDescriptor.offset, - length: fileDescriptor.length - }; - this.isSeek = true; - this.avPlayer.fdSrc = avFileDescriptor; - this.avPlayer.prepare(); - } catch (error) { - Logger.error(TAG, `avPlayerPlay fail, error code: ${error.code}, message: ${error.message}`); - } - } - - async release(): Promise { - try { - this.avPlayer?.release(); - } catch (error) { - Logger.error(TAG, `avPlayerPlay release fail, error code: ${error.code}, message: ${error.message}`); - } - } -} \ No newline at end of file diff --git a/fluentbloglibrary/src/main/ets/view/SampleUnitAVPlayView.ets b/fluentbloglibrary/src/main/ets/view/SampleUnitAVPlayView.ets deleted file mode 100644 index 40b9f4a1d27b1f235294d9caab911a2901b9678d..0000000000000000000000000000000000000000 --- a/fluentbloglibrary/src/main/ets/view/SampleUnitAVPlayView.ets +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2024 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 { Constants } from '../common/Constants'; -import { BreakpointTypeEnum } from '../utils/BreakpointSystem'; -import { AVPlayerUtil } from '../utils/AVPlayerUtil'; - -// Delay time -const DELAY = 500; -// Surface size -const SURFACE_WIDTH = 1600; -const SURFACE_HEIGHT = 900; - -@Component -export default struct SampleUnitAVPlayView { - @Link avPlayer: AVPlayerUtil; - @StorageLink(Constants.KEY_PREFIX + 'CurrentBreakpoint') curBp: string = BreakpointTypeEnum.SM; - @State xComponentWidth: string = '100%'; - @State xComponentHeight: string = '50%' - private xComponentController: XComponentController = new XComponentController(); - setTimeInstance: number = 1; - currentSurfaceID: string = ''; - - build() { - Stack({ alignContent: Alignment.Bottom }) { - XComponent({ - type: XComponentType.SURFACE, - controller: this.xComponentController - }) - .backgroundImage($r('app.media.video_pic')) - .backgroundImageSize({ width: Constants.FULL_SIZE, height: Constants.FULL_SIZE }) - .onLoad(() => { - this.xComponentController.setXComponentSurfaceRect({ - surfaceWidth: SURFACE_WIDTH, surfaceHeight: SURFACE_HEIGHT - }) - this.avPlayer.surfaceID = this.xComponentController.getXComponentSurfaceId(); - }) - .onVisibleAreaChange([0.0, 1.0], (isVisible: boolean, currentRatio: number) => { - if (isVisible && currentRatio === 1) { - if (this.setTimeInstance) { - clearTimeout(this.setTimeInstance) - } - this.setTimeInstance = setTimeout(() => { - if (this.avPlayer && this.avPlayer.surfaceID !== '') { - if (this.currentSurfaceID) { - if (this.avPlayer.surfaceID !== this.currentSurfaceID) { - } - } else { - this.currentSurfaceID = this.avPlayer.surfaceID - } - } - }, DELAY) - } - if (!isVisible && currentRatio <= 0.0) { - this.avPlayer.avPlayer?.stop(); - this.currentSurfaceID = '' - } - }) - .height(this.xComponentHeight) - .width(this.xComponentWidth) - } - } -} \ No newline at end of file