Showing
14 changed files
with
186 additions
and
49 deletions
| @@ -32,6 +32,11 @@ export class HttpUrlUtils { | @@ -32,6 +32,11 @@ export class HttpUrlUtils { | ||
| 32 | * 详情页面详情接口 | 32 | * 详情页面详情接口 |
| 33 | */ | 33 | */ |
| 34 | static readonly DETAIL_PATH: string = "/api/rmrb-bff-display-zh/content/zh/c/content/detail"; | 34 | static readonly DETAIL_PATH: string = "/api/rmrb-bff-display-zh/content/zh/c/content/detail"; |
| 35 | + | ||
| 36 | + /** | ||
| 37 | + * 获取视频直播间拉流地址 | ||
| 38 | + */ | ||
| 39 | + static readonly PULL_STREAM_PATH: string = "/api/live-center-video/zh/c/vlive/pull-stream/"; | ||
| 35 | /** | 40 | /** |
| 36 | * 批查接口,查询互动相关数据,如收藏数、评论数等 | 41 | * 批查接口,查询互动相关数据,如收藏数、评论数等 |
| 37 | */ | 42 | */ |
| @@ -70,6 +70,8 @@ export { NewspaperTimeItemBean } from './src/main/ets/bean/newspaper/NewspaperTi | @@ -70,6 +70,8 @@ export { NewspaperTimeItemBean } from './src/main/ets/bean/newspaper/NewspaperTi | ||
| 70 | 70 | ||
| 71 | export { ContentDetailDTO } from './src/main/ets/bean/detail/ContentDetailDTO'; | 71 | export { ContentDetailDTO } from './src/main/ets/bean/detail/ContentDetailDTO'; |
| 72 | 72 | ||
| 73 | +export { GetPullAddressBean } from './src/main/ets/bean/live/GetPullAddressBean'; | ||
| 74 | + | ||
| 73 | export { RmhInfoDTO } from './src/main/ets/bean/detail/RmhInfoDTO'; | 75 | export { RmhInfoDTO } from './src/main/ets/bean/detail/RmhInfoDTO'; |
| 74 | 76 | ||
| 75 | export { UserInfoDTO } from './src/main/ets/bean/detail/UserInfoDTO'; | 77 | export { UserInfoDTO } from './src/main/ets/bean/detail/UserInfoDTO'; |
| @@ -19,4 +19,9 @@ export interface RmhInfoDTO { | @@ -19,4 +19,9 @@ export interface RmhInfoDTO { | ||
| 19 | userId: string; | 19 | userId: string; |
| 20 | userType: string; | 20 | userType: string; |
| 21 | honoraryIcon:string; | 21 | honoraryIcon:string; |
| 22 | + | ||
| 23 | + /** | ||
| 24 | + * 发布标识,0-cms;1-表示号主发布 | ||
| 25 | + */ | ||
| 26 | + rmhPlatform:number | ||
| 22 | } | 27 | } |
| 1 | +/** | ||
| 2 | + * 获取拉流地址解析类 | ||
| 3 | + */ | ||
| 4 | +export class GetPullAddressBean { | ||
| 5 | + origin: OriginBean = new OriginBean(); | ||
| 6 | + transCode: Array<TransCodeBean> = new Array; | ||
| 7 | +} | ||
| 8 | + | ||
| 9 | +class OriginBean { | ||
| 10 | + expireTime: number = -1; | ||
| 11 | + definition: string = ''; | ||
| 12 | + flvUrl: string = ''; | ||
| 13 | + m3u8Url: string = ''; | ||
| 14 | + rtmpUrl: string = ''; | ||
| 15 | + rtsUrl: string = ''; | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +export class TransCodeBean { | ||
| 19 | + expireTime: number = -1; | ||
| 20 | + definition: string = ''; | ||
| 21 | + flvUrl: string = ''; | ||
| 22 | + m3u8Url: string = ''; | ||
| 23 | + rtmpUrl: string = ''; | ||
| 24 | + rtsUrl: string = ''; | ||
| 25 | +} |
| @@ -466,7 +466,8 @@ export struct SearchResultContentComponent { | @@ -466,7 +466,8 @@ export struct SearchResultContentComponent { | ||
| 466 | rmhDesc: obj.introduction, | 466 | rmhDesc: obj.introduction, |
| 467 | userId: obj.userId, | 467 | userId: obj.userId, |
| 468 | userType: obj.userType, | 468 | userType: obj.userType, |
| 469 | - honoraryIcon:'' | 469 | + honoraryIcon:'', |
| 470 | + rmhPlatform:0 | ||
| 470 | } | 471 | } |
| 471 | if(rem.length>0){ | 472 | if(rem.length>0){ |
| 472 | rem.forEach(item=>{ | 473 | rem.forEach(item=>{ |
| @@ -491,7 +492,8 @@ export struct SearchResultContentComponent { | @@ -491,7 +492,8 @@ export struct SearchResultContentComponent { | ||
| 491 | rmhDesc: item.introduction, | 492 | rmhDesc: item.introduction, |
| 492 | userId: item.userId, | 493 | userId: item.userId, |
| 493 | userType: item.userType, | 494 | userType: item.userType, |
| 494 | - honoraryIcon:'' | 495 | + honoraryIcon:'', |
| 496 | + rmhPlatform:0 | ||
| 495 | } | 497 | } |
| 496 | } | 498 | } |
| 497 | }) | 499 | }) |
| @@ -883,7 +883,8 @@ class MinePageDatasModel{ | @@ -883,7 +883,8 @@ class MinePageDatasModel{ | ||
| 883 | rmhDesc: obj.introduction, | 883 | rmhDesc: obj.introduction, |
| 884 | userId: obj.userId, | 884 | userId: obj.userId, |
| 885 | userType: obj.userType, | 885 | userType: obj.userType, |
| 886 | - honoraryIcon:'' | 886 | + honoraryIcon:'', |
| 887 | + rmhPlatform:0 | ||
| 887 | } | 888 | } |
| 888 | if(rem.length>0){ | 889 | if(rem.length>0){ |
| 889 | rem.forEach(item=>{ | 890 | rem.forEach(item=>{ |
| @@ -908,7 +909,8 @@ class MinePageDatasModel{ | @@ -908,7 +909,8 @@ class MinePageDatasModel{ | ||
| 908 | rmhDesc: item.introduction, | 909 | rmhDesc: item.introduction, |
| 909 | userId: item.userId, | 910 | userId: item.userId, |
| 910 | userType: item.userType, | 911 | userType: item.userType, |
| 911 | - honoraryIcon:'' | 912 | + honoraryIcon:'', |
| 913 | + rmhPlatform:0 | ||
| 912 | } | 914 | } |
| 913 | } | 915 | } |
| 914 | }) | 916 | }) |
| 1 | import { Logger, ResourcesUtils, EmitterUtils, EmitterEventId } from 'wdKit'; | 1 | import { Logger, ResourcesUtils, EmitterUtils, EmitterEventId } from 'wdKit'; |
| 2 | import { HttpUrlUtils, ResponseDTO, WDHttp } from 'wdNetwork'; | 2 | import { HttpUrlUtils, ResponseDTO, WDHttp } from 'wdNetwork'; |
| 3 | -import { ContentDetailDTO, InteractDataDTO } from 'wdBean'; | 3 | +import { ContentDetailDTO, GetPullAddressBean, InteractDataDTO } from 'wdBean'; |
| 4 | import { HttpRequest } from 'wdNetwork/src/main/ets/http/HttpRequest'; | 4 | import { HttpRequest } from 'wdNetwork/src/main/ets/http/HttpRequest'; |
| 5 | 5 | ||
| 6 | const TAG = 'ContentDetailRequest'; | 6 | const TAG = 'ContentDetailRequest'; |
| @@ -208,6 +208,19 @@ export class ContentDetailRequest { | @@ -208,6 +208,19 @@ export class ContentDetailRequest { | ||
| 208 | return url; | 208 | return url; |
| 209 | } | 209 | } |
| 210 | 210 | ||
| 211 | + | ||
| 212 | + static getLiveRoomPullStreamUrl(vliveId:string){ | ||
| 213 | + let url = HttpUrlUtils.getHost() + HttpUrlUtils.PULL_STREAM_PATH | ||
| 214 | + url = url + vliveId | ||
| 215 | + return url; | ||
| 216 | + } | ||
| 217 | + | ||
| 218 | + static getLiveRoomPullStream(vliveId: string): Promise<ResponseDTO<GetPullAddressBean>> { | ||
| 219 | + let url = ContentDetailRequest.getLiveRoomPullStreamUrl(vliveId) | ||
| 220 | + return WDHttp.get<ResponseDTO<GetPullAddressBean>>(url) | ||
| 221 | + } | ||
| 222 | + | ||
| 223 | + | ||
| 211 | static getContentDetail(params: ContentDetailRequestParams): Promise<ResponseDTO<ContentDetailDTO[]>> { | 224 | static getContentDetail(params: ContentDetailRequestParams): Promise<ResponseDTO<ContentDetailDTO[]>> { |
| 212 | if (mock_switch) { | 225 | if (mock_switch) { |
| 213 | return ContentDetailRequest.getContentDetailDataMock(getContext()); | 226 | return ContentDetailRequest.getContentDetailDataMock(getContext()); |
| @@ -216,6 +229,8 @@ export class ContentDetailRequest { | @@ -216,6 +229,8 @@ export class ContentDetailRequest { | ||
| 216 | return WDHttp.get<ResponseDTO<ContentDetailDTO[]>>(url) | 229 | return WDHttp.get<ResponseDTO<ContentDetailDTO[]>>(url) |
| 217 | } | 230 | } |
| 218 | 231 | ||
| 232 | + | ||
| 233 | + | ||
| 219 | /** | 234 | /** |
| 220 | * 查询沉浸式视频频道推荐楼层数据 | 235 | * 查询沉浸式视频频道推荐楼层数据 |
| 221 | * @returns | 236 | * @returns |
| 1 | -import { Action, ContentDetailDTO } from 'wdBean/Index'; | 1 | +import { Action, ContentDetailDTO, GetPullAddressBean } from 'wdBean/Index'; |
| 2 | import { LiveViewModel } from '../viewModel/LiveViewModel'; | 2 | import { LiveViewModel } from '../viewModel/LiveViewModel'; |
| 3 | import router from '@ohos.router'; | 3 | import router from '@ohos.router'; |
| 4 | 4 | ||
| @@ -78,14 +78,7 @@ export struct DetailPlayLiveCommon { | @@ -78,14 +78,7 @@ export struct DetailPlayLiveCommon { | ||
| 78 | this.liveState = detailData.liveInfo?.liveState | 78 | this.liveState = detailData.liveInfo?.liveState |
| 79 | 79 | ||
| 80 | 80 | ||
| 81 | - if (this.liveState === 'wait' || this.liveLandscape === 'news') { | ||
| 82 | - this.contentDetailData = data[0] | ||
| 83 | - } else if (this.liveLandscape === 'general') { | ||
| 84 | - //todo 不加setTimeOut ,接口返回的数据 就没法让PlayerComponent #@Consume @Watch('updateData') liveDetailsBean 的updateData方法运行 | ||
| 85 | - setTimeout(() => { | ||
| 86 | this.contentDetailData = data[0] | 81 | this.contentDetailData = data[0] |
| 87 | - }, 10) | ||
| 88 | - } | ||
| 89 | 82 | ||
| 90 | console.log(TAG, '查询视频详情用于评论展示 openComment:', detailData.openComment) | 83 | console.log(TAG, '查询视频详情用于评论展示 openComment:', detailData.openComment) |
| 91 | this.publishCommentModel.targetId = String(detailData?.newsId || '') | 84 | this.publishCommentModel.targetId = String(detailData?.newsId || '') |
| @@ -106,7 +99,20 @@ export struct DetailPlayLiveCommon { | @@ -106,7 +99,20 @@ export struct DetailPlayLiveCommon { | ||
| 106 | if (detailData.liveInfo.liveState == 'end') { | 99 | if (detailData.liveInfo.liveState == 'end') { |
| 107 | this.playUrl = detailData.liveInfo.vlive[0].replayUri | 100 | this.playUrl = detailData.liveInfo.vlive[0].replayUri |
| 108 | } | 101 | } |
| 109 | - //console.error('XXXXZZZZ', "liveLandscape =" + this.liveLandscape + ' this.liveState =' + this.liveState) | 102 | + |
| 103 | + //人民号类型单独获取直播地址 | ||
| 104 | + if (detailData.rmhPlatform === 1) { | ||
| 105 | + | ||
| 106 | + let vliveId = detailData.liveInfo.vlive[0].vliveId as string | ||
| 107 | + console.error(TAG, 'vliveId==' + vliveId) | ||
| 108 | + this.liveViewModel.getLiveRoomPullAddress(vliveId) | ||
| 109 | + .then((data: GetPullAddressBean) => { | ||
| 110 | + console.log(TAG, ' GetPullAddressBean:', JSON.stringify(data)) | ||
| 111 | + | ||
| 112 | + }) | ||
| 113 | + | ||
| 114 | + } | ||
| 115 | + | ||
| 110 | } | 116 | } |
| 111 | }) | 117 | }) |
| 112 | } | 118 | } |
| 1 | -import { ContentDetailDTO, LiveDetailsBean, LiveRoomBean, LiveRoomDataBean, ValueType } from 'wdBean/Index' | 1 | +import { ContentDetailDTO, |
| 2 | + GetPullAddressBean, | ||
| 3 | + LiveDetailsBean, LiveRoomBean, LiveRoomDataBean, ValueType } from 'wdBean/Index' | ||
| 4 | +import { ContentDetailRequest } from 'wdDetailPlayApi/Index' | ||
| 2 | 5 | ||
| 3 | import { ResponseDTO } from 'wdNetwork/Index' | 6 | import { ResponseDTO } from 'wdNetwork/Index' |
| 4 | import { LiveModel } from './LiveModel' | 7 | import { LiveModel } from './LiveModel' |
| @@ -24,6 +27,28 @@ export class LiveViewModel { | @@ -24,6 +27,28 @@ export class LiveViewModel { | ||
| 24 | 27 | ||
| 25 | } | 28 | } |
| 26 | 29 | ||
| 30 | + getLiveRoomPullAddress(vliveId:string){ | ||
| 31 | + // return new Promise<GetPullAddressBean>((success, fail) => { | ||
| 32 | + // this.liveModel.getContentDetail(contentId, relId, relType).then((data) => { | ||
| 33 | + // success(data) | ||
| 34 | + // }).catch((message: string) => { | ||
| 35 | + // fail(message) | ||
| 36 | + // }) | ||
| 37 | + // }) | ||
| 38 | + | ||
| 39 | + return new Promise<GetPullAddressBean>((success, fail) => { | ||
| 40 | + ContentDetailRequest.getLiveRoomPullStream(vliveId).then(async (resDTO: ResponseDTO<GetPullAddressBean>) => { | ||
| 41 | + console.log(TAG, 'getContentDetail:', JSON.stringify(resDTO.data)) | ||
| 42 | + if (resDTO.data) { | ||
| 43 | + success(resDTO.data) | ||
| 44 | + } | ||
| 45 | + }).catch(() => { | ||
| 46 | + fail("数据为空") | ||
| 47 | + }) | ||
| 48 | + | ||
| 49 | + }) | ||
| 50 | + | ||
| 51 | + } | ||
| 27 | 52 | ||
| 28 | //直播详情 | 53 | //直播详情 |
| 29 | getLiveDetails(contentId: string, relId: string, relType: string) { | 54 | getLiveDetails(contentId: string, relId: string, relType: string) { |
| @@ -52,7 +52,6 @@ export struct TopPlayComponent { | @@ -52,7 +52,6 @@ export struct TopPlayComponent { | ||
| 52 | } else if (status === PlayerConstants.STATUS_COMPLETION) { | 52 | } else if (status === PlayerConstants.STATUS_COMPLETION) { |
| 53 | // 播放完成 | 53 | // 播放完成 |
| 54 | 54 | ||
| 55 | - | ||
| 56 | } else { | 55 | } else { |
| 57 | this.isError = false | 56 | this.isError = false |
| 58 | } | 57 | } |
| @@ -28,7 +28,10 @@ export struct PlayerComponent { | @@ -28,7 +28,10 @@ export struct PlayerComponent { | ||
| 28 | this.playerController?.pause() | 28 | this.playerController?.pause() |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | - aboutToAppear(): void { | 31 | + async aboutToAppear(): Promise<void> { |
| 32 | + setTimeout(() => { | ||
| 33 | + this.updateData() | ||
| 34 | + }, 10) | ||
| 32 | } | 35 | } |
| 33 | 36 | ||
| 34 | async aboutToDisappear(): Promise<void> { | 37 | async aboutToDisappear(): Promise<void> { |
| @@ -36,6 +39,7 @@ export struct PlayerComponent { | @@ -36,6 +39,7 @@ export struct PlayerComponent { | ||
| 36 | await this.playerController?.pause() | 39 | await this.playerController?.pause() |
| 37 | await this.playerController?.stop() | 40 | await this.playerController?.stop() |
| 38 | await this.playerController?.release() | 41 | await this.playerController?.release() |
| 42 | + | ||
| 39 | } | 43 | } |
| 40 | 44 | ||
| 41 | updateData() { | 45 | updateData() { |
| @@ -58,6 +62,7 @@ export struct PlayerComponent { | @@ -58,6 +62,7 @@ export struct PlayerComponent { | ||
| 58 | this.liveStreamType = liveStreamType | 62 | this.liveStreamType = liveStreamType |
| 59 | this.playUrl = playUrl | 63 | this.playUrl = playUrl |
| 60 | } | 64 | } |
| 65 | + console.error("XXXXZZZZ", 'updateData ----liveState==>' + this.playUrl) | ||
| 61 | } | 66 | } |
| 62 | 67 | ||
| 63 | build() { | 68 | build() { |
| @@ -69,6 +74,7 @@ export struct PlayerComponent { | @@ -69,6 +74,7 @@ export struct PlayerComponent { | ||
| 69 | playerController: this.playerController, | 74 | playerController: this.playerController, |
| 70 | onLoad: () => { | 75 | onLoad: () => { |
| 71 | this.isCanplay = true | 76 | this.isCanplay = true |
| 77 | + console.error("XXXXZZZZ", '------2------------') | ||
| 72 | this.playerController?.firstPlay(this.playUrl); | 78 | this.playerController?.firstPlay(this.playUrl); |
| 73 | } | 79 | } |
| 74 | }) | 80 | }) |
| @@ -77,7 +83,7 @@ export struct PlayerComponent { | @@ -77,7 +83,7 @@ export struct PlayerComponent { | ||
| 77 | playerController: this.playerController, | 83 | playerController: this.playerController, |
| 78 | onLoad: () => { | 84 | onLoad: () => { |
| 79 | this.isCanplay = true | 85 | this.isCanplay = true |
| 80 | - console.error('WDAliPlayerController', '------1------------') | 86 | + console.error('XXXXZZZZ', '------1------------') |
| 81 | this.playerController?.firstPlay(this.playUrl); | 87 | this.playerController?.firstPlay(this.playUrl); |
| 82 | } | 88 | } |
| 83 | }).margin({ top: 195 }).height(211) | 89 | }).margin({ top: 195 }).height(211) |
| @@ -4,6 +4,7 @@ import { SpConstants } from 'wdConstant/Index' | @@ -4,6 +4,7 @@ import { SpConstants } from 'wdConstant/Index' | ||
| 4 | import { ContentDetailRequest, postInteractAccentionOperateParams } from 'wdDetailPlayApi/Index' | 4 | import { ContentDetailRequest, postInteractAccentionOperateParams } from 'wdDetailPlayApi/Index' |
| 5 | import { NumberFormatterUtils, DateTimeUtils, SPHelper } from 'wdKit/Index' | 5 | import { NumberFormatterUtils, DateTimeUtils, SPHelper } from 'wdKit/Index' |
| 6 | import { WDRouterPage, WDRouterRule } from 'wdRouter/Index' | 6 | import { WDRouterPage, WDRouterRule } from 'wdRouter/Index' |
| 7 | +import { router } from '@kit.ArkUI' | ||
| 7 | 8 | ||
| 8 | const TAG = 'PlayerEndView' | 9 | const TAG = 'PlayerEndView' |
| 9 | 10 | ||
| @@ -15,9 +16,12 @@ export struct PlayerEndView { | @@ -15,9 +16,12 @@ export struct PlayerEndView { | ||
| 15 | @Consume liveRoomDataBean: LiveRoomDataBean | 16 | @Consume liveRoomDataBean: LiveRoomDataBean |
| 16 | @State duration: string = '' | 17 | @State duration: string = '' |
| 17 | @State followStatus: String = '0'; | 18 | @State followStatus: String = '0'; |
| 19 | + private onBack: () => void = () => { | ||
| 20 | + } | ||
| 18 | 21 | ||
| 19 | aboutToAppear(): void { | 22 | aboutToAppear(): void { |
| 20 | - const sn = DateTimeUtils.parseDate(this.contentDetailData.liveInfo.startTime, DateTimeUtils.PATTERN_DATE_TIME_HYPHEN) | 23 | + const sn = |
| 24 | + DateTimeUtils.parseDate(this.contentDetailData.liveInfo.startTime, DateTimeUtils.PATTERN_DATE_TIME_HYPHEN) | ||
| 21 | const en = DateTimeUtils.parseDate(this.contentDetailData.liveInfo.endTime, DateTimeUtils.PATTERN_DATE_TIME_HYPHEN) | 25 | const en = DateTimeUtils.parseDate(this.contentDetailData.liveInfo.endTime, DateTimeUtils.PATTERN_DATE_TIME_HYPHEN) |
| 22 | const sd = DateTimeUtils.getDuration(sn, en) | 26 | const sd = DateTimeUtils.getDuration(sn, en) |
| 23 | this.duration = DateTimeUtils.secondToTime(sd / 1000) | 27 | this.duration = DateTimeUtils.secondToTime(sd / 1000) |
| @@ -113,7 +117,12 @@ export struct PlayerEndView { | @@ -113,7 +117,12 @@ export struct PlayerEndView { | ||
| 113 | .fontWeight(400) | 117 | .fontWeight(400) |
| 114 | .fontSize(16) | 118 | .fontSize(16) |
| 115 | .fontColor(Color.White) | 119 | .fontColor(Color.White) |
| 116 | - .padding({ top: 8, bottom: 8, left: 122, right: 122 }) | 120 | + .padding({ |
| 121 | + top: 8, | ||
| 122 | + bottom: 8, | ||
| 123 | + left: 122, | ||
| 124 | + right: 122 | ||
| 125 | + }) | ||
| 117 | .backgroundColor(this.followStatus == '0' ? '#FFED2800' : Color.Grey) | 126 | .backgroundColor(this.followStatus == '0' ? '#FFED2800' : Color.Grey) |
| 118 | .borderRadius(4) | 127 | .borderRadius(4) |
| 119 | .onClick(() => { | 128 | .onClick(() => { |
| @@ -140,8 +149,30 @@ export struct PlayerEndView { | @@ -140,8 +149,30 @@ export struct PlayerEndView { | ||
| 140 | } | 149 | } |
| 141 | .width(307) | 150 | .width(307) |
| 142 | .padding({ top: 40 }) | 151 | .padding({ top: 40 }) |
| 152 | + | ||
| 153 | + Blank() | ||
| 154 | + | ||
| 155 | + // 返回按钮 | ||
| 156 | + Row() { | ||
| 157 | + Image($r('app.media.icon_arrow_left_white')) | ||
| 158 | + .width(24) | ||
| 159 | + .height(24) | ||
| 160 | + .aspectRatio(1) | ||
| 161 | + .interpolation(ImageInterpolation.High) | ||
| 162 | + .hoverEffect(HoverEffect.Scale) | ||
| 163 | + .margin({ bottom: 30 ,left:14}) | ||
| 164 | + .onClick(() => { | ||
| 165 | + if (this.onBack) { | ||
| 166 | + this.onBack() | ||
| 167 | + } | ||
| 168 | + router.back(); | ||
| 169 | + }) | ||
| 170 | + | ||
| 171 | + }.width('100%') | ||
| 172 | + | ||
| 143 | } | 173 | } |
| 144 | .height('100%') | 174 | .height('100%') |
| 175 | + .width('100%') | ||
| 145 | 176 | ||
| 146 | } | 177 | } |
| 147 | } | 178 | } |
| @@ -7,12 +7,13 @@ import { | @@ -7,12 +7,13 @@ import { | ||
| 7 | paused, | 7 | paused, |
| 8 | stopped, | 8 | stopped, |
| 9 | completion, | 9 | completion, |
| 10 | - error} from 'premierlibrary/src/main/ets/com/aliyun/player/IPlayer'; | 10 | + error |
| 11 | +} from 'premierlibrary/src/main/ets/com/aliyun/player/IPlayer'; | ||
| 11 | 12 | ||
| 12 | import { initGlobalPlayerSettings, setupPlayerConfig } from '../utils/GlobalSetting'; | 13 | import { initGlobalPlayerSettings, setupPlayerConfig } from '../utils/GlobalSetting'; |
| 13 | import prompt from '@ohos.promptAction'; | 14 | import prompt from '@ohos.promptAction'; |
| 14 | import { PlayerConstants, AVPlayerStatus, Events } from '../constants/PlayerConstants'; | 15 | import { PlayerConstants, AVPlayerStatus, Events } from '../constants/PlayerConstants'; |
| 15 | -import { Logger } from 'wdKit/Index'; | 16 | +import { Logger, StringUtils } from 'wdKit/Index'; |
| 16 | 17 | ||
| 17 | const TAG = "WDAliPlayerController" | 18 | const TAG = "WDAliPlayerController" |
| 18 | 19 | ||
| @@ -26,7 +27,6 @@ const TAG = "WDAliPlayerController" | @@ -26,7 +27,6 @@ const TAG = "WDAliPlayerController" | ||
| 26 | export class WDAliPlayerController { | 27 | export class WDAliPlayerController { |
| 27 | private initPromise: Promise<void>; | 28 | private initPromise: Promise<void>; |
| 28 | private avPlayer?: AliPlayer; | 29 | private avPlayer?: AliPlayer; |
| 29 | - | ||
| 30 | // 内部播放器状态 | 30 | // 内部播放器状态 |
| 31 | private avPlayerStatus: number = idle | 31 | private avPlayerStatus: number = idle |
| 32 | private duration: number = 0; | 32 | private duration: number = 0; |
| @@ -38,18 +38,14 @@ export class WDAliPlayerController { | @@ -38,18 +38,14 @@ export class WDAliPlayerController { | ||
| 38 | private seekTime: number = 0; | 38 | private seekTime: number = 0; |
| 39 | private positionY: number = 0; | 39 | private positionY: number = 0; |
| 40 | private startTime: number = 0 | 40 | private startTime: number = 0 |
| 41 | - | ||
| 42 | public errorCode?: number | 41 | public errorCode?: number |
| 43 | public errorMesage?: string | 42 | public errorMesage?: string |
| 44 | - | ||
| 45 | public onVideoSizeChange?: (width: number, height: number) => void; | 43 | public onVideoSizeChange?: (width: number, height: number) => void; |
| 46 | public onBufferUpdate?: (buffered: number, duration: number) => void; | 44 | public onBufferUpdate?: (buffered: number, duration: number) => void; |
| 47 | public onTimeUpdate?: (position: number, duration: number) => void; | 45 | public onTimeUpdate?: (position: number, duration: number) => void; |
| 48 | public onVolumeUpdate?: (volume: number) => void; | 46 | public onVolumeUpdate?: (volume: number) => void; |
| 49 | - | ||
| 50 | // 播放完成,决定是否继续播放回调 | 47 | // 播放完成,决定是否继续播放回调 |
| 51 | public continue?: () => void; | 48 | public continue?: () => void; |
| 52 | - | ||
| 53 | // 准备完成,决定是否播放回调。如果不实现,则自动播放 | 49 | // 准备完成,决定是否播放回调。如果不实现,则自动播放 |
| 54 | public onCanplay?: () => void; | 50 | public onCanplay?: () => void; |
| 55 | public onStatusChange?: (status: number) => void; | 51 | public onStatusChange?: (status: number) => void; |
| @@ -117,12 +113,12 @@ export class WDAliPlayerController { | @@ -117,12 +113,12 @@ export class WDAliPlayerController { | ||
| 117 | onInfo: (bean: InfoBean) => { | 113 | onInfo: (bean: InfoBean) => { |
| 118 | 114 | ||
| 119 | if (bean.getCode() === InfoCode.CurrentPosition) { | 115 | if (bean.getCode() === InfoCode.CurrentPosition) { |
| 120 | - let position : number = bean.getExtraValue() | 116 | + let position: number = bean.getExtraValue() |
| 121 | Logger.debug(TAG, `播放进度条:${position}/ ${this.duration}`) | 117 | Logger.debug(TAG, `播放进度条:${position}/ ${this.duration}`) |
| 122 | this.initProgress(position); | 118 | this.initProgress(position); |
| 123 | 119 | ||
| 124 | } else if (bean.getCode() === InfoCode.BufferedPosition) { | 120 | } else if (bean.getCode() === InfoCode.BufferedPosition) { |
| 125 | - let buffer : number = bean.getExtraValue() | 121 | + let buffer: number = bean.getExtraValue() |
| 126 | if (this.onBufferUpdate) { | 122 | if (this.onBufferUpdate) { |
| 127 | this.onBufferUpdate(buffer, this.duration) | 123 | this.onBufferUpdate(buffer, this.duration) |
| 128 | } | 124 | } |
| @@ -140,7 +136,8 @@ export class WDAliPlayerController { | @@ -140,7 +136,8 @@ export class WDAliPlayerController { | ||
| 140 | switch (status) { | 136 | switch (status) { |
| 141 | case initalized: { | 137 | case initalized: { |
| 142 | //this.avPlayer?.prepare(); | 138 | //this.avPlayer?.prepare(); |
| 143 | - } break | 139 | + } |
| 140 | + break | ||
| 144 | case prepared: { | 141 | case prepared: { |
| 145 | if (this.startTime) { | 142 | if (this.startTime) { |
| 146 | this.setSeekTime(this.startTime, SliderChangeMode.Begin); | 143 | this.setSeekTime(this.startTime, SliderChangeMode.Begin); |
| @@ -154,20 +151,24 @@ export class WDAliPlayerController { | @@ -154,20 +151,24 @@ export class WDAliPlayerController { | ||
| 154 | } else { | 151 | } else { |
| 155 | this.play() | 152 | this.play() |
| 156 | } | 153 | } |
| 157 | - } break | 154 | + } |
| 155 | + break | ||
| 158 | case started: { | 156 | case started: { |
| 159 | this.setBright(); | 157 | this.setBright(); |
| 160 | this.status = PlayerConstants.STATUS_START; | 158 | this.status = PlayerConstants.STATUS_START; |
| 161 | this.watchStatus(); | 159 | this.watchStatus(); |
| 162 | - } break | 160 | + } |
| 161 | + break | ||
| 163 | case paused: { | 162 | case paused: { |
| 164 | this.status = PlayerConstants.STATUS_PAUSE; | 163 | this.status = PlayerConstants.STATUS_PAUSE; |
| 165 | this.watchStatus(); | 164 | this.watchStatus(); |
| 166 | - } break | 165 | + } |
| 166 | + break | ||
| 167 | case stopped: { | 167 | case stopped: { |
| 168 | this.status = PlayerConstants.STATUS_STOP; | 168 | this.status = PlayerConstants.STATUS_STOP; |
| 169 | this.watchStatus(); | 169 | this.watchStatus(); |
| 170 | - } break | 170 | + } |
| 171 | + break | ||
| 171 | case completion: { | 172 | case completion: { |
| 172 | this.status = PlayerConstants.STATUS_COMPLETION; | 173 | this.status = PlayerConstants.STATUS_COMPLETION; |
| 173 | this.watchStatus(); | 174 | this.watchStatus(); |
| @@ -179,7 +180,8 @@ export class WDAliPlayerController { | @@ -179,7 +180,8 @@ export class WDAliPlayerController { | ||
| 179 | //this.url = this.avPlayer.url || ''; | 180 | //this.url = this.avPlayer.url || ''; |
| 180 | //this.avPlayer.reset(); | 181 | //this.avPlayer.reset(); |
| 181 | } | 182 | } |
| 182 | - } break | 183 | + } |
| 184 | + break | ||
| 183 | case error: { | 185 | case error: { |
| 184 | // 这里拿不到错误信息 | 186 | // 这里拿不到错误信息 |
| 185 | // this.status = PlayerConstants.STATUS_ERROR; | 187 | // this.status = PlayerConstants.STATUS_ERROR; |
| @@ -189,7 +191,7 @@ export class WDAliPlayerController { | @@ -189,7 +191,7 @@ export class WDAliPlayerController { | ||
| 189 | } | 191 | } |
| 190 | }); | 192 | }); |
| 191 | this.avPlayer?.setOnErrorListener({ | 193 | this.avPlayer?.setOnErrorListener({ |
| 192 | - onError:(errorInfo) => { | 194 | + onError: (errorInfo) => { |
| 193 | Logger.error(TAG, "播放错误", JSON.stringify(errorInfo)) | 195 | Logger.error(TAG, "播放错误", JSON.stringify(errorInfo)) |
| 194 | this.errorCode = errorInfo.getCode() | 196 | this.errorCode = errorInfo.getCode() |
| 195 | this.errorMesage = errorInfo.getMsg() | 197 | this.errorMesage = errorInfo.getMsg() |
| @@ -220,21 +222,29 @@ export class WDAliPlayerController { | @@ -220,21 +222,29 @@ export class WDAliPlayerController { | ||
| 220 | } | 222 | } |
| 221 | 223 | ||
| 222 | private setAliPlayerURL(url: string) { | 224 | private setAliPlayerURL(url: string) { |
| 223 | - let urlSource : UrlSource = new UrlSource() | 225 | + let urlSource: UrlSource = new UrlSource() |
| 224 | urlSource.setUri(url) | 226 | urlSource.setUri(url) |
| 225 | this.avPlayer?.setUrlDataSource(urlSource) | 227 | this.avPlayer?.setUrlDataSource(urlSource) |
| 226 | } | 228 | } |
| 227 | 229 | ||
| 228 | - private getStatusStringWith(status: number) : string { | 230 | + private getStatusStringWith(status: number): string { |
| 229 | switch (status) { | 231 | switch (status) { |
| 230 | - case idle: return 'idle' | ||
| 231 | - case initalized: return 'initalized' | ||
| 232 | - case prepared: return 'prepared' | ||
| 233 | - case started: return 'started' | ||
| 234 | - case paused: return 'paused' | ||
| 235 | - case stopped: return 'stopped' | ||
| 236 | - case completion: return 'completion' | ||
| 237 | - case error: return 'error' | 232 | + case idle: |
| 233 | + return 'idle' | ||
| 234 | + case initalized: | ||
| 235 | + return 'initalized' | ||
| 236 | + case prepared: | ||
| 237 | + return 'prepared' | ||
| 238 | + case started: | ||
| 239 | + return 'started' | ||
| 240 | + case paused: | ||
| 241 | + return 'paused' | ||
| 242 | + case stopped: | ||
| 243 | + return 'stopped' | ||
| 244 | + case completion: | ||
| 245 | + return 'completion' | ||
| 246 | + case error: | ||
| 247 | + return 'error' | ||
| 238 | } | 248 | } |
| 239 | return 'unknow' | 249 | return 'unknow' |
| 240 | } | 250 | } |
| @@ -256,6 +266,10 @@ export class WDAliPlayerController { | @@ -256,6 +266,10 @@ export class WDAliPlayerController { | ||
| 256 | } | 266 | } |
| 257 | 267 | ||
| 258 | async firstPlay(url: string) { | 268 | async firstPlay(url: string) { |
| 269 | + if (StringUtils.isEmpty(url)) { | ||
| 270 | + return | ||
| 271 | + } | ||
| 272 | + | ||
| 259 | this.url = url; | 273 | this.url = url; |
| 260 | if (this.avPlayer == null) { | 274 | if (this.avPlayer == null) { |
| 261 | Logger.info(TAG, "等待播放器初始化") | 275 | Logger.info(TAG, "等待播放器初始化") |
| @@ -278,7 +292,7 @@ export class WDAliPlayerController { | @@ -278,7 +292,7 @@ export class WDAliPlayerController { | ||
| 278 | 292 | ||
| 279 | this.avPlayer?.setAutoPlay(false) | 293 | this.avPlayer?.setAutoPlay(false) |
| 280 | 294 | ||
| 281 | - Logger.debug(TAG, "开始播放", this.url) | 295 | + Logger.debug(TAG, "开始播放:"+ this.url) |
| 282 | this.setAliPlayerURL(this.url); | 296 | this.setAliPlayerURL(this.url); |
| 283 | 297 | ||
| 284 | Logger.info(TAG, "设置SurfaceId: " + this.surfaceId) | 298 | Logger.info(TAG, "设置SurfaceId: " + this.surfaceId) |
| @@ -175,7 +175,7 @@ export class WDPlayerController { | @@ -175,7 +175,7 @@ export class WDPlayerController { | ||
| 175 | this.pageParam = pageParam | 175 | this.pageParam = pageParam |
| 176 | } | 176 | } |
| 177 | if (this.avPlayer == null) { | 177 | if (this.avPlayer == null) { |
| 178 | - Logger.error("等待") | 178 | + console.log("等待") |
| 179 | await this.initPromise; | 179 | await this.initPromise; |
| 180 | } else { | 180 | } else { |
| 181 | if (this.avPlayer.state != AVPlayerStatus.IDLE) { | 181 | if (this.avPlayer.state != AVPlayerStatus.IDLE) { |
| @@ -188,7 +188,7 @@ export class WDPlayerController { | @@ -188,7 +188,7 @@ export class WDPlayerController { | ||
| 188 | if (this.avPlayer == null) { | 188 | if (this.avPlayer == null) { |
| 189 | return | 189 | return |
| 190 | } | 190 | } |
| 191 | - Logger.error("开始播放", this.url) | 191 | + console.log("开始播放", this.url) |
| 192 | this.avPlayer.url = this.url; | 192 | this.avPlayer.url = this.url; |
| 193 | //加载时长prepareTime | 193 | //加载时长prepareTime |
| 194 | this.creatEndTime = DateTimeUtils.getTimeStamp() | 194 | this.creatEndTime = DateTimeUtils.getTimeStamp() |
-
Please register or login to post a comment