Showing
16 changed files
with
211 additions
and
49 deletions
| 1 | -import { DateFormatUtil, WDPlayerController, WDPlayerRenderLiveView } from 'wdPlayer/Index'; | 1 | +import { DateFormatUtil, WDAliPlayerController, WDPlayerController, WDPlayerRenderLiveView } from 'wdPlayer/Index'; |
| 2 | import router from '@ohos.router'; | 2 | import router from '@ohos.router'; |
| 3 | import { StringUtils } from 'wdKit/Index'; | 3 | import { StringUtils } from 'wdKit/Index'; |
| 4 | import { Action } from 'wdBean'; | 4 | import { Action } from 'wdBean'; |
| @@ -10,7 +10,7 @@ const TAG = 'VideoPlayPage'; | @@ -10,7 +10,7 @@ const TAG = 'VideoPlayPage'; | ||
| 10 | export struct VideoPlayPage { | 10 | export struct VideoPlayPage { |
| 11 | //是否处于播放状态中 | 11 | //是否处于播放状态中 |
| 12 | @State isPlayStatus: boolean = true | 12 | @State isPlayStatus: boolean = true |
| 13 | - playerController: WDPlayerController = new WDPlayerController(); | 13 | + playerController: WDAliPlayerController = new WDAliPlayerController(); |
| 14 | //视频地址 | 14 | //视频地址 |
| 15 | @State videoUrl: string = '' | 15 | @State videoUrl: string = '' |
| 16 | //封面图 | 16 | //封面图 |
| @@ -8,7 +8,7 @@ import { Logger, WindowModel } from 'wdKit/Index'; | @@ -8,7 +8,7 @@ import { Logger, WindowModel } from 'wdKit/Index'; | ||
| 8 | import { router, window } from '@kit.ArkUI'; | 8 | import { router, window } from '@kit.ArkUI'; |
| 9 | import { devicePLSensorManager } from 'wdDetailPlayApi/Index'; | 9 | import { devicePLSensorManager } from 'wdDetailPlayApi/Index'; |
| 10 | import { LiveCommentComponent } from 'wdComponent/Index'; | 10 | import { LiveCommentComponent } from 'wdComponent/Index'; |
| 11 | -import { WDPlayerController } from 'wdPlayer/Index'; | 11 | +import { WDAliPlayerController, WDPlayerController } from 'wdPlayer/Index'; |
| 12 | import { OperRowListView } from 'wdComponent/src/main/ets/components/view/OperRowListView'; | 12 | import { OperRowListView } from 'wdComponent/src/main/ets/components/view/OperRowListView'; |
| 13 | import { publishCommentModel } from 'wdComponent/src/main/ets/components/comment/model/PublishCommentModel'; | 13 | import { publishCommentModel } from 'wdComponent/src/main/ets/components/comment/model/PublishCommentModel'; |
| 14 | import { ResponseDTO } from 'wdNetwork/Index'; | 14 | import { ResponseDTO } from 'wdNetwork/Index'; |
| @@ -19,7 +19,7 @@ let TAG: string = 'DetailPlayLivePage'; | @@ -19,7 +19,7 @@ let TAG: string = 'DetailPlayLivePage'; | ||
| 19 | export struct DetailPlayLivePage { | 19 | export struct DetailPlayLivePage { |
| 20 | //横竖屏,默认竖屏 | 20 | //横竖屏,默认竖屏 |
| 21 | @Provide displayDirection: DisplayDirection = DisplayDirection.VERTICAL | 21 | @Provide displayDirection: DisplayDirection = DisplayDirection.VERTICAL |
| 22 | - playerController: WDPlayerController = new WDPlayerController(); | 22 | + playerController: WDAliPlayerController = new WDAliPlayerController(); |
| 23 | liveViewModel: LiveViewModel = new LiveViewModel() | 23 | liveViewModel: LiveViewModel = new LiveViewModel() |
| 24 | @State relId: string = '' | 24 | @State relId: string = '' |
| 25 | @State contentId: string = '' | 25 | @State contentId: string = '' |
| @@ -4,7 +4,7 @@ import router from '@ohos.router'; | @@ -4,7 +4,7 @@ import router from '@ohos.router'; | ||
| 4 | import { WindowModel } from 'wdKit/Index'; | 4 | import { WindowModel } from 'wdKit/Index'; |
| 5 | import { PlayerComponent } from '../widgets/vertical/PlayerComponent'; | 5 | import { PlayerComponent } from '../widgets/vertical/PlayerComponent'; |
| 6 | import { PlayerInfoComponent } from '../widgets/vertical/PlayerInfoComponent'; | 6 | import { PlayerInfoComponent } from '../widgets/vertical/PlayerInfoComponent'; |
| 7 | -import { WDPlayerController } from 'wdPlayer/Index'; | 7 | +import { WDAliPlayerController, WDPlayerController } from 'wdPlayer/Index'; |
| 8 | import { DisplayDirection } from 'wdConstant/Index'; | 8 | import { DisplayDirection } from 'wdConstant/Index'; |
| 9 | import { LiveEmptyComponent, WDLiveViewDefaultType } from 'wdComponent/Index'; | 9 | import { LiveEmptyComponent, WDLiveViewDefaultType } from 'wdComponent/Index'; |
| 10 | import { PlayerEndView } from '../widgets/vertical/PlayerEndView'; | 10 | import { PlayerEndView } from '../widgets/vertical/PlayerEndView'; |
| @@ -16,7 +16,7 @@ const TAG = 'DetailPlayVLivePage' | @@ -16,7 +16,7 @@ const TAG = 'DetailPlayVLivePage' | ||
| 16 | @Component | 16 | @Component |
| 17 | export struct DetailPlayVLivePage { | 17 | export struct DetailPlayVLivePage { |
| 18 | private liveViewModel: LiveViewModel = new LiveViewModel() | 18 | private liveViewModel: LiveViewModel = new LiveViewModel() |
| 19 | - private playerController: WDPlayerController = new WDPlayerController(); | 19 | + private playerController: WDAliPlayerController = new WDAliPlayerController(); |
| 20 | private swiperController: SwiperController = new SwiperController() | 20 | private swiperController: SwiperController = new SwiperController() |
| 21 | @Provide bottomSafeHeight: number = AppStorage.get<number>('bottomSafeHeight') || 0 | 21 | @Provide bottomSafeHeight: number = AppStorage.get<number>('bottomSafeHeight') || 0 |
| 22 | @Provide topSafeHeight: number = AppStorage.get<number>('topSafeHeight') || 0 | 22 | @Provide topSafeHeight: number = AppStorage.get<number>('topSafeHeight') || 0 |
| @@ -2,14 +2,14 @@ import { window } from '@kit.ArkUI' | @@ -2,14 +2,14 @@ import { window } from '@kit.ArkUI' | ||
| 2 | import lottie from '@ohos/lottie'; | 2 | import lottie from '@ohos/lottie'; |
| 3 | 3 | ||
| 4 | import { NumberFormatterUtils, StringUtils, WindowModel } from 'wdKit/Index' | 4 | import { NumberFormatterUtils, StringUtils, WindowModel } from 'wdKit/Index' |
| 5 | -import { DateFormatUtil, WDPlayerController } from 'wdPlayer/Index' | 5 | +import { DateFormatUtil, WDAliPlayerController, WDPlayerController } from 'wdPlayer/Index' |
| 6 | import { LiveDetailsBean, LiveRoomDataBean } from 'wdBean/Index' | 6 | import { LiveDetailsBean, LiveRoomDataBean } from 'wdBean/Index' |
| 7 | import { DisplayDirection } from 'wdConstant/Index' | 7 | import { DisplayDirection } from 'wdConstant/Index' |
| 8 | import { LiveFollowComponent, LottieView } from 'wdComponent/Index' | 8 | import { LiveFollowComponent, LottieView } from 'wdComponent/Index' |
| 9 | 9 | ||
| 10 | @Component | 10 | @Component |
| 11 | export struct PlayUIComponent { | 11 | export struct PlayUIComponent { |
| 12 | - playerController: WDPlayerController = new WDPlayerController(); | 12 | + playerController?: WDAliPlayerController; |
| 13 | //菜单键是否可见 | 13 | //菜单键是否可见 |
| 14 | @State @Watch('onChangeMenuVisible') isMenuVisible: boolean = true | 14 | @State @Watch('onChangeMenuVisible') isMenuVisible: boolean = true |
| 15 | @Consume liveDetailsBean: LiveDetailsBean | 15 | @Consume liveDetailsBean: LiveDetailsBean |
| @@ -39,12 +39,14 @@ export struct PlayUIComponent { | @@ -39,12 +39,14 @@ export struct PlayUIComponent { | ||
| 39 | aboutToAppear(): void { | 39 | aboutToAppear(): void { |
| 40 | this.onChangeMenuVisible() | 40 | this.onChangeMenuVisible() |
| 41 | //播放进度监听 | 41 | //播放进度监听 |
| 42 | + if (this.playerController) { | ||
| 42 | this.playerController.onTimeUpdate = (position: number, duration: number) => { | 43 | this.playerController.onTimeUpdate = (position: number, duration: number) => { |
| 43 | this.currentTime = DateFormatUtil.secondToTime(Math.floor(position / 1000)); | 44 | this.currentTime = DateFormatUtil.secondToTime(Math.floor(position / 1000)); |
| 44 | this.totalTime = DateFormatUtil.secondToTime(Math.floor(duration / 1000)); | 45 | this.totalTime = DateFormatUtil.secondToTime(Math.floor(duration / 1000)); |
| 45 | this.progressVal = Math.floor(position * 100 / duration); | 46 | this.progressVal = Math.floor(position * 100 / duration); |
| 46 | } | 47 | } |
| 47 | } | 48 | } |
| 49 | + } | ||
| 48 | 50 | ||
| 49 | aboutToDisappear(): void { | 51 | aboutToDisappear(): void { |
| 50 | if (this.liveDetailsBean.liveInfo?.liveState == 'running') { | 52 | if (this.liveDetailsBean.liveInfo?.liveState == 'running') { |
| @@ -312,10 +314,10 @@ export struct PlayUIComponent { | @@ -312,10 +314,10 @@ export struct PlayUIComponent { | ||
| 312 | .onClick(() => { | 314 | .onClick(() => { |
| 313 | if (this.isPlayStatus) { | 315 | if (this.isPlayStatus) { |
| 314 | this.isPlayStatus = false | 316 | this.isPlayStatus = false |
| 315 | - this.playerController.pause() | 317 | + this.playerController?.pause() |
| 316 | } else { | 318 | } else { |
| 317 | this.isPlayStatus = true | 319 | this.isPlayStatus = true |
| 318 | - this.playerController.play() | 320 | + this.playerController?.play() |
| 319 | } | 321 | } |
| 320 | }) | 322 | }) |
| 321 | } | 323 | } |
| 1 | import { LiveDetailsBean } from 'wdBean/Index'; | 1 | import { LiveDetailsBean } from 'wdBean/Index'; |
| 2 | import { StringUtils } from 'wdKit/Index'; | 2 | import { StringUtils } from 'wdKit/Index'; |
| 3 | -import { WDPlayerController, WDPlayerRenderLiveView } from 'wdPlayer/Index'; | 3 | +import { WDAliPlayerController, WDPlayerController, WDPlayerRenderLiveView } from 'wdPlayer/Index'; |
| 4 | import { PlayUIComponent } from './PlayUIComponent'; | 4 | import { PlayUIComponent } from './PlayUIComponent'; |
| 5 | import { Logger } from 'wdKit/Index'; | 5 | import { Logger } from 'wdKit/Index'; |
| 6 | 6 | ||
| @@ -10,12 +10,14 @@ const TAG: string = 'TopPlayComponent' | @@ -10,12 +10,14 @@ const TAG: string = 'TopPlayComponent' | ||
| 10 | @Component | 10 | @Component |
| 11 | export struct TopPlayComponent { | 11 | export struct TopPlayComponent { |
| 12 | @Consume @Watch('updateData') liveDetailsBean: LiveDetailsBean | 12 | @Consume @Watch('updateData') liveDetailsBean: LiveDetailsBean |
| 13 | - playerController?: WDPlayerController | 13 | + playerController?: WDAliPlayerController |
| 14 | @State imgUrl: string = '' | 14 | @State imgUrl: string = '' |
| 15 | //未开始 | 15 | //未开始 |
| 16 | @State isWait: boolean = false | 16 | @State isWait: boolean = false |
| 17 | //已结束直播 | 17 | //已结束直播 |
| 18 | @State isEnd: boolean = false | 18 | @State isEnd: boolean = false |
| 19 | + private playUrl: string = "" | ||
| 20 | + private xComponentIsLoaded: boolean = false | ||
| 19 | 21 | ||
| 20 | aboutToAppear(): void { | 22 | aboutToAppear(): void { |
| 21 | if (this.playerController) { | 23 | if (this.playerController) { |
| @@ -49,16 +51,31 @@ export struct TopPlayComponent { | @@ -49,16 +51,31 @@ export struct TopPlayComponent { | ||
| 49 | // this.playerController?.firstPlay('https://rmrbcmsonline.peopleapp.com/upload/rmh/video/mp4/202404/1713752415708fb81d0b8f137b.mp4'); | 51 | // this.playerController?.firstPlay('https://rmrbcmsonline.peopleapp.com/upload/rmh/video/mp4/202404/1713752415708fb81d0b8f137b.mp4'); |
| 50 | if (StringUtils.isNotEmpty(playUrl)) { | 52 | if (StringUtils.isNotEmpty(playUrl)) { |
| 51 | Logger.debug(TAG, `${playUrl}`) | 53 | Logger.debug(TAG, `${playUrl}`) |
| 52 | - this.playerController?.firstPlay(playUrl); | 54 | + this.playUrl = playUrl |
| 55 | + this.tryToPlay() | ||
| 53 | } | 56 | } |
| 54 | } | 57 | } |
| 55 | } | 58 | } |
| 56 | 59 | ||
| 60 | + tryToPlay() { | ||
| 61 | + if (!this.xComponentIsLoaded) { | ||
| 62 | + Logger.debug(TAG, "需要xComponent加载完成") | ||
| 63 | + return | ||
| 64 | + } | ||
| 65 | + if (this.playUrl.length == 0) { | ||
| 66 | + Logger.debug(TAG, "播放地址为空") | ||
| 67 | + return | ||
| 68 | + } | ||
| 69 | + this.playerController?.firstPlay(this.playUrl); | ||
| 70 | + } | ||
| 71 | + | ||
| 57 | build() { | 72 | build() { |
| 58 | Stack() { | 73 | Stack() { |
| 59 | WDPlayerRenderLiveView({ | 74 | WDPlayerRenderLiveView({ |
| 60 | playerController: this.playerController, | 75 | playerController: this.playerController, |
| 61 | onLoad: async () => { | 76 | onLoad: async () => { |
| 77 | + this.xComponentIsLoaded = true | ||
| 78 | + this.tryToPlay() | ||
| 62 | } | 79 | } |
| 63 | }) | 80 | }) |
| 64 | .height('100%') | 81 | .height('100%') |
| 1 | import { LiveDetailsBean } from 'wdBean/Index'; | 1 | import { LiveDetailsBean } from 'wdBean/Index'; |
| 2 | -import { WDPlayerController, WDPlayerRenderVLiveView, WDPlayerRenderView } from 'wdPlayer/Index'; | 2 | +import { WDPlayerController, WDPlayerRenderVLiveView, WDPlayerRenderView, WDAliPlayerController, |
| 3 | + AliPlayerRenderView } from 'wdPlayer/Index'; | ||
| 3 | import { PictureLoading } from './PictureLoading'; | 4 | import { PictureLoading } from './PictureLoading'; |
| 4 | 5 | ||
| 5 | const TAG = 'PlayerComponent' | 6 | const TAG = 'PlayerComponent' |
| 6 | 7 | ||
| 7 | @Component | 8 | @Component |
| 8 | export struct PlayerComponent { | 9 | export struct PlayerComponent { |
| 9 | - @Prop playerController: WDPlayerController; | 10 | + @Prop playerController: WDAliPlayerController; |
| 10 | @Consume @Watch('updateData') liveDetailsBean: LiveDetailsBean | 11 | @Consume @Watch('updateData') liveDetailsBean: LiveDetailsBean |
| 11 | @Consume @Watch('pageShowChange') pageShow: number | 12 | @Consume @Watch('pageShowChange') pageShow: number |
| 12 | @Consume @Watch('pageHideChange') pageHide: number | 13 | @Consume @Watch('pageHideChange') pageHide: number |
| @@ -78,7 +79,7 @@ export struct PlayerComponent { | @@ -78,7 +79,7 @@ export struct PlayerComponent { | ||
| 78 | } | 79 | } |
| 79 | }) | 80 | }) |
| 80 | } else if (this.liveStreamType == 0) { | 81 | } else if (this.liveStreamType == 0) { |
| 81 | - WDPlayerRenderView({ | 82 | + AliPlayerRenderView({ |
| 82 | playerController: this.playerController, | 83 | playerController: this.playerController, |
| 83 | onLoad: () => { | 84 | onLoad: () => { |
| 84 | this.playerController?.firstPlay(this.playUrl); | 85 | this.playerController?.firstPlay(this.playUrl); |
| 1 | -import { WDPlayerController } from 'wdPlayer/Index' | 1 | +import { WDAliPlayerController, WDPlayerController } from 'wdPlayer/Index' |
| 2 | import { PlayerUIComponent } from './PlayerUIComponent' | 2 | import { PlayerUIComponent } from './PlayerUIComponent' |
| 3 | 3 | ||
| 4 | @Component | 4 | @Component |
| 5 | export struct PlayerInfoComponent { | 5 | export struct PlayerInfoComponent { |
| 6 | swiperController?: SwiperController | 6 | swiperController?: SwiperController |
| 7 | - private playerController?: WDPlayerController | 7 | + private playerController?: WDAliPlayerController |
| 8 | @Consume bottomSafeHeight: number | 8 | @Consume bottomSafeHeight: number |
| 9 | @Consume topSafeHeight: number | 9 | @Consume topSafeHeight: number |
| 10 | @Consume liveState: string | 10 | @Consume liveState: string |
| 1 | import { ContentDetailDTO } from 'wdBean/Index'; | 1 | import { ContentDetailDTO } from 'wdBean/Index'; |
| 2 | -import { WDPlayerController } from 'wdPlayer/Index'; | 2 | +import { WDAliPlayerController, WDPlayerController } from 'wdPlayer/Index'; |
| 3 | import { PlayerCommentComponent } from './PlayerCommentComponent'; | 3 | import { PlayerCommentComponent } from './PlayerCommentComponent'; |
| 4 | import { PlayerTitleComponent } from './PlayerTitleComponent'; | 4 | import { PlayerTitleComponent } from './PlayerTitleComponent'; |
| 5 | import { PlayerVideoControlComponent } from './PlayerVideoControlComponent'; | 5 | import { PlayerVideoControlComponent } from './PlayerVideoControlComponent'; |
| 6 | 6 | ||
| 7 | @Component | 7 | @Component |
| 8 | export struct PlayerUIComponent { | 8 | export struct PlayerUIComponent { |
| 9 | - private playerController?: WDPlayerController | 9 | + private playerController?: WDAliPlayerController |
| 10 | @Consume isShowControl: boolean | 10 | @Consume isShowControl: boolean |
| 11 | 11 | ||
| 12 | build() { | 12 | build() { |
| @@ -2,13 +2,13 @@ import { window } from '@kit.ArkUI' | @@ -2,13 +2,13 @@ import { window } from '@kit.ArkUI' | ||
| 2 | import { NumberFormatterUtils, WindowModel } from 'wdKit/Index' | 2 | import { NumberFormatterUtils, WindowModel } from 'wdKit/Index' |
| 3 | 3 | ||
| 4 | import { devicePLSensorManager } from 'wdDetailPlayApi/Index' | 4 | import { devicePLSensorManager } from 'wdDetailPlayApi/Index' |
| 5 | -import { DateFormatUtil, WDPlayerController } from 'wdPlayer/Index' | 5 | +import { DateFormatUtil, WDAliPlayerController, WDPlayerController } from 'wdPlayer/Index' |
| 6 | import { LiveDetailsBean, LiveRoomDataBean } from 'wdBean/Index' | 6 | import { LiveDetailsBean, LiveRoomDataBean } from 'wdBean/Index' |
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | @Component | 9 | @Component |
| 10 | export struct PlayerVideoControlComponent { | 10 | export struct PlayerVideoControlComponent { |
| 11 | - private playerController?: WDPlayerController | 11 | + private playerController?: WDAliPlayerController |
| 12 | @Consume liveDetailsBean: LiveDetailsBean | 12 | @Consume liveDetailsBean: LiveDetailsBean |
| 13 | @Consume liveRoomDataBean: LiveRoomDataBean | 13 | @Consume liveRoomDataBean: LiveRoomDataBean |
| 14 | @State currentTime: string = '' | 14 | @State currentTime: string = '' |
| @@ -15,3 +15,5 @@ export { DateFormatUtil } from "./src/main/ets/utils/DateFormatUtil" | @@ -15,3 +15,5 @@ export { DateFormatUtil } from "./src/main/ets/utils/DateFormatUtil" | ||
| 15 | export { WDAliPlayerController } from "./src/main/ets/controller/WDAliPlayerController" | 15 | export { WDAliPlayerController } from "./src/main/ets/controller/WDAliPlayerController" |
| 16 | 16 | ||
| 17 | export { WDListPlayerData, WDAliListPlayerController } from "./src/main/ets/controller/WDAliListPlayerController" | 17 | export { WDListPlayerData, WDAliListPlayerController } from "./src/main/ets/controller/WDAliListPlayerController" |
| 18 | + | ||
| 19 | +export { AliPlayerRenderView } from "./src/main/ets/pages/AliPlayerRenderView" |
| @@ -11,8 +11,10 @@ import { | @@ -11,8 +11,10 @@ import { | ||
| 11 | 11 | ||
| 12 | import { initGlobalPlayerSettings, setupPlayerConfig } from '../utils/GlobalSetting'; | 12 | import { initGlobalPlayerSettings, setupPlayerConfig } from '../utils/GlobalSetting'; |
| 13 | import prompt from '@ohos.promptAction'; | 13 | import prompt from '@ohos.promptAction'; |
| 14 | -import { Logger } from '../utils/Logger'; | ||
| 15 | import { PlayerConstants, AVPlayerStatus, Events } from '../constants/PlayerConstants'; | 14 | import { PlayerConstants, AVPlayerStatus, Events } from '../constants/PlayerConstants'; |
| 15 | +import { Logger } from 'wdKit/Index'; | ||
| 16 | + | ||
| 17 | +const TAG = "WDAliPlayerController" | ||
| 16 | 18 | ||
| 17 | /* | 19 | /* |
| 18 | * 此播放器为阿里播放器鸿蒙版本封装,可播放单个视频、或直播 | 20 | * 此播放器为阿里播放器鸿蒙版本封装,可播放单个视频、或直播 |
| @@ -54,7 +56,7 @@ export class WDAliPlayerController { | @@ -54,7 +56,7 @@ export class WDAliPlayerController { | ||
| 54 | public onFirstFrameDisplay?: () => void | 56 | public onFirstFrameDisplay?: () => void |
| 55 | 57 | ||
| 56 | constructor() { | 58 | constructor() { |
| 57 | - Logger.info("初始化") | 59 | + Logger.info(TAG, "初始化") |
| 58 | initGlobalPlayerSettings() | 60 | initGlobalPlayerSettings() |
| 59 | this.initPromise = this.createAVPlayer(); | 61 | this.initPromise = this.createAVPlayer(); |
| 60 | } | 62 | } |
| @@ -64,24 +66,24 @@ export class WDAliPlayerController { | @@ -64,24 +66,24 @@ export class WDAliPlayerController { | ||
| 64 | */ | 66 | */ |
| 65 | private createAVPlayer(): Promise<void> { | 67 | private createAVPlayer(): Promise<void> { |
| 66 | return new Promise((resolve, reject) => { | 68 | return new Promise((resolve, reject) => { |
| 67 | - Logger.debug("开始创建") | 69 | + Logger.debug(TAG, "开始创建") |
| 68 | let traceId = '' | 70 | let traceId = '' |
| 69 | this.avPlayer = AliPlayerFactory.createAliPlayer(getContext(), traceId) | 71 | this.avPlayer = AliPlayerFactory.createAliPlayer(getContext(), traceId) |
| 70 | if (this.avPlayer) { | 72 | if (this.avPlayer) { |
| 71 | - Logger.debug("创建完成1") | 73 | + Logger.debug(TAG, "创建完成1") |
| 72 | setupPlayerConfig(this.avPlayer!) | 74 | setupPlayerConfig(this.avPlayer!) |
| 73 | this.bindState(); | 75 | this.bindState(); |
| 74 | resolve(); | 76 | resolve(); |
| 75 | } else { | 77 | } else { |
| 76 | - Logger.error("创建完成0") | ||
| 77 | - Logger.error('[WDPlayerController] createAvPlayer fail!'); | 78 | + Logger.error(TAG, "创建完成0") |
| 79 | + Logger.error(TAG, '[WDPlayerController] createAvPlayer fail!'); | ||
| 78 | reject(); | 80 | reject(); |
| 79 | } | 81 | } |
| 80 | }); | 82 | }); |
| 81 | } | 83 | } |
| 82 | 84 | ||
| 83 | public destory() { | 85 | public destory() { |
| 84 | - Logger.debug("播放器销毁") | 86 | + Logger.debug(TAG, "播放器销毁") |
| 85 | this.avPlayer?.stop() | 87 | this.avPlayer?.stop() |
| 86 | this.avPlayer?.release() | 88 | this.avPlayer?.release() |
| 87 | } | 89 | } |
| @@ -94,13 +96,13 @@ export class WDAliPlayerController { | @@ -94,13 +96,13 @@ export class WDAliPlayerController { | ||
| 94 | // 当调用play()方法后,会调用 | 96 | // 当调用play()方法后,会调用 |
| 95 | onPrepared: () => { | 97 | onPrepared: () => { |
| 96 | this.duration = this.avPlayer?.getDuration(); | 98 | this.duration = this.avPlayer?.getDuration(); |
| 97 | - Logger.debug("已准备好", `${this.duration}`) | 99 | + Logger.debug(TAG, "已准备好", `${this.duration}`) |
| 98 | } | 100 | } |
| 99 | } | 101 | } |
| 100 | ); | 102 | ); |
| 101 | this.avPlayer?.setOnRenderingStartListener({ | 103 | this.avPlayer?.setOnRenderingStartListener({ |
| 102 | onRenderingStart: () => { | 104 | onRenderingStart: () => { |
| 103 | - Logger.debug("首帧开始显示") | 105 | + Logger.debug(TAG, "首帧开始显示") |
| 104 | if (this.onFirstFrameDisplay) { | 106 | if (this.onFirstFrameDisplay) { |
| 105 | this.onFirstFrameDisplay() | 107 | this.onFirstFrameDisplay() |
| 106 | } | 108 | } |
| @@ -108,7 +110,7 @@ export class WDAliPlayerController { | @@ -108,7 +110,7 @@ export class WDAliPlayerController { | ||
| 108 | }); | 110 | }); |
| 109 | this.avPlayer?.setOnCompletionListener({ | 111 | this.avPlayer?.setOnCompletionListener({ |
| 110 | onCompletion: () => { | 112 | onCompletion: () => { |
| 111 | - Logger.debug("播放完成") | 113 | + Logger.debug(TAG, "播放完成") |
| 112 | } | 114 | } |
| 113 | }); | 115 | }); |
| 114 | this.avPlayer?.setOnInfoListener({ | 116 | this.avPlayer?.setOnInfoListener({ |
| @@ -116,7 +118,7 @@ export class WDAliPlayerController { | @@ -116,7 +118,7 @@ export class WDAliPlayerController { | ||
| 116 | 118 | ||
| 117 | if (bean.getCode() === InfoCode.CurrentPosition) { | 119 | if (bean.getCode() === InfoCode.CurrentPosition) { |
| 118 | let position : number = bean.getExtraValue() | 120 | let position : number = bean.getExtraValue() |
| 119 | - Logger.debug(`播放进度条:${position}/ ${this.duration}`) | 121 | + Logger.debug(TAG, `播放进度条:${position}/ ${this.duration}`) |
| 120 | this.initProgress(position); | 122 | this.initProgress(position); |
| 121 | 123 | ||
| 122 | } else if (bean.getCode() === InfoCode.BufferedPosition) { | 124 | } else if (bean.getCode() === InfoCode.BufferedPosition) { |
| @@ -126,7 +128,7 @@ export class WDAliPlayerController { | @@ -126,7 +128,7 @@ export class WDAliPlayerController { | ||
| 126 | } | 128 | } |
| 127 | 129 | ||
| 128 | } else if (bean.getCode() === InfoCode.SwitchToSoftwareVideoDecoder) { | 130 | } else if (bean.getCode() === InfoCode.SwitchToSoftwareVideoDecoder) { |
| 129 | - Logger.debug(`DOWNGRADE TO SOFTWARE DECODE`) | 131 | + Logger.debug(TAG, `DOWNGRADE TO SOFTWARE DECODE`) |
| 130 | // this.mSwitchedToSoftListener?.onSwitched(); | 132 | // this.mSwitchedToSoftListener?.onSwitched(); |
| 131 | } | 133 | } |
| 132 | } | 134 | } |
| @@ -134,7 +136,7 @@ export class WDAliPlayerController { | @@ -134,7 +136,7 @@ export class WDAliPlayerController { | ||
| 134 | this.avPlayer?.setOnStateChangedListener({ | 136 | this.avPlayer?.setOnStateChangedListener({ |
| 135 | onStateChanged: (status: number) => { | 137 | onStateChanged: (status: number) => { |
| 136 | this.avPlayerStatus = status | 138 | this.avPlayerStatus = status |
| 137 | - Logger.debug("status update:" + `${this.getStatusStringWith(status)}`) | 139 | + Logger.debug(TAG, "status update:" + `${this.getStatusStringWith(status)}`) |
| 138 | 140 | ||
| 139 | switch (status) { | 141 | switch (status) { |
| 140 | case initalized: { | 142 | case initalized: { |
| @@ -189,7 +191,7 @@ export class WDAliPlayerController { | @@ -189,7 +191,7 @@ export class WDAliPlayerController { | ||
| 189 | }); | 191 | }); |
| 190 | this.avPlayer?.setOnErrorListener({ | 192 | this.avPlayer?.setOnErrorListener({ |
| 191 | onError:(errorInfo) => { | 193 | onError:(errorInfo) => { |
| 192 | - Logger.error("播放错误", JSON.stringify(errorInfo)) | 194 | + Logger.error(TAG, "播放错误", JSON.stringify(errorInfo)) |
| 193 | this.errorCode = errorInfo.getCode() | 195 | this.errorCode = errorInfo.getCode() |
| 194 | this.errorMesage = errorInfo.getMsg() | 196 | this.errorMesage = errorInfo.getMsg() |
| 195 | this.status = PlayerConstants.STATUS_ERROR; | 197 | this.status = PlayerConstants.STATUS_ERROR; |
| @@ -240,16 +242,24 @@ export class WDAliPlayerController { | @@ -240,16 +242,24 @@ export class WDAliPlayerController { | ||
| 240 | 242 | ||
| 241 | setXComponentController(controller: XComponentController) { | 243 | setXComponentController(controller: XComponentController) { |
| 242 | this.setSurfaceId(controller.getXComponentSurfaceId()) | 244 | this.setSurfaceId(controller.getXComponentSurfaceId()) |
| 245 | + if (this.avPlayerStatus > PlayerConstants.STATUS_IDLE) { | ||
| 246 | + Logger.info(TAG, "设置SurfaceId: " + this.surfaceId) | ||
| 247 | + this.avPlayer?.setSurfaceId(this.surfaceId) | ||
| 248 | + } | ||
| 243 | } | 249 | } |
| 244 | 250 | ||
| 245 | setSurfaceId(surfaceId: string) { | 251 | setSurfaceId(surfaceId: string) { |
| 246 | this.surfaceId = surfaceId | 252 | this.surfaceId = surfaceId |
| 253 | + if (this.avPlayerStatus > PlayerConstants.STATUS_IDLE) { | ||
| 254 | + Logger.info(TAG, "设置SurfaceId: " + this.surfaceId) | ||
| 255 | + this.avPlayer?.setSurfaceId(this.surfaceId) | ||
| 256 | + } | ||
| 247 | } | 257 | } |
| 248 | 258 | ||
| 249 | async firstPlay(url: string) { | 259 | async firstPlay(url: string) { |
| 250 | this.url = url; | 260 | this.url = url; |
| 251 | if (this.avPlayer == null) { | 261 | if (this.avPlayer == null) { |
| 252 | - Logger.info("等待播放器初始化") | 262 | + Logger.info(TAG, "等待播放器初始化") |
| 253 | await this.initPromise; | 263 | await this.initPromise; |
| 254 | } else { | 264 | } else { |
| 255 | if (this.avPlayerStatus != idle) { | 265 | if (this.avPlayerStatus != idle) { |
| @@ -269,10 +279,10 @@ export class WDAliPlayerController { | @@ -269,10 +279,10 @@ export class WDAliPlayerController { | ||
| 269 | 279 | ||
| 270 | this.avPlayer?.setAutoPlay(false) | 280 | this.avPlayer?.setAutoPlay(false) |
| 271 | 281 | ||
| 272 | - Logger.debug("开始播放", this.url) | 282 | + Logger.debug(TAG, "开始播放", this.url) |
| 273 | this.setAliPlayerURL(this.url); | 283 | this.setAliPlayerURL(this.url); |
| 274 | 284 | ||
| 275 | - Logger.info("设置SurfaceId" + this.surfaceId) | 285 | + Logger.info(TAG, "设置SurfaceId: " + this.surfaceId) |
| 276 | this.avPlayer?.setSurfaceId(this.surfaceId) | 286 | this.avPlayer?.setSurfaceId(this.surfaceId) |
| 277 | 287 | ||
| 278 | this.avPlayer?.prepare() | 288 | this.avPlayer?.prepare() |
| @@ -287,17 +297,17 @@ export class WDAliPlayerController { | @@ -287,17 +297,17 @@ export class WDAliPlayerController { | ||
| 287 | } | 297 | } |
| 288 | 298 | ||
| 289 | pause() { | 299 | pause() { |
| 290 | - Logger.debug("暂停", this.url) | 300 | + Logger.debug(TAG, "暂停", this.url) |
| 291 | this.avPlayer?.pause(); | 301 | this.avPlayer?.pause(); |
| 292 | } | 302 | } |
| 293 | 303 | ||
| 294 | play() { | 304 | play() { |
| 295 | - Logger.debug("播放", this.url) | 305 | + Logger.debug(TAG, "播放", this.url) |
| 296 | this.avPlayer?.start(); | 306 | this.avPlayer?.start(); |
| 297 | } | 307 | } |
| 298 | 308 | ||
| 299 | stop() { | 309 | stop() { |
| 300 | - Logger.debug("停止", this.url) | 310 | + Logger.debug(TAG, "停止", this.url) |
| 301 | this.avPlayer?.stop(); | 311 | this.avPlayer?.stop(); |
| 302 | } | 312 | } |
| 303 | 313 | ||
| @@ -405,7 +415,7 @@ export class WDAliPlayerController { | @@ -405,7 +415,7 @@ export class WDAliPlayerController { | ||
| 405 | if (this.onVolumeUpdate) { | 415 | if (this.onVolumeUpdate) { |
| 406 | this.onVolumeUpdate(this.volume); | 416 | this.onVolumeUpdate(this.volume); |
| 407 | } | 417 | } |
| 408 | - console.log("volume : " + this.volume) | 418 | + Logger.debug(TAG, "volume : " + this.volume) |
| 409 | } | 419 | } |
| 410 | 420 | ||
| 411 | onBrightActionUpdate(event: GestureEvent) { | 421 | onBrightActionUpdate(event: GestureEvent) { |
| @@ -429,7 +439,7 @@ export class WDAliPlayerController { | @@ -429,7 +439,7 @@ export class WDAliPlayerController { | ||
| 429 | } | 439 | } |
| 430 | 440 | ||
| 431 | watchStatus() { | 441 | watchStatus() { |
| 432 | - console.log('watchStatus', this.status) | 442 | + Logger.debug(TAG, 'watchStatus: ' + this.status) |
| 433 | if (this.onStatusChange) { | 443 | if (this.onStatusChange) { |
| 434 | this.onStatusChange(this.status) | 444 | this.onStatusChange(this.status) |
| 435 | } | 445 | } |
| 1 | +import componentUtils from '@ohos.arkui.componentUtils'; | ||
| 2 | +import { WDPlayerController } from '../controller/WDPlayerController' | ||
| 3 | +import { WindowModel } from 'wdKit'; | ||
| 4 | +import { Logger } from '../utils/Logger'; | ||
| 5 | +import { enableAliPlayer } from '../utils/GlobalSetting'; | ||
| 6 | +import { WDAliPlayerController } from '../controller/WDAliPlayerController'; | ||
| 7 | + | ||
| 8 | +class Size { | ||
| 9 | + width: Length = "100%"; | ||
| 10 | + height: Length = "100%"; | ||
| 11 | + | ||
| 12 | + constructor(width: Length, height: Length) { | ||
| 13 | + this.width = width; | ||
| 14 | + this.height = height; | ||
| 15 | + } | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +let insIndex: number = 0; | ||
| 19 | +const TAG = 'AliPlayerRenderView' | ||
| 20 | + | ||
| 21 | +class MGPlayRenderViewIns { | ||
| 22 | + static intCount: number = 0; | ||
| 23 | + | ||
| 24 | + static add() { | ||
| 25 | + MGPlayRenderViewIns.intCount++; | ||
| 26 | + WindowModel.shared.setWindowKeepScreenOn(true); | ||
| 27 | + console.log("add-- +1") | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + static del() { | ||
| 31 | + console.log("del-- -1") | ||
| 32 | + MGPlayRenderViewIns.intCount--; | ||
| 33 | + if (MGPlayRenderViewIns.intCount <= 0) { | ||
| 34 | + WindowModel.shared.setWindowKeepScreenOn(false); | ||
| 35 | + } | ||
| 36 | + } | ||
| 37 | +} | ||
| 38 | + | ||
| 39 | +/** | ||
| 40 | + * 播放窗口组件,对接阿里播放器的RenderView | ||
| 41 | + */ | ||
| 42 | +@Component | ||
| 43 | +export struct AliPlayerRenderView { | ||
| 44 | + private playerController?: WDAliPlayerController; | ||
| 45 | + private xComponentController: XComponentController = new XComponentController(); | ||
| 46 | + private insId: string = "AliPlayerRenderView" + insIndex; | ||
| 47 | + onLoad?: ((event?: object) => void); | ||
| 48 | + @State videoWidth: number = 16 | ||
| 49 | + @State videoHeight: number = 9 | ||
| 50 | + @State videoRatio: number = 16 / 9 | ||
| 51 | + @State selfSize: Size = new Size('100%', '100%'); | ||
| 52 | + private enableAliPlayer = true | ||
| 53 | + | ||
| 54 | + aboutToAppear() { | ||
| 55 | + MGPlayRenderViewIns.add(); | ||
| 56 | + | ||
| 57 | + insIndex++; | ||
| 58 | + if (!this.playerController) { | ||
| 59 | + return | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + this.playerController.onVideoSizeChange = (width: number, height: number) => { | ||
| 63 | + // console.log(`WDPlayerRenderView onVideoSizeChange width:${width} videoTop:${height}`) | ||
| 64 | + Logger.info(TAG, ` onVideoSizeChange width:${width} videoTop:${height}`) | ||
| 65 | + this.videoWidth = width; | ||
| 66 | + this.videoHeight = height; | ||
| 67 | + this.videoRatio = width / height | ||
| 68 | + this.updateLayout() | ||
| 69 | + } | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + aboutToDisappear() { | ||
| 73 | + Logger.info(TAG, `aboutToDisappear`) | ||
| 74 | + MGPlayRenderViewIns.del(); | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + build() { | ||
| 78 | + Row() { | ||
| 79 | + // 设置为“surface“类型时XComponent组件可以和其他组件一起进行布局和渲染。 | ||
| 80 | + XComponent({ | ||
| 81 | + id: this.insId, | ||
| 82 | + type: XComponentType.SURFACE, | ||
| 83 | + libraryname: enableAliPlayer && this.enableAliPlayer ? "premierlibrary" : undefined, | ||
| 84 | + controller: this.xComponentController | ||
| 85 | + }) | ||
| 86 | + .onLoad(async (event) => { | ||
| 87 | + Logger.info(TAG, 'onLoad') | ||
| 88 | + this.xComponentController.setXComponentSurfaceSize({ | ||
| 89 | + surfaceWidth: 1920, | ||
| 90 | + surfaceHeight: 1080 | ||
| 91 | + }); | ||
| 92 | + if (enableAliPlayer && this.enableAliPlayer) { | ||
| 93 | + this.playerController?.setSurfaceId(this.insId) | ||
| 94 | + } else { | ||
| 95 | + this.playerController?.setXComponentController(this.xComponentController) | ||
| 96 | + } | ||
| 97 | + if (this.onLoad) { | ||
| 98 | + this.onLoad(event) | ||
| 99 | + } | ||
| 100 | + }) | ||
| 101 | + .zIndex(1000) | ||
| 102 | + .width(this.selfSize.width) | ||
| 103 | + .height(this.selfSize.height) | ||
| 104 | + } | ||
| 105 | + .onAreaChange(() => { | ||
| 106 | + this.updateLayout() | ||
| 107 | + }) | ||
| 108 | + .backgroundColor("#000000") | ||
| 109 | + .justifyContent(FlexAlign.Center) | ||
| 110 | + .height('100%') | ||
| 111 | + .width('100%') | ||
| 112 | + .align(this.videoWidth > this.videoHeight ? Alignment.Top : Alignment.Center) | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + updateLayout() { | ||
| 116 | + let info = componentUtils.getRectangleById(this.insId); | ||
| 117 | + if (info.size.width > 0 && info.size.height > 0 && this.videoHeight > 0 && this.videoWidth > 0) { | ||
| 118 | + if (info.size.width / info.size.height > this.videoWidth / this.videoHeight) { | ||
| 119 | + let scale = info.size.height / this.videoHeight; | ||
| 120 | + this.selfSize = new Size((this.videoWidth * scale / info.size.width) * 100 + "%", '100%'); | ||
| 121 | + } else { | ||
| 122 | + let scale = info.size.width / this.videoWidth; | ||
| 123 | + this.selfSize = new Size('100%', (this.videoHeight * scale / info.size.height) * 100 + "%"); | ||
| 124 | + } | ||
| 125 | + } | ||
| 126 | + } | ||
| 127 | +} |
| @@ -3,6 +3,7 @@ import { WDPlayerController } from '../controller/WDPlayerController' | @@ -3,6 +3,7 @@ import { WDPlayerController } from '../controller/WDPlayerController' | ||
| 3 | import { WindowModel } from 'wdKit'; | 3 | import { WindowModel } from 'wdKit'; |
| 4 | import { Logger } from '../utils/Logger'; | 4 | import { Logger } from '../utils/Logger'; |
| 5 | import { enableAliPlayer } from '../utils/GlobalSetting'; | 5 | import { enableAliPlayer } from '../utils/GlobalSetting'; |
| 6 | +import { WDAliPlayerController } from '../controller/WDAliPlayerController'; | ||
| 6 | 7 | ||
| 7 | class Size { | 8 | class Size { |
| 8 | width: Length = "100%"; | 9 | width: Length = "100%"; |
| @@ -40,7 +41,7 @@ class MGPlayRenderViewIns { | @@ -40,7 +41,7 @@ class MGPlayRenderViewIns { | ||
| 40 | */ | 41 | */ |
| 41 | @Component | 42 | @Component |
| 42 | export struct WDPlayerRenderLiveView { | 43 | export struct WDPlayerRenderLiveView { |
| 43 | - private playerController?: WDPlayerController; | 44 | + private playerController?: WDAliPlayerController; |
| 44 | private xComponentController: XComponentController = new XComponentController(); | 45 | private xComponentController: XComponentController = new XComponentController(); |
| 45 | onLoad?: ((event?: object) => void); | 46 | onLoad?: ((event?: object) => void); |
| 46 | videoWidth: number = 0 | 47 | videoWidth: number = 0 |
| @@ -3,6 +3,7 @@ import { WDPlayerController } from '../controller/WDPlayerController' | @@ -3,6 +3,7 @@ import { WDPlayerController } from '../controller/WDPlayerController' | ||
| 3 | import { WindowModel } from 'wdKit'; | 3 | import { WindowModel } from 'wdKit'; |
| 4 | import { Logger } from '../utils/Logger'; | 4 | import { Logger } from '../utils/Logger'; |
| 5 | import { enableAliPlayer } from '../utils/GlobalSetting'; | 5 | import { enableAliPlayer } from '../utils/GlobalSetting'; |
| 6 | +import { WDAliPlayerController } from '../controller/WDAliPlayerController'; | ||
| 6 | 7 | ||
| 7 | class Size { | 8 | class Size { |
| 8 | width: Length = "100%"; | 9 | width: Length = "100%"; |
| @@ -40,7 +41,7 @@ class MGPlayRenderViewIns { | @@ -40,7 +41,7 @@ class MGPlayRenderViewIns { | ||
| 40 | */ | 41 | */ |
| 41 | @Component | 42 | @Component |
| 42 | export struct WDPlayerRenderVLiveView { | 43 | export struct WDPlayerRenderVLiveView { |
| 43 | - private playerController?: WDPlayerController; | 44 | + private playerController?: WDAliPlayerController; |
| 44 | private xComponentController: XComponentController = new XComponentController(); | 45 | private xComponentController: XComponentController = new XComponentController(); |
| 45 | private insId: string = "WDPlayRenderView" + insIndex; | 46 | private insId: string = "WDPlayRenderView" + insIndex; |
| 46 | onLoad?: ((event?: object) => void); | 47 | onLoad?: ((event?: object) => void); |
| @@ -48,6 +48,7 @@ export struct WDPlayerRenderView { | @@ -48,6 +48,7 @@ export struct WDPlayerRenderView { | ||
| 48 | @State videoHeight: number = 9 | 48 | @State videoHeight: number = 9 |
| 49 | @State videoRatio: number = 16 / 9 | 49 | @State videoRatio: number = 16 / 9 |
| 50 | @State selfSize: Size = new Size('100%', '100%'); | 50 | @State selfSize: Size = new Size('100%', '100%'); |
| 51 | + private enableAliPlayer = false | ||
| 51 | 52 | ||
| 52 | aboutToAppear() { | 53 | aboutToAppear() { |
| 53 | MGPlayRenderViewIns.add(); | 54 | MGPlayRenderViewIns.add(); |
| @@ -78,7 +79,7 @@ export struct WDPlayerRenderView { | @@ -78,7 +79,7 @@ export struct WDPlayerRenderView { | ||
| 78 | XComponent({ | 79 | XComponent({ |
| 79 | id: this.insId, | 80 | id: this.insId, |
| 80 | type: XComponentType.SURFACE, | 81 | type: XComponentType.SURFACE, |
| 81 | - libraryname: enableAliPlayer ? "premierlibrary" : undefined, | 82 | + libraryname: enableAliPlayer && this.enableAliPlayer ? "premierlibrary" : undefined, |
| 82 | controller: this.xComponentController | 83 | controller: this.xComponentController |
| 83 | }) | 84 | }) |
| 84 | .onLoad(async (event) => { | 85 | .onLoad(async (event) => { |
| @@ -87,7 +88,7 @@ export struct WDPlayerRenderView { | @@ -87,7 +88,7 @@ export struct WDPlayerRenderView { | ||
| 87 | surfaceWidth: 1920, | 88 | surfaceWidth: 1920, |
| 88 | surfaceHeight: 1080 | 89 | surfaceHeight: 1080 |
| 89 | }); | 90 | }); |
| 90 | - if (enableAliPlayer) { | 91 | + if (enableAliPlayer && this.enableAliPlayer) { |
| 91 | this.playerController?.setSurfaceId(this.insId) | 92 | this.playerController?.setSurfaceId(this.insId) |
| 92 | } else { | 93 | } else { |
| 93 | this.playerController?.setXComponentController(this.xComponentController) | 94 | this.playerController?.setXComponentController(this.xComponentController) |
| @@ -43,4 +43,4 @@ export function setupPlayerConfig(player: AliPlayer) { | @@ -43,4 +43,4 @@ export function setupPlayerConfig(player: AliPlayer) { | ||
| 43 | * 3、WDAliListPlayerController 暂时由于SDK问题,不能使用 | 43 | * 3、WDAliListPlayerController 暂时由于SDK问题,不能使用 |
| 44 | * 4、 | 44 | * 4、 |
| 45 | * */ | 45 | * */ |
| 46 | -export const enableAliPlayer = false | ||
| 46 | +export const enableAliPlayer = true |
-
Please register or login to post a comment