60 lines
2.1 KiB
Plaintext
60 lines
2.1 KiB
Plaintext
import { runCatching, seconds } from '@polyvharmony/media-player-sdk';
|
|
import { BasicConstant } from '@itcast/basic'
|
|
import { promptAction, router } from '@kit.ArkUI';
|
|
import { PLVMockMediaResourceData } from '../polyv/PLVMockMediaResourceData'
|
|
import {
|
|
PLVMediaPlayerSingleVideoPageParam
|
|
} from 'media-player-common';
|
|
import HashMap from '@ohos.util.HashMap';
|
|
import { hdHttp, HdResponse ,logger} from '@itcast/basic/Index'
|
|
import { BusinessError } from '@kit.BasicServicesKit';
|
|
import { VideoDetailModel } from '../model/VideoDetailModel'
|
|
class VideoTools {
|
|
hashMap: HashMap<string, string> = new HashMap();
|
|
getVideoDetail(video_uuid:string)
|
|
{
|
|
this.hashMap.clear();
|
|
this.hashMap.set('video_uuid', video_uuid)
|
|
hdHttp.httpReq<string>(BasicConstant.videoDetail,this.hashMap).then(async (res: HdResponse<string>) => {
|
|
|
|
logger.info('Response videoDetail'+res);
|
|
let json:VideoDetailModel = JSON.parse(res+'') as VideoDetailModel;
|
|
if(json.video.polyv_uuid==null||json.video.polyv_uuid==undefined)
|
|
{
|
|
promptAction.showToast({ message: '视频信息错误' })
|
|
this.goPLVMediaPlayerSingleVideoPage('',video_uuid)
|
|
}
|
|
else
|
|
{
|
|
this.goPLVMediaPlayerSingleVideoPage(json.video.polyv_uuid,video_uuid)
|
|
}
|
|
|
|
|
|
}).catch((err: BusinessError) => {
|
|
this.goPLVMediaPlayerSingleVideoPage('',video_uuid)
|
|
})
|
|
}
|
|
|
|
async goPLVMediaPlayerSingleVideoPage(vid:string,video_uuid:string)
|
|
{
|
|
const mediaResourcesResult = await runCatching(PLVMockMediaResourceData.getInstance().setupMediaResourcesFromLocal(vid))
|
|
if (mediaResourcesResult.success === false) {
|
|
promptAction.showToast({
|
|
message: `'视频数据初始化失败': ${mediaResourcesResult.error}`,
|
|
duration: seconds(3).toMillis()
|
|
})
|
|
return
|
|
}
|
|
const mediaResource = mediaResourcesResult.data[0]
|
|
router.pushUrl({
|
|
url:'pages/VideoPage/PLVMediaPlayerSingleVideoPage',
|
|
params: {
|
|
video_uuid:video_uuid,
|
|
param:new PLVMediaPlayerSingleVideoPageParam(mediaResource)
|
|
}
|
|
})
|
|
}
|
|
|
|
}
|
|
|
|
export const videoTools = new VideoTools() |