diff --git a/README.md b/README.md index 9bbabe23f77f6b11a82d5b3ae70d09401a241751..3307aaefe79a1b702e909803ae1f63f911a3dcb1 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,8 @@ │ │ └──EntryAbility.ets │ ├──pages │ │ ├──AVPlayer.ets // 视频播放 -│ │ ├──Index.ets // 首页 -│ │ └──VideoPlay.ets // 视频播放页面 +│ │ ├──VideoPlay.ets // 视频播放页面 +│ │ └──WindowPiP.ets // 首页 │ └──utils │ └──Logger.ets // 日志工具类 └──entry/src/main/resources // 应用资源目录 diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index 66ae67b68e3157505813313da500c523a38a80c2..636f8db2f5a3f6b33f97f185f4c95b251a485cf0 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -30,13 +30,13 @@ export default class EntryAbility extends UIAbility { // Main window is created, set main page for this ability hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); - windowStage.loadContent('pages/WindowPip', (err) => { + windowStage.loadContent('pages/WindowPiP', (err) => { if (err.code) { hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); return; } hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); - let uiContext: UIContext | undefined = windowStage.getMainWindowSync().getUIContext() + let uiContext: UIContext | undefined = windowStage.getMainWindowSync().getUIContext(); AppStorage.setOrCreate('uiContext', uiContext); }); } diff --git a/entry/src/main/ets/pages/AVPlayer.ets b/entry/src/main/ets/pages/AVPlayer.ets index 308d93d382d598dfd612e4e4e739562884bfe4d1..ef1065ee05a18ab142ec94a30f59ea8c7e1fe5fb 100644 --- a/entry/src/main/ets/pages/AVPlayer.ets +++ b/entry/src/main/ets/pages/AVPlayer.ets @@ -145,14 +145,18 @@ export class AVPlayer { * and use the fdSrc attribute to play back. */ async avPlayerFdSrc() { - // Create an avPlayer instance object. - this.avPlayer = await media.createAVPlayer(); - // Create a callback function for state machine changes. - this.setAVPlayerCallback(); - let context = UIContext as common.UIAbilityContext; - let fileDescriptor = await context.resourceManager.getRawFd('video.mp4'); - // Assign a value to fdSrc to trigger an initialized state machine report. - this.avPlayer.fdSrc = fileDescriptor; + try { + // Create an avPlayer instance object. + this.avPlayer = await media.createAVPlayer(); + // Create a callback function for state machine changes. + this.setAVPlayerCallback(); + let context = UIContext as common.UIAbilityContext; + let fileDescriptor = await context.resourceManager.getRawFd('video.mp4'); + // Assign a value to fdSrc to trigger an initialized state machine report. + this.avPlayer.fdSrc = fileDescriptor; + } catch (e) { + Logger.error(`Failed to create AVPlayer, error message:${e.message}`); + } } async playNext() { diff --git a/entry/src/main/ets/pages/VideoPlay.ets b/entry/src/main/ets/pages/VideoPlay.ets index 93bc8bb7874bbb1733abab8b94a3df5b404c32f9..26bc894256a92718efbdac11a2ea0f46e3115cdc 100644 --- a/entry/src/main/ets/pages/VideoPlay.ets +++ b/entry/src/main/ets/pages/VideoPlay.ets @@ -85,18 +85,22 @@ export struct PlayVideo { } async createPipController() { - this.pipController = await PiPWindow.create({ - context: UIContext, - componentController: this.mXComponentController, - navigationId: this.navigationId, - templateType: PiPWindow.PiPTemplateType.VIDEO_PLAY - }); - this.pipController.on('stateChange', (state: PiPWindow.PiPState, reason: string) => { - this.onStateChange(state, reason); - }); - this.pipController.on('controlPanelActionEvent', (event: PiPWindow.PiPActionEventType, status?: number) => { - this.onActionEvent(event, status); - }); + try { + this.pipController = await PiPWindow.create({ + context: UIContext, + componentController: this.mXComponentController, + navigationId: this.navigationId, + templateType: PiPWindow.PiPTemplateType.VIDEO_PLAY + }); + this.pipController.on('stateChange', (state: PiPWindow.PiPState, reason: string) => { + this.onStateChange(state, reason); + }); + this.pipController.on('controlPanelActionEvent', (event: PiPWindow.PiPActionEventType, status?: number) => { + this.onActionEvent(event, status); + }); + } catch (e) { + Logger.error(`Failed to create pip controller. Cause:${e.code}, message:${e.message}`); + } } destroyPipController() { diff --git a/entry/src/main/ets/pages/WindowPip.ets b/entry/src/main/ets/pages/WindowPiP.ets similarity index 98% rename from entry/src/main/ets/pages/WindowPip.ets rename to entry/src/main/ets/pages/WindowPiP.ets index a8dd0390f65b2a4d7427b63ce93315d04ebffdcb..5992ea3bb555b97c58cf9377a433943906802a16 100644 --- a/entry/src/main/ets/pages/WindowPip.ets +++ b/entry/src/main/ets/pages/WindowPiP.ets @@ -24,7 +24,7 @@ let UIContext = uiContext!.getHostContext()!; struct ImageWidthTitle { @State imageHeight: number = 0; @Link pageInfos: NavPathStack; - private titleResource?: Resource; + public titleResource?: Resource; build() { Column({ space: Constants.HOME_SPACE }) { @@ -52,7 +52,7 @@ struct ImageWidthTitle { @Entry @Component -struct WindowPip { +struct WindowPiP { @Provide('pageInfos') pageInfos: NavPathStack = new NavPathStack(); @State curState: string = ''; private navigationId: string = 'navId'; diff --git a/entry/src/main/resources/base/profile/main_pages.json b/entry/src/main/resources/base/profile/main_pages.json index 521b733f03711a7408248c2e58816de7b23ffae6..0600190bdee9f42c28059b1b7643c04705972821 100644 --- a/entry/src/main/resources/base/profile/main_pages.json +++ b/entry/src/main/resources/base/profile/main_pages.json @@ -1,5 +1,5 @@ { "src": [ - "pages/WindowPip" + "pages/WindowPiP" ] }