diff --git a/build-profile.json5 b/build-profile.json5 index 6e95c60bd2de9ac1a7e4e999d811e83d5b3c2cfe..989cad5f5e559330dba694a846a1afa1acfe433a 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -1,6 +1,19 @@ { "app": { "signingConfigs": [ + { + "name": "default", + "type": "HarmonyOS", + "material": { + "certpath": "C:\\Users\\Administrator\\.ohos\\config\\default_knock-share_GGa8AleRuyqM0kcQZXV0TCd7PgzSGbxFp6gPttvHjF0=.cer", + "keyAlias": "debugKey", + "keyPassword": "0000001BA202BEE11C664B8E9B62FB518C3A6433C3A926F36B61D2E122C1CA71FAD2F45369DCF8299E99A4", + "profile": "C:\\Users\\Administrator\\.ohos\\config\\default_knock-share_GGa8AleRuyqM0kcQZXV0TCd7PgzSGbxFp6gPttvHjF0=.p7b", + "signAlg": "SHA256withECDSA", + "storeFile": "C:\\Users\\Administrator\\.ohos\\config\\default_knock-share_GGa8AleRuyqM0kcQZXV0TCd7PgzSGbxFp6gPttvHjF0=.p12", + "storePassword": "0000001B5327FE318EF4B7D185A0954336209F0BF5B2547512889EAA9813301F6435688125673D29888477" + } + } ], "products": [ { diff --git a/knocksharelibrary/src/main/ets/controller/KnockController.ets b/knocksharelibrary/src/main/ets/controller/KnockController.ets index c1d24b2a48c892d2f5961d258fd1bdc5e8037290..1734c85a03bee7c891ef88d3d303614569e1daa6 100644 --- a/knocksharelibrary/src/main/ets/controller/KnockController.ets +++ b/knocksharelibrary/src/main/ets/controller/KnockController.ets @@ -18,7 +18,7 @@ import { fileUri } from '@kit.CoreFileKit'; import { BusinessError } from '@kit.BasicServicesKit'; import { uniformTypeDescriptor } from '@kit.ArkData'; import { common } from '@kit.AbilityKit'; -import { VIDEO_SOURCES, VideoData } from '../model/VideoData'; +import { VIDEO_SOURCES, VideoData, VIDEO_NAME } from '../model/VideoData'; import { Logger } from '../utils/Logger'; import { ConfigMapKey, ResourceUtil } from '../utils/ResourceUtil'; @@ -45,22 +45,22 @@ export class KnockController { * @param target After the Huawei Share event is triggered, * you can call back the parameters and share them across devices. */ - public immersiveCallback(target: harmonyShare.SharableTarget) { + public immersiveCallback(target: harmonyShare.SharableTarget, videoIndex: number) { // share app linking try { - let videoIndex: number = AppStorage.get('videoIndex') as number; let videoData: VideoData = VIDEO_SOURCES[videoIndex]; // Video thumbnail image sandbox path let filePath: string = this.context?.filesDir + `/${videoData.head}`; // Get video thumbnail URI path let coverUri: string = fileUri.getUriFromPath(filePath); let videoUrl: string = - ResourceUtil.getRawFileStringByKey(getContext(this) as common.UIAbilityContext, ConfigMapKey.VIDEO_URL); + ResourceUtil.getRawFileStringByKey(getContext(this) as common.UIAbilityContext, + VIDEO_NAME[videoIndex] as ConfigMapKey); let shareData: systemShare.SharedData = new systemShare.SharedData({ // Set the shared data type to Link utd: uniformTypeDescriptor.UniformDataType.HYPERLINK, // The shared App Linking link is replaced with the real address here - content: `${videoUrl}?videoIndex=${videoIndex}`, + content: videoUrl, thumbnailUri: coverUri, title: videoData.name, description: videoData.description @@ -79,11 +79,11 @@ export class KnockController { /** * Add knock listening */ - public immersiveListening() { + public immersiveListening(videoIndex: number) { try { - if (canIUse('SystemCapability.Collaboration.HarmonyShare') && !this.isKnockListening) { + if (canIUse('SystemCapability.Collaboration.HarmonyShare')) { harmonyShare.on('knockShare', (target: harmonyShare.SharableTarget) => { - this.immersiveCallback(target); + this.immersiveCallback(target, videoIndex); }); this.isKnockListening = true; } diff --git a/knocksharelibrary/src/main/ets/model/VideoData.ets b/knocksharelibrary/src/main/ets/model/VideoData.ets index 5adff58a6ce2e63b7bf7377f7bfda7c3bb31c344..145f5aafb937a5b63081e9497edd04ab25e3ec60 100644 --- a/knocksharelibrary/src/main/ets/model/VideoData.ets +++ b/knocksharelibrary/src/main/ets/model/VideoData.ets @@ -50,4 +50,11 @@ export const VIDEO_SOURCES: VideoData[] = [ description: 'Nova 系列宣传视频描述', index: 3 }, -]; \ No newline at end of file +]; + +export const VIDEO_NAME: string[] = [ + 'kvPopup', + 'brandAmbassadorVideo', + 'kvIntroPop', + 'cameraIntroPopup' +] \ No newline at end of file diff --git a/knocksharelibrary/src/main/ets/pages/KnockSharePage.ets b/knocksharelibrary/src/main/ets/pages/KnockSharePage.ets index f03d086b38217bd1b7accac0de544e40afe6f853..1dfcb86b55d320a0cb7953d97202195dbee80e3e 100644 --- a/knocksharelibrary/src/main/ets/pages/KnockSharePage.ets +++ b/knocksharelibrary/src/main/ets/pages/KnockSharePage.ets @@ -20,6 +20,7 @@ import { RouterParam } from '../common/Constants'; import { BreakpointType, BreakpointTypeEnum } from '../utils/BreakpointSystem'; import { WindowUtil } from '../utils/WindowUtil'; import { hilog } from '@kit.PerformanceAnalysisKit'; +import App from '@system.app'; const TAG = '[KnockShareSample]'; @@ -74,11 +75,12 @@ struct TipDialog { @Component export struct KnockSharePage { - @StorageLink('avPlayerController') avPlayerController?: AVPlayerController = undefined; @StorageLink('currentBreakpoint') curBp: string = BreakpointTypeEnum.SM; @StorageProp('topRectHeight') topRectHeight: number = 0; - @StorageLink('KnockSharePageStack') pageStack: NavPathStack = new NavPathStack(); + @StorageLink('KnockShareSamplePageStack') pageStack: NavPathStack = new NavPathStack(); @StorageProp('statusBarHeight') statusBarHeight: number = 0; + @StorageLink('KnockShareSampleVideoIndex') videoIndex: number = -1; + private customDialogController: CustomDialogController | null = new CustomDialogController({ builder: TipDialog({onConfirm: () => { this.customDialogController?.close(); @@ -96,14 +98,20 @@ export struct KnockSharePage { }); aboutToAppear(): void { - const needTip = AppStorage.has('needTip'); + const context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext; + ImageUtil.saveImage(context); + WindowUtil.updateStatusBarColor(getContext(this), true); + const needTip = AppStorage.get('needTip') ?? false; if (needTip) { this.customDialogController?.open(); AppStorage.delete('needTip'); + } else { + const videoIndex = AppStorage.get('KnockShareSampleVideoIndex') ?? -1; + if (videoIndex != -1) { + const param: RouterParam = { videoIndex: this.videoIndex } + this.pageStack.pushPath({ name: 'videoPlayIndex', param: param }) + } } - const context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext; - ImageUtil.saveImage(context); - WindowUtil.updateStatusBarColor(getContext(this), true); } @Builder diff --git a/knocksharelibrary/src/main/ets/pages/VideoPlay.ets b/knocksharelibrary/src/main/ets/pages/VideoPlay.ets index 5c0c73b99c21c20669bdb469e2030902754dfb88..72c657abb1fe37581676036c98fb57b32f0035cd 100644 --- a/knocksharelibrary/src/main/ets/pages/VideoPlay.ets +++ b/knocksharelibrary/src/main/ets/pages/VideoPlay.ets @@ -29,39 +29,38 @@ const TAG = '[KnockShareSample]'; @Component export struct VideoPlay { - @StorageLink('avPlayerController') avPlayerController ?: AVPlayerController = undefined; - @StorageLink('videoIndex') videoIndex: number = -1; @StorageProp('statusBarHeight') statusBarHeight: number = 0; @StorageProp('naviIndicatorHeight') naviIndicatorHeight: number = 0; @StorageLink('currentBreakpoint') curBp: string = BreakpointTypeEnum.SM; - @StorageLink('KnockSharePageStack') pageStack: NavPathStack = new NavPathStack(); + @StorageLink('KnockShareSamplePageStack') pageStack: NavPathStack = new NavPathStack(); @State videoEpisode: number[] = []; @State immersiveStatus: boolean = false; + @State @Watch('videoIndexChange') videoIndex: number = -1; private knockController: KnockController | undefined = undefined; aboutToAppear(): void { WindowUtil.updateStatusBarColor(getContext(this), true); Logger.info(TAG, `aboutToAppear videoIndex is ${this.videoIndex}`); - VIDEO_SOURCES.forEach((item, index: number) => { + VIDEO_SOURCES.forEach((_item, index: number) => { this.videoEpisode.push(index + 1); }) let context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext; this.knockController = KnockController.getInstance(context); - this.knockController?.immersiveListening(); + this.knockController?.immersiveListening(this.videoIndex); + } + + videoIndexChange() { + this.knockController?.immersiveListening(this.videoIndex); } onBackPress(): boolean | void { - if (this.avPlayerController) { - this.avPlayerController.releasePlayer(); - this.avPlayerController = undefined; - } this.pageStack.pop(); return true; } onPageShow(): void { - this.knockController?.immersiveListening(); + this.knockController?.immersiveListening(this.videoIndex); } onPageHide(): void { @@ -70,11 +69,6 @@ export struct VideoPlay { aboutToDisappear(): void { this.knockController?.immersiveDisableListening(); - - if (this.avPlayerController) { - this.avPlayerController.releasePlayer(); - this.avPlayerController = undefined; - } } diff --git a/knocksharelibrary/src/main/ets/utils/ResourceUtil.ets b/knocksharelibrary/src/main/ets/utils/ResourceUtil.ets index ebcdaef8d18555b3d4d5d8e80b48539c76b42501..c0bd2b40ed69c161cd35da0ee9e1c1d97624c27d 100644 --- a/knocksharelibrary/src/main/ets/utils/ResourceUtil.ets +++ b/knocksharelibrary/src/main/ets/utils/ResourceUtil.ets @@ -83,17 +83,29 @@ export class ResourceUtil { } private static getDataByKey(content: ConfigMapData, key: ConfigMapKey): string { - if (key === ConfigMapKey.VIDEO_URL) { - return content.videoUrl; + if (key === ConfigMapKey.KV_POPUP) { + return content.kvPopup; + } else if (key === ConfigMapKey.BRAND_AMBASSADOR) { + return content.brandAmbassador; + } else if (key === ConfigMapKey.KV_INTRO_POP) { + return content.kvIntroPop; + } else if (key === ConfigMapKey.CAMEAR_INTRO_POPUP) { + return content.cameraIntroPopup; } return ''; } } export class ConfigMapData { - public videoUrl: string = ''; + public kvPopup: string = ''; + public brandAmbassador: string = ''; + public kvIntroPop: string = ''; + public cameraIntroPopup: string = ''; } export enum ConfigMapKey { - VIDEO_URL = 'videoUrl', + KV_POPUP = 'kvPopup', + BRAND_AMBASSADOR = 'brandAmbassador', + KV_INTRO_POP = 'kvIntroPop', + CAMEAR_INTRO_POPUP = 'cameraIntroPopup', } \ No newline at end of file diff --git a/knocksharelibrary/src/main/ets/view/AVPlayerControllerView.ets b/knocksharelibrary/src/main/ets/view/AVPlayerControllerView.ets index b4292d7dccfe25416cdad4e21b5589ba1c650b45..b49261c0c76cfbf48a311ed700a0822cc63d732c 100644 --- a/knocksharelibrary/src/main/ets/view/AVPlayerControllerView.ets +++ b/knocksharelibrary/src/main/ets/view/AVPlayerControllerView.ets @@ -20,7 +20,7 @@ import { BreakpointTypeEnum } from '../utils/BreakpointSystem'; @Component export struct AVPlayerControllerView { - @StorageLink('avPlayerController') avPlayerController?: AVPlayerController = undefined; + @Link avPlayerController?: AVPlayerController; @StorageLink('currentBreakpoint') curBp: string = BreakpointTypeEnum.SM; @StorageProp('naviIndicatorHeight') naviIndicatorHeight: number = 0; @Link currentTime: number; diff --git a/knocksharelibrary/src/main/ets/view/EpisodeChoose.ets b/knocksharelibrary/src/main/ets/view/EpisodeChoose.ets index 5d06c1abf823e7e6c7ec7caa2134bc2bbc2464bc..20af1103a2f715ae9b7428b62c404568a0a80d56 100644 --- a/knocksharelibrary/src/main/ets/view/EpisodeChoose.ets +++ b/knocksharelibrary/src/main/ets/view/EpisodeChoose.ets @@ -14,6 +14,9 @@ */ import { LengthMetrics, LengthUnit } from '@kit.ArkUI'; import { BreakpointTypeEnum } from '../utils/BreakpointSystem'; +import { Logger } from '../utils/Logger'; + +const TAG = '[KnockShareSample]'; @Component export struct EpisodeChoose { @@ -22,7 +25,7 @@ export struct EpisodeChoose { @StorageLink('currentBreakpoint') curBp: string = BreakpointTypeEnum.SM; aboutToAppear(): void { - console.info('videoIndex EpisodeChoose ' + this.videoIndex) + Logger.info(TAG, 'videoIndex EpisodeChoose ' + this.videoIndex) } build() { diff --git a/knocksharelibrary/src/main/ets/view/VideoPlayingView.ets b/knocksharelibrary/src/main/ets/view/VideoPlayingView.ets index d48de0be7c0443f185aa3c65f453b9169364a3b8..888b06d4870ef455204dde2eafca2c42f0c26dca 100644 --- a/knocksharelibrary/src/main/ets/view/VideoPlayingView.ets +++ b/knocksharelibrary/src/main/ets/view/VideoPlayingView.ets @@ -23,12 +23,12 @@ const TAG = 'VideoPlayingView'; @Component export struct VideoPlayingView { - @StorageLink('avPlayerController') @Watch('avPlayerStateChange') avPlayerController?: AVPlayerController = undefined; + @State @Watch('avPlayerStateChange') avPlayerController?: AVPlayerController = undefined; @StorageLink('currentBreakpoint') curBp: string = BreakpointTypeEnum.SM; @StorageProp('statusBarHeight') statusBarHeight: number = 0; @StorageProp('naviIndicatorHeight') naviIndicatorHeight: number = 0; @Link @Watch('videoIndexChange') videoIndex: number; - @StorageLink('KnockSharePageStack') pageStack: NavPathStack = new NavPathStack(); + @StorageLink('KnockShareSamplePageStack') pageStack: NavPathStack = new NavPathStack(); @Prop videoList: VideoData[]; @State surfaceID: string = ''; @State currentTime: number = 0; @@ -103,6 +103,12 @@ export struct VideoPlayingView { } } + async aboutToDisappear(): Promise { + if (this.avPlayerController) { + await this.avPlayerController.releasePlayer(); + } + } + build() { Stack() { Column() { @@ -120,7 +126,6 @@ export struct VideoPlayingView { .width('100%') .aspectRatio(16 / 9) .onLoad(async () => { - await this.releaseAVPlayer(); await this.initAVPlayer(); }) } @@ -163,7 +168,8 @@ export struct VideoPlayingView { durationTime: this.durationTime, isPlaying: this.isPlaying, isShowAVPlayerController: this.isShowAVPlayerController, - avPlayerControllerTimeID: this.avPlayerControllerTimeID + avPlayerControllerTimeID: this.avPlayerControllerTimeID, + avPlayerController: this.avPlayerController }) .visibility(this.isShowAVPlayerController ? Visibility.Visible : Visibility.Hidden) } diff --git a/knocksharelibrary/src/main/resources/rawfile/web_config.json5 b/knocksharelibrary/src/main/resources/rawfile/web_config.json5 index cbba9f8692fa747e7279b540339343283d19e468..4ff79d1744f0a0ca502b923c9d5a1a1251262bc1 100644 --- a/knocksharelibrary/src/main/resources/rawfile/web_config.json5 +++ b/knocksharelibrary/src/main/resources/rawfile/web_config.json5 @@ -1,3 +1,6 @@ { - "videoUrl": "https://testvideo.dre.agchosting.link" + "kvPopup": "https://consumer.huawei.com/content/dam/huawei-cbg-site/cn/mkt/pdp/phones/pura-x/video/kv-popup.mp4", + "brandAmbassador": "https://consumer.huawei.com/content/dam/huawei-cbg-site/cn/mkt/pdp/phones/mate-xt-ultimate-design/videos/hero/brand-ambassador-video.mp4", + "kvIntroPop": "https://consumer.huawei.com/content/dam/huawei-cbg-site/cn/mkt/pdp/phones/ah-pro-plus/video/kv-intro-pop.mp4", + "cameraIntroPopup": "https://consumer.huawei.com/content/dam/huawei-cbg-site/cn/mkt/pdp/phones/nova13-pro/video/camera-intro-popup.mp4" } \ No newline at end of file diff --git a/knocksharesample/src/main/ets/entryability/EntryAbility.ets b/knocksharesample/src/main/ets/entryability/EntryAbility.ets index cc1f3c2676dc3ceadc07ba49e93f02813817e86e..b14264cd791b935a7baa2791410e2a5bb4fc069c 100644 --- a/knocksharesample/src/main/ets/entryability/EntryAbility.ets +++ b/knocksharesample/src/main/ets/entryability/EntryAbility.ets @@ -39,7 +39,7 @@ export default class EntryAbility extends UIAbility { onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); Logger.info(TAG, 'Ability onCreate'); - AppStorage.set('KnockSharePageStack', this.pageStack); + AppStorage.set('KnockShareSamplePageStack', this.pageStack); this.mVideoIndex = Utils.getVideoIndex(want); Utils.videoIndex = this.mVideoIndex; } @@ -51,8 +51,7 @@ export default class EntryAbility extends UIAbility { Logger.info(TAG, 'Ability onWindowStageCreate'); let pageUrl: string = 'pages/Index'; if (this.mVideoIndex !== -1) { - pageUrl = 'pages/VideoPlayIndex'; - AppStorage.setOrCreate('videoIndex', this.mVideoIndex); + AppStorage.setOrCreate('KnockShareSampleVideoIndex', this.mVideoIndex); } else { AppStorage.setOrCreate('needTip', true); } diff --git a/knocksharesample/src/main/ets/pages/Index.ets b/knocksharesample/src/main/ets/pages/Index.ets index 22c2938d7f935dcc70c622c25252c4a226470fb7..aae11edd966221e554cd79f59ea304b48a56a30c 100644 --- a/knocksharesample/src/main/ets/pages/Index.ets +++ b/knocksharesample/src/main/ets/pages/Index.ets @@ -3,7 +3,8 @@ import { KnockSharePage } from 'knocksharelibrary'; @Entry @Component struct Index { - @StorageLink('KnockSharePageStack') pageStack: NavPathStack = new NavPathStack(); + @StorageLink('KnockShareSamplePageStack') pageStack: NavPathStack = new NavPathStack(); + build() { Navigation(this.pageStack) { Stack() { diff --git a/knocksharesample/src/main/ets/pages/VideoPlayIndex.ets b/knocksharesample/src/main/ets/pages/VideoPlayIndex.ets index d0dc56874ee2e068f3a7bb4c2de8f462976f2416..0942a46809817ae9ceeddd5d3fe3f70cfd97245c 100644 --- a/knocksharesample/src/main/ets/pages/VideoPlayIndex.ets +++ b/knocksharesample/src/main/ets/pages/VideoPlayIndex.ets @@ -1,6 +1,5 @@ import { VideoPlay } from 'knocksharelibrary' import { RouterParam } from 'knocksharelibrary/src/main/ets/common/Constants'; -import { Utils } from '../utils/Utils'; @Builder export function VideoPlayIndexBuilder() { @@ -10,27 +9,12 @@ export function VideoPlayIndexBuilder() { @Entry @Component struct VideoPlayIndex { - @StorageLink('videoIndex') videoIndex: number = -1; - @StorageLink('KnockSharePageStack') pageStack: NavPathStack = new NavPathStack(); - - aboutToAppear(): void { - if (Utils.videoIndex != -1) { - this.videoIndex = Utils.videoIndex; - Utils.videoIndex = -1; - } - } - - onPageShow(): void { - AppStorage.setOrCreate('KnockShareVideoPlayShow', true); - } - - aboutToDisappear(): void { - AppStorage.setOrCreate('KnockShareVideoPlayShow', false); - } + private videoIndex: number = -1; + @StorageLink('KnockShareSamplePageStack') pageStack: NavPathStack = new NavPathStack(); build() { NavDestination() { - VideoPlay() + VideoPlay({ videoIndex: this.videoIndex }) } .width('100%') .height('100%') diff --git a/knocksharesample/src/main/ets/utils/Utils.ets b/knocksharesample/src/main/ets/utils/Utils.ets index 2b5cbaef4f154ab62a5f21fe430f2fb0a0f6468f..f90404c8c20c3a49a348a459076d6d3cc26f4ced 100644 --- a/knocksharesample/src/main/ets/utils/Utils.ets +++ b/knocksharesample/src/main/ets/utils/Utils.ets @@ -45,16 +45,16 @@ export class Utils { static onNewWant(want: Want) { let videoIndex: number = Utils.getVideoIndex(want); if (videoIndex !== -1) { - const pageStack = AppStorage.get('KnockSharePageStack') as NavPathStack; - const videoPlayShow = AppStorage.get('KnockShareVideoPlayShow') as boolean; - - if (!videoPlayShow) { - let param: RouterParam = { - videoIndex: videoIndex - } - pageStack.pushPath({ name: 'videoPlayIndex', param: param }); + let param: RouterParam = { + videoIndex: videoIndex + } + const pageStack = AppStorage.get('KnockShareSamplePageStack') as NavPathStack; + const pages = pageStack.getAllPathName(); + const currentPage = pages[pages.length - 1]; + if (currentPage === 'videoPlayIndex') { + pageStack.replacePath({ name: 'videoPlayIndex', param: param }); } else { - AppStorage.setOrCreate('videoIndex', videoIndex); + pageStack.pushPath({ name: 'videoPlayIndex', param: param }); } } } diff --git a/knocksharesample/src/main/module.json5 b/knocksharesample/src/main/module.json5 index 2b2b1f84bfad0ca9ad6ff44a3160bfa74215eb0b..3068b6cd497eb9dcb7da24b3c113ee244432a451 100644 --- a/knocksharesample/src/main/module.json5 +++ b/knocksharesample/src/main/module.json5 @@ -27,25 +27,10 @@ { "entities": [ "entity.system.home", - // entities must contain "entity.system.browsable" - "entity.system.browsable" ], "actions": [ "action.system.home", - // Actions must contain "ohos.want.action.viewData" - "ohos.want.action.viewData" ], - "uris": [ - { - // The scheme must be configured as https - "scheme": "https", - // The host must be configured as the associated domain name - "host": "testvideo.dre.agchosting.link", - "path": "" - } - ], - // domainVerify must be set to true - "domainVerify": true } ] }