陈剑华

Merge remote-tracking branch 'origin/main'

Showing 32 changed files with 1383 additions and 153 deletions
... ... @@ -96,10 +96,10 @@ export struct RmhTitle {
build() {
Flex() {
Stack() {
Image(this.rmhInfo.rmhHeadUrl)
Image(this.rmhInfo?.rmhHeadUrl)
.width(36)
.height(36).borderRadius(50)
Image(this.rmhInfo.authIcon)
Image(this.rmhInfo?.authIcon)
.width(14)
.height(14)
.borderRadius(50)
... ... @@ -109,7 +109,7 @@ export struct RmhTitle {
.flexShrink(0)
Column() {
Text(this.rmhInfo.rmhName)
Text(this.rmhInfo?.rmhName)
.fontSize($r('app.float.font_size_13'))
.fontColor($r('app.color.color_222222'))
.fontWeight(600)
... ... @@ -122,13 +122,13 @@ export struct RmhTitle {
.fontSize($r("app.float.font_size_12"))
.fontColor($r("app.color.color_B0B0B0"))
}
if (this.publishTime && this.rmhInfo.rmhDesc) {
if (this.publishTime && this.rmhInfo?.rmhDesc) {
Image($r('app.media.point'))
.width(16)
.height(16)
}
}
Text(this.rmhInfo.rmhDesc)
Text(this.rmhInfo?.rmhDesc)
.fontSize($r("app.float.font_size_12"))
.fontColor($r("app.color.color_B0B0B0"))
.maxLines(1)
... ... @@ -141,7 +141,7 @@ export struct RmhTitle {
}
Blank()
if (this.rmhInfo.cnIsAttention) {
if (this.rmhInfo?.cnIsAttention) {
Row() {
if (Number(this.followStatus) === 0) {
Image($r('app.media.rmh_follow'))
... ...
... ... @@ -40,7 +40,7 @@ export struct Card17Component {
this.contentDTO.fullColumnImgUrls.length > 0 ? this.contentDTO.fullColumnImgUrls[0].url : '' : '')
.backgroundColor(this.loadImg ? '#f5f5f5' : 0xf5f5f5)
.width(CommonConstants.FULL_WIDTH)
.aspectRatio(16 / 9)
.height(160)// .aspectRatio(CompUtils.ASPECT_RATIO_16_9)
.borderRadius({
topLeft: $r('app.float.image_border_radius'),
bottomLeft: $r('app.float.image_border_radius'),
... ... @@ -52,7 +52,7 @@ export struct Card17Component {
this.contentDTO.fullColumnImgUrls.length > 1 ? this.contentDTO.fullColumnImgUrls[1].url : '' : '')
.backgroundColor(this.loadImg ? '#f5f5f5' : 0xf5f5f5)
.width(CommonConstants.FULL_WIDTH)
.aspectRatio(16 / 9)
.height(79)// .aspectRatio(CompUtils.ASPECT_RATIO_16_9)
.margin({ bottom: 1 })
.borderRadius({
topRight: $r('app.float.image_border_radius'),
... ... @@ -69,7 +69,7 @@ export struct Card17Component {
this.contentDTO.fullColumnImgUrls.length > 2 ? this.contentDTO.fullColumnImgUrls[2].url : '' : '')
.backgroundColor(this.loadImg ? '#f5f5f5' : 0xf5f5f5)
.width(CommonConstants.FULL_WIDTH)
.aspectRatio(16 / 9)
.height(79)// .aspectRatio(CompUtils.ASPECT_RATIO_16_9)
.margin({ top: 1 })
.borderRadius({
bottomRight: $r('app.float.image_border_radius'),
... ... @@ -107,4 +107,12 @@ export struct Card17Component {
bottom: $r('app.float.card_comp_pagePadding_tb')
})
}
}
// 全局公共样式
@Styles
function ImageSize() {
.padding({ right: 18, left: 18 })
.width('100%')
.margin({ top: 10 })
}
\ No newline at end of file
... ...
... ... @@ -68,7 +68,7 @@ export class commentItemModel {
fromUserHeader: string = ''
fromUserId: string = ''
fromUserName: string = ''
fromUserType: WDPublicUserType = 0
fromUserType: WDPublicUserType = 1
id: string = ''
likeNum: string = '0'
mySelf: string = ''
... ...
... ... @@ -3,8 +3,8 @@ import curves from '@ohos.curves';
import { BusinessError } from '@ohos.base';
import display from '@ohos.display';
const collapseString = '...展开全文'
const uncollapseString = '...收起'
const collapseString = '...展开'
const uncollapseString = ' 收起'
const TestLongText = "超过三行超\n过三行超过\n三行超超过三行\n超过三行超过三行超过三\n行超过"
... ... @@ -129,7 +129,9 @@ export struct CommentText {
// Stack({ alignContent: Alignment.BottomEnd }) {
Text(this.longMessage) {
Span(this.expandedStates ? this.longMessage : this.maxLineMesssage)
Span(this.collapseText).onClick(() => {
Span(this.collapseText)
.fontColor("#999999")
.onClick(() => {
if (this.collapseText == collapseString) {
this.collapseText = uncollapseString;
this.expandedStates = true;
... ...
... ... @@ -26,7 +26,7 @@ export struct QualityCommentsComponent {
private scroller: Scroller = new Scroller();
@State tileOpacity: number = 0;
firstPositionY: number = 0;
bottomSafeHeight: string = AppStorage.get<number>('bottomSafeHeight') + 'px';
bottomSafeHeight: number = AppStorage.get<number>('bottomSafeHeight') || 0;
topSafeHeight: number = AppStorage.get<number>('topSafeHeight') as number;
lastWindowColor: string = '#ffffff'
currentWindowColor: string = '#FF4202'
... ... @@ -247,9 +247,9 @@ export struct QualityCommentsComponent {
ListItem() {
if (this.hasMore === false) NoMoreLayout()
}
ListItem() {
}.height(this.bottomSafeHeight)
// ListItem() {
//
// }.height(this.bottomSafeHeight)
}.onReachEnd(()=>{
this.currentPage++
this.getData()
... ... @@ -257,8 +257,7 @@ export struct QualityCommentsComponent {
.margin({ top: 196 })
.height("100%")
.width("100%")
// .edgeEffect(EdgeEffect.None) // 必须设置列表为滑动到边缘无效果
.edgeEffect(EdgeEffect.Spring)
.edgeEffect(EdgeEffect.None) // 必须设置列表为滑动到边缘无效果
.nestedScroll({
scrollForward: NestedScrollMode.PARENT_FIRST,
scrollBackward: NestedScrollMode.SELF_FIRST
... ... @@ -352,7 +351,7 @@ struct QualityCommentItem {
Row() {
Row() {
Image($r('app.media.comment_img_link')).width(16).height(16)
Text(this.item.shareInfo.shareTitle)
Text(this.item.targetTitle)
.fontSize(14)
.fontColor('#666666')
.margin({ left: 6, right: 12 })
... ...
... ... @@ -485,10 +485,13 @@ class CommentViewModel {
jumpToAccountPage(commentItem: commentItemModel) {
let url = HttpUrlUtils.getOtherUserDetailDataUrl()
let item : Record<string, string >= {
"creatorId": commentItem.fromCreatorId || "",
"userType": `${commentItem.fromUserType}`,
"userId": commentItem.fromUserId || "-1",
let item : Record<string, string >= {}
if (commentItem.fromCreatorId) {
item["creatorId"] = commentItem.fromCreatorId
} else {
item["userType"] = `${commentItem.fromUserType}`
item["userId"] = commentItem.fromUserId
}
HttpBizUtil.post<ResponseDTO<MasterDetailRes>>(url, item).then((result) => {
if (!result.data || result.data.mainControl != 1) {
... ...
import { CompDTO, ContentDTO } from 'wdBean';
import { CompDTO, ContentDTO, LiveRoomDataBean } from 'wdBean';
import { CommonConstants } from 'wdConstant/Index';
import { Logger } from 'wdKit/Index';
import { ProcessUtils } from 'wdRouter';
... ... @@ -20,6 +20,9 @@ export struct ZhGridLayout02 {
@State compDTO: CompDTO = {} as CompDTO
@State operDataList: ContentDTO[] = []
@State loadImg: boolean = false;
@State liveRoomList: LiveRoomDataBean[] = []
currentPage = 1
pageSize = 12
async aboutToAppear(): Promise<void> {
Logger.debug(TAG, 'aboutToAppear ' + this.compDTO.objectTitle)
... ... @@ -27,14 +30,12 @@ export struct ZhGridLayout02 {
PageViewModel.getLiveReviewUrl(this.currentPage, this.pageSize).then((liveReviewDTO) => {
this.operDataList = []
this.operDataList.push(...liveReviewDTO.list)
this.getLiveRoomDataInfo(this.operDataList)
})
this.loadImg = await onlyWifiLoadImg();
}
currentPage = 1
pageSize = 12
build() {
Column() {
Scroll() {
... ... @@ -50,7 +51,7 @@ export struct ZhGridLayout02 {
.fontWeight(600)
}
.justifyContent(FlexAlign.Start)
.margin({ top: 8, bottom: 8 })
.margin({ top: 16, bottom: 8 })
.width(CommonConstants.FULL_WIDTH)
GridRow({
... ... @@ -100,13 +101,26 @@ export struct ZhGridLayout02 {
@Builder
buildItemCard(item: ContentDTO) {
Column() {
Image(this.loadImg ? item.fullColumnImgUrls[0].url : '')
.backgroundColor(0xf5f5f5)
.width('100%')
.height(95)
.borderRadius(4)
Stack({ alignContent: Alignment.BottomEnd }) {
Image(this.loadImg ? item.fullColumnImgUrls[0].url : '')
.backgroundColor(0xf5f5f5)
.width('100%')
.height(95)
.borderRadius(4)
if (this.getLiveRoomNumber(item).length > 0) {
Text(this.getLiveRoomNumber(item))
.fontSize('11vp')
.fontWeight(400)
.fontColor(Color.White)
.margin({
right: '5vp',
bottom: '5vp'
})
}
}
Text(item.newsTitle)
.margin({top:'5'})
.margin({ top: '5' })
.fontSize(13)
.maxLines(2)
.textOverflow({ overflow: TextOverflow.Ellipsis })
... ... @@ -117,14 +131,56 @@ export struct ZhGridLayout02 {
})
}
// 获取评论数
async getLiveRoomDataInfo(list: ContentDTO[]) {
const reserveIds = this.getLiveDetailIds(list)
PageViewModel.getLiveRoomBatchInfo(reserveIds).then((result) => {
if (result && result.length > 0) {
this.liveRoomList.push(...result)
}
}).catch(() => {
})
}
// 判断是否预约
getLiveRoomNumber(item: ContentDTO): string {
const objc = this.liveRoomList.find((element: LiveRoomDataBean) => {
return element.liveId.toString() == item.objectId
})
if (objc && objc.pv && objc.pv > 0) {
return this.computeShowNum(objc.pv)
}
return ''
}
addItems() {
Logger.debug(TAG, 'addItems')
this.currentPage++
PageViewModel.getLiveReviewUrl(this.currentPage, this.pageSize).then((liveReviewDTO) => {
this.operDataList.push(...liveReviewDTO.list)
this.getLiveRoomDataInfo(this.operDataList)
Logger.debug(TAG, 'addItems after: ' + this.operDataList.length)
})
}
private getLiveDetailIds(list: ContentDTO[]): string {
let idList: string[] = []
list.forEach(item => {
idList.push(item.objectId)
});
return idList.join(',')
}
private computeShowNum(count: number): string {
if (count >= 10000) {
let num = (count / 10000).toFixed(1)
if (Number(num.substring(num.length - 1)) == 0) {
num = num.substring(0, num.length - 2)
}
return num + '万人参加'
}
return `${count}人参加`
}
}
... ...
... ... @@ -3,6 +3,7 @@ import { WDRouterPage, WDRouterRule } from 'wdRouter/Index'
import { WDMessageCenterMessageType } from '../../../model/InteractMessageModel'
import MinePageDatasModel from '../../../model/MinePageDatasModel'
import { MessageItem } from '../../../viewmodel/MessageItem'
import { CustomPullToRefresh } from '../../reusable/CustomPullToRefresh'
import { CustomTitleUI } from '../../reusable/CustomTitleUI'
import { MessageListItemUI } from './MessageListItemUI'
... ... @@ -11,6 +12,7 @@ const TAG = "MessageListUI"
@Component
export struct MessageListUI {
@State msgData: MessageItem[] = []
private scroller: Scroller = new Scroller();
aboutToAppear() {
this.msgData = MinePageDatasModel.getMessageData()
... ... @@ -138,45 +140,72 @@ export struct MessageListUI {
//标题栏目
CustomTitleUI({ titleName: "消息" })
List() {
ForEach(this.msgData, (item: MessageItem, index: number) => {
ListItem() {
MessageListItemUI({ item: item, index: index })
}
.padding({ left: "31lpx", right: "31lpx" })
.onClick(() => {
switch (index) {
case 0: //互动消息
if(item.unReadCount > 0){
this.sendEnterEvent(WDMessageCenterMessageType.WDMessageCenterMessageType_Interact)
}
WDRouterRule.jumpWithPage(WDRouterPage.interactMessagePage)
break;
case 1: //预约消息
if(item.unReadCount > 0){
this.sendEnterEvent(WDMessageCenterMessageType.WDMessageCenterMessageType_Subscribe)
}
WDRouterRule.jumpWithPage(WDRouterPage.subscribeMessagePage)
break;
case 2: //历史推送
break;
case 3: //系统消息
break;
}
})
.height('154lpx')
.width("100%")
})
}
CustomPullToRefresh({
alldata:this.msgData,
scroller:this.scroller,
customList:()=>{
this.ListLayout()
},
onRefresh:(resolve)=>{
if(resolve) resolve('刷新成功')
},
onLoadMore:(resolve)=> {
}
})
}
.backgroundColor($r('app.color.white'))
.height('100%')
.width('100%')
}
@Builder ListLayout(){
List({scroller: this.scroller}) {
ForEach(this.msgData, (item: MessageItem, index: number) => {
ListItem() {
MessageListItemUI({ item: item, index: index })
}
.padding({ left: "31lpx", right: "31lpx" })
.onClick(() => {
switch (index) {
case 0: //互动消息
if(item.unReadCount > 0){
this.sendEnterEvent(WDMessageCenterMessageType.WDMessageCenterMessageType_Interact)
}
WDRouterRule.jumpWithPage(WDRouterPage.interactMessagePage)
break;
case 1: //预约消息
if(item.unReadCount > 0){
this.sendEnterEvent(WDMessageCenterMessageType.WDMessageCenterMessageType_Subscribe)
}
WDRouterRule.jumpWithPage(WDRouterPage.subscribeMessagePage)
break;
case 2: //历史推送
break;
case 3: //系统消息
break;
}
})
.height('154lpx')
.width("100%")
})
}
}
sendEnterEvent(type:number){
MinePageDatasModel.sendEnterMessageData(type).then((value) => {
console.log(TAG, "消息已读")
this.msgData.forEach((item) => {
if (item.title == "预约消息" && type === 2) {
if(item.unReadCount > 0){
item.unReadCount = 0
}
}else if(item.title == "互动消息" && type === 1){
if(item.unReadCount > 0){
item.unReadCount = 0
}
}
})
}).catch((err: Error) => {
console.log(TAG, JSON.stringify(err))
})
... ...
... ... @@ -2,6 +2,7 @@ import { LazyDataSource, StringUtils } from 'wdKit/Index';
import { Remark, SubscribeMessageModel,
WDMessageCenterMessageType } from '../../../../model/InteractMessageModel';
import MinePageDatasModel from '../../../../model/MinePageDatasModel';
import { CustomPullToRefresh } from '../../../reusable/CustomPullToRefresh';
import { CustomTitleUI } from '../../../reusable/CustomTitleUI';
import { ListHasNoMoreDataUI } from '../../../reusable/ListHasNoMoreDataUI';
import { EmptyComponent } from '../../../view/EmptyComponent';
... ... @@ -17,6 +18,7 @@ export struct SubscribeMessageComponent{
@State hasMore: boolean = true
curPageNum: number = 1;
@State isGetRequest: boolean = false
private scroller: Scroller = new Scroller();
aboutToAppear() {
this.getNewPageData()
... ... @@ -32,33 +34,28 @@ export struct SubscribeMessageComponent{
.height('100%')
.width('100%')
}
} else {
//刷新控件 TODO
//List
List() {
LazyForEach(this.data, (item: SubscribeMessageModel, index: number) => {
ListItem() {
SubscribeListChildComponent({ item: item })
}.width('100%')
.onClick(() => {
})
})
//没有更多数据 显示提示
if (!this.hasMore) {
ListItem() {
ListHasNoMoreDataUI()
CustomPullToRefresh({
alldata:this.data,
scroller:this.scroller,
customList:()=>{
this.ListLayout()
},
onRefresh:(resolve)=>{
this.curPageNum = 1;
this.hasMore = true
this.isGetRequest = false
this.data.clear()
if (!this.isLoading) {
this.getNewPageData()
}
if(resolve) resolve('刷新成功')
},
onLoadMore:(resolve)=> {
if (!this.isLoading) {
//加载分页数据
this.getNewPageData()
}
}
}.width('100%')
.cachedCount(4)
.scrollBar(BarState.Off)
.layoutWeight(1)
.onReachEnd(() => {
if (!this.isLoading) {
//加载分页数据
this.getNewPageData()
}
})
}
... ... @@ -68,6 +65,25 @@ export struct SubscribeMessageComponent{
.width('100%')
}
@Builder ListLayout(){
List({scroller: this.scroller}) {
LazyForEach(this.data, (item: SubscribeMessageModel, index: number) => {
ListItem() {
SubscribeListChildComponent({ item: item })
}.width('100%')
})
//没有更多数据 显示提示
if (!this.hasMore) {
ListItem() {
ListHasNoMoreDataUI()
}
}
}.width('100%')
.cachedCount(4)
.scrollBar(BarState.Off)
.layoutWeight(1)
}
getNewPageData() {
this.isLoading = true
if (this.hasMore) {
... ...
... ... @@ -67,16 +67,17 @@ export struct PrivacySettingPage {
getArrowCell({ item:item, index:index });
}
}.onClick(() => {
if (index != 0) {
if (!item.permission) {
//跳转权限设置
const permissionUtil = new PermissionUtil();
PermissionUtil.reqPermissionsFromUser([item.permissionKey], this).then((res)=>{
item.permission = res;
});
}else{
PermissionUtil.openPermissionsInSystemSettings(this);
}
if (item.privacyName == DiyString) {
return
}
if (!item.permission) {
//跳转权限设置
const permissionUtil = new PermissionUtil();
PermissionUtil.reqPermissionsFromUser([item.permissionKey], this).then((res)=>{
item.permission = res;
});
}else{
PermissionUtil.openPermissionsInSystemSettings(this);
}
})
})
... ...
... ... @@ -49,7 +49,7 @@ export class LiveModel {
success(data.data)
}, (error: Error) => {
fail(error.message)
Logger.debug(TAG + ":error ", error.toString())
Logger.debug(TAG + ":error ", error.message)
})
})
}
... ...
... ... @@ -64,11 +64,11 @@ export struct TabChatComponent {
ListLayout() {
List() {
ListItem() {
// 下拉刷新
RefreshLayout({
refreshBean: new RefreshLayoutBean(this.pageModel.isVisiblePullDown, this.pageModel.pullDownRefreshImage,
this.pageModel.pullDownRefreshText, this.pageModel.pullDownRefreshHeight)
})
// 下拉刷新 TODO 待对接新的下拉刷新组件
// RefreshLayout({
// refreshBean: new RefreshLayoutBean(this.pageModel.isVisiblePullDown, this.pageModel.pullDownRefreshImage,
// this.pageModel.pullDownRefreshText, this.pageModel.pullDownRefreshHeight)
// })
}
ForEach(this.liveChatList, (item: LiveRoomItemBean) => {
... ...
... ... @@ -26,32 +26,57 @@ export struct TabComponent {
}
build() {
Tabs({ barPosition: BarPosition.Start, index: this.currentIndex, controller: this.controller }) {
ForEach(this.tabs, (item: string, index: number) => {
TabContent() {
if ('简介' === item) {
TabInfoComponent()
} else if ('直播间' === item) {
TabLiveComponent()
} else if ('大家聊' === item) {
TabChatComponent()
Stack({alignContent: Alignment.TopStart}) {
Tabs({ barPosition: BarPosition.Start, index: this.currentIndex, controller: this.controller }) {
ForEach(this.tabs, (item: string, index: number) => {
TabContent() {
if ('简介' === item) {
TabInfoComponent()
} else if ('直播间' === item) {
TabLiveComponent()
} else if ('大家聊' === item) {
TabChatComponent()
}
}
}.tabBar(this.tabBuilder(index, item))
.backgroundColor('#F5F5F5')
}, (item: string, index: number) => {
return item + index
.backgroundColor('#F5F5F5')
}, (item: string, index: number) => {
return item + index
})
}
.layoutWeight(1)
.vertical(false)
.barMode(BarMode.Fixed)
.barHeight(48)
.animationDuration(100)
.onChange((index: number) => {
this.currentIndex = index
})
}
.layoutWeight(1)
.vertical(false)
.barMode(BarMode.Fixed)
.barWidth(70 * this.tabs.length)
.barHeight(48)
.animationDuration(100)
.onChange((index: number) => {
this.currentIndex = index
})
.backgroundColor(Color.White)
.backgroundColor(Color.White)
// 页签
Row() {
Scroll() {
Row({space: '24vp'}) {
ForEach(this.tabs, (item: string, index: number) => {
this.tabBuilder(index, item)
})
}
.width('100%')
.justifyContent(FlexAlign.Center)
}
.backgroundColor(Color.White)
.align(Alignment.Start)
.scrollable(ScrollDirection.Horizontal)
.scrollBar(BarState.Off)
.width('100%')
}
.backgroundColor(Color.White)
.height('48vp')
.alignItems(VerticalAlign.Bottom)
.width('100%')
}.layoutWeight(1)
}
@Builder
... ... @@ -60,7 +85,7 @@ export struct TabComponent {
Text(name)
.margin({ top: 6 })
.fontColor(this.currentIndex === index ? this.selectedFontColor : this.fontColor)
.fontSize('18fp')
.fontSize('18vp')
.fontWeight(this.currentIndex === index ? 600 : 400)
Divider()
.strokeWidth(2)
... ... @@ -68,7 +93,13 @@ export struct TabComponent {
.width(15)
.color('#CB0000')
.visibility(this.currentIndex === index ? Visibility.Visible : Visibility.Hidden)
}.width('100%')
}.justifyContent(FlexAlign.Center)
.constraintSize({ minWidth: 35 })
.height('48vp')
.onClick(() => {
this.controller.changeIndex(index)
this.currentIndex = index
})
}
aboutToDisappear(): void {
... ...
... ... @@ -46,11 +46,11 @@ export struct TabLiveComponent {
ListLayout() {
List() {
ListItem() {
// 下拉刷新
RefreshLayout({
refreshBean: new RefreshLayoutBean(this.pageModel.isVisiblePullDown, this.pageModel.pullDownRefreshImage,
this.pageModel.pullDownRefreshText, this.pageModel.pullDownRefreshHeight)
})
// 下拉刷新 TODO 待对接新的下拉刷新组件
// RefreshLayout({
// refreshBean: new RefreshLayoutBean(this.pageModel.isVisiblePullDown, this.pageModel.pullDownRefreshImage,
// this.pageModel.pullDownRefreshText, this.pageModel.pullDownRefreshHeight)
// })
}
ForEach(this.liveList, (item: LiveRoomItemBean) => {
... ...
... ... @@ -11,3 +11,7 @@ export { PlayerConstants } from "./src/main/ets/constants/PlayerConstants"
export { SpeedBean } from "./src/main/ets/bean/SpeedBean"
export { DateFormatUtil } from "./src/main/ets/utils/DateFormatUtil"
export { WDAliPlayerController } from "./src/main/ets/controller/WDAliPlayerController"
export { WDListPlayerData, WDAliListPlayerController } from "./src/main/ets/controller/WDAliListPlayerController"
\ No newline at end of file
... ...
... ... @@ -7,6 +7,7 @@
"main": "Index.ets",
"version": "1.0.0",
"dependencies": {
"wdKit": "file:../../commons/wdKit"
"wdKit": "file:../../commons/wdKit",
"premierlibrary": "file:./libs/premierlibrary.har"
}
}
... ...
... ... @@ -5,6 +5,8 @@ export class PlayerConstants {
static readonly STATUS_START: number = 1;
static readonly STATUS_PAUSE: number = 2;
static readonly STATUS_STOP: number = 3;
static readonly STATUS_ERROR: number = 4;
static readonly STATUS_COMPLETION: number = 5;
static readonly OPERATE_STATE: Array<string> = ['prepared','playing', 'paused', 'completed'];
... ...
import { AliPlayerFactory, AliPlayer, InfoBean, UrlSource, ErrorInfo, InfoCode } from 'premierlibrary';
import {
idle,
initalized,
prepared,
started,
paused,
stopped,
completion,
error} from 'premierlibrary/src/main/ets/com/aliyun/player/IPlayer';
import { AliListPlayer } from 'premierlibrary/src/main/ets/com/aliyun/player/AliListPlayer'
import { initGlobalPlayerSettings, setupPlayerConfig } from '../utils/GlobalSetting';
import prompt from '@ohos.promptAction';
import { Logger } from '../utils/Logger';
import { PlayerConstants, AVPlayerStatus, Events } from '../constants/PlayerConstants';
export interface WDListPlayerData {
uid: string
url: string
surfaceId?: string
}
/*
* 此播放器为阿里播放器鸿蒙版本封装,可播放单个视频、列表多个视频
* 列表上下滑场景用:WDAliListPlayerController
*
* 阿里文档链接:https://help.aliyun.com/zh/apsara-video-sdk/developer-reference/integrated-hongmeng-harmonyos-next-framework-player-sdk
*/
@Observed
export class WDAliListPlayerController {
private initPromise: Promise<void>;
private avPlayer?: AliListPlayer;
// 内部播放器状态
private avPlayerStatus: number = idle
private duration: number = 0;
private status: number = PlayerConstants.STATUS_IDLE;
private loop: boolean = false;
private url: string = '';
private surfaceId: string = '';
private playSpeed: number = 1;
private seekTime: number = 0;
private positionY: number = 0;
private startTime: number = 0
public errorCode?: number
public errorMesage?: string
public onVideoSizeChange?: (width: number, height: number) => void;
public onBufferUpdate?: (buffered: number, duration: number) => void;
public onTimeUpdate?: (position: number, duration: number) => void;
public onVolumeUpdate?: (volume: number) => void;
// 播放完成,决定是否继续播放回调
public continue?: () => void;
// 准备完成,决定是否播放回调。如果不实现,则自动播放
public onCanplay?: () => void;
public onStatusChange?: (status: number) => void;
public onFirstFrameDisplay?: () => void
//// ------------ 以下为列表播放器属性
private playSources: WDListPlayerData[] = []
private currentPlayRecord?: WDListPlayerData
constructor() {
Logger.info("初始化")
initGlobalPlayerSettings()
this.initPromise = this.createAVPlayer();
}
/**
* 创建 videoPlayer对象
*/
private createAVPlayer(): Promise<void> {
return new Promise((resolve, reject) => {
Logger.debug("开始创建")
let traceId = ''
this.avPlayer = AliPlayerFactory.createAliListPlayer(getContext(), traceId)
if (this.avPlayer) {
Logger.debug("创建完成1")
setupPlayerConfig(this.avPlayer!)
this.bindState();
resolve();
} else {
Logger.error("创建完成0")
Logger.error('[WDPlayerController] createAvPlayer fail!');
reject();
}
});
}
public destory() {
Logger.debug("播放器销毁")
this.avPlayer?.stop()
this.avPlayer?.release()
this.playSources = []
this.currentPlayRecord = undefined
}
/**
* AliPlayer 绑定事件.
*/
private bindState() {
this.avPlayer?.setOnPreparedListener({
// 当调用play()方法后,会调用
onPrepared: () => {
this.duration = this.avPlayer?.getDuration();
Logger.debug("已准备好", `${this.duration}`)
}
}
);
this.avPlayer?.setOnRenderingStartListener({
onRenderingStart: () => {
Logger.debug("首帧开始显示")
if (this.onFirstFrameDisplay) {
this.onFirstFrameDisplay()
}
}
});
this.avPlayer?.setOnCompletionListener({
onCompletion: () => {
Logger.debug("播放完成")
}
});
this.avPlayer?.setOnInfoListener({
onInfo: (bean: InfoBean) => {
if (bean.getCode() === InfoCode.CurrentPosition) {
let position : number = bean.getExtraValue()
Logger.debug(`播放进度条:${position}/ ${this.duration}`)
this.initProgress(position);
} else if (bean.getCode() === InfoCode.BufferedPosition) {
let buffer : number = bean.getExtraValue()
if (this.onBufferUpdate) {
this.onBufferUpdate(buffer, this.duration)
}
} else if (bean.getCode() === InfoCode.SwitchToSoftwareVideoDecoder) {
Logger.debug(`DOWNGRADE TO SOFTWARE DECODE`)
// this.mSwitchedToSoftListener?.onSwitched();
}
}
});
this.avPlayer?.setOnStateChangedListener({
onStateChanged: (status: number) => {
this.avPlayerStatus = status
Logger.debug("status update:" + `${this.getStatusStringWith(status)}`)
switch (status) {
case initalized: {
//this.avPlayer?.prepare();
} break
case prepared: {
if (this.startTime) {
this.setSeekTime(this.startTime, SliderChangeMode.Begin);
}
this.duration = this.avPlayer?.getDuration();
if (this.onVideoSizeChange) {
this.onVideoSizeChange(this.avPlayer?.getVideoWidth(), this.avPlayer?.getVideoHeight());
}
if (this.onCanplay) {
this.onCanplay()
} else {
this.play()
}
} break
case started: {
this.setBright();
this.status = PlayerConstants.STATUS_START;
this.watchStatus();
} break
case paused: {
this.status = PlayerConstants.STATUS_PAUSE;
this.watchStatus();
} break
case stopped: {
this.status = PlayerConstants.STATUS_STOP;
this.watchStatus();
} break
case completion: {
this.status = PlayerConstants.STATUS_COMPLETION;
this.watchStatus();
if (this.continue) {
this.continue();
} else {
//TODO:
//this.duration = 0;
//this.url = this.avPlayer.url || '';
//this.avPlayer.reset();
}
} break
case error: {
// 这里拿不到错误信息
// this.status = PlayerConstants.STATUS_ERROR;
// this.watchStatus();
}
}
}
});
this.avPlayer?.setOnErrorListener({
onError:(errorInfo) => {
Logger.error("播放错误", JSON.stringify(errorInfo))
this.errorCode = errorInfo.getCode()
this.errorMesage = errorInfo.getMsg()
this.status = PlayerConstants.STATUS_ERROR;
this.watchStatus();
}
});
this.avPlayer?.setOnLoadingStatusListener({
onLoadingBegin: () => {
// Logger.error("开始加载。。。")
},
onLoadingProgress: (percent: number, netSpeed: number) => {
// this.loadingProgress = percent;
// this.loadingSpeed = netSpeed;
},
onLoadingEnd: () => {
// Logger.error("结束加载")
// this.showLoadingScene = false;
// this.loadingProgress = 0;
// this.loadingSpeed = 0;
}
});
this.avPlayer?.setOnSeekCompleteListener({
onSeekComplete: () => {
this.initProgress(this.avPlayer?.getCurrentPosition());
}
})
}
private getStatusStringWith(status: number) : string {
switch (status) {
case idle: return 'idle'
case initalized: return 'initalized'
case prepared: return 'prepared'
case started: return 'started'
case paused: return 'paused'
case stopped: return 'stopped'
case completion: return 'completion'
case error: return 'error'
}
return 'unknow'
}
public setXComponentController(controller: XComponentController) {
this.setSurfaceId(controller.getXComponentSurfaceId())
}
public setSurfaceId(surfaceId: string) {
this.surfaceId = surfaceId
}
public async addSources(sources: WDListPlayerData[]) {
if (this.avPlayer == null) {
Logger.info("等待播放器初始化")
await this.initPromise;
}
if (this.avPlayer == null) {
return
}
/// 追加数据源
this.playSources.splice(this.playSources.length, 0, ...sources)
sources.map(data => {
this.avPlayer?.addUrl(data.url, data.uid)
})
}
public moveTo(uid: string, surfaceId: string) {
let uidDatas = this.playSources.filter(data => data.uid === uid)
if (uidDatas.length == 0) {
Logger.info("请先addSources()添加数据源url" + uid)
return
}
this.currentPlayRecord = uidDatas[0]
this.avPlayer?.setSurfaceId(surfaceId)
// this.setAliPlayerURL(this.currentPlayRecord.url)
let result = this.avPlayer?.moveTo(uid)
Logger.info("moveTo" + uid + ` result:${result}`)
this.avPlayer?.prepare()
}
private setAliPlayerURL(url: string) {
let urlSource : UrlSource = new UrlSource()
urlSource.setUri(url)
this.avPlayer?.setUrlDataSource(urlSource)
}
private release() {
if (this.avPlayer == null) {
return
}
this.avPlayer.release()
this.avPlayer = undefined
}
public pause() {
Logger.debug("暂停", this.url)
this.avPlayer?.pause();
}
public play() {
Logger.debug("播放", this.url)
this.avPlayer?.start();
}
public stop() {
Logger.debug("停止", this.url)
this.avPlayer?.stop();
}
public setLoop(loop: boolean) {
this.loop = loop;
this.avPlayer?.setLoop(loop);
}
public setMute(mute: boolean) {
this.avPlayer?.setMute(mute)
}
public setSpeed(playSpeed: number) {
this.playSpeed = playSpeed;
this.avPlayer?.setSpeed(this.playSpeed);
}
public switchPlayOrPause() {
if (this.avPlayerStatus == started) {
this.avPlayer?.pause();
} else if (this.avPlayerStatus == completion) {
this.avPlayer?.seekTo(0, 0)
this.avPlayer?.start()
} else {
this.avPlayer?.start();
}
}
public setSeekTime(value: number, mode: SliderChangeMode) {
// if (this.avPlayer == null) {
// await this.initPromise;
// }
// if (this.avPlayer == null) {
// return
// }
// if (mode == SliderChangeMode.Begin) {
// this.seekTime = value * 1000;
// this.avPlayer?.seek(this.seekTime, media.SeekMode.SEEK_PREV_SYNC);
// }
if (mode === SliderChangeMode.Moving) {
// this.progressThis.progressVal = value;
// this.progressThis.currentTime = DateFormatUtil.secondToTime(Math.floor(value * this.duration /
// 100 / 1000));
}
if (mode === SliderChangeMode.End) {
this.seekTime = Math.floor(value * this.duration / 100);
this.avPlayer?.seekTo(this.seekTime, 0);
}
}
public setBright() {
// globalThis.windowClass.setWindowBrightness(this.playerThis.bright)
}
public getStatus() {
return this.status;
}
public getPlayer() {
return this.avPlayer != undefined
}
initProgress(time: number) {
if (this.onTimeUpdate) {
this.onTimeUpdate(time, this.duration);
}
}
resetProgress() {
this.seekTime = 0;
this.duration = 0;
}
onVolumeActionStart(event: GestureEvent) {
this.positionY = event.offsetY;
}
onBrightActionStart(event: GestureEvent) {
this.positionY = event.offsetY;
}
volume: number = 1
onVolumeActionUpdate(event: GestureEvent) {
if (!this.avPlayer) {
return
}
if (this.avPlayerStatus != prepared &&
this.avPlayerStatus != started &&
this.avPlayerStatus != paused &&
this.avPlayerStatus != completion) {
return;
}
let changeVolume = (event.offsetY - this.positionY) / 300;
let currentVolume = this.volume - changeVolume;
if (currentVolume > 1) {
currentVolume = 1;
}
if (currentVolume <= 0) {
currentVolume = 0;
}
this.volume = currentVolume;
this.avPlayer?.setVolume(this.volume);
this.positionY = event.offsetY;
if (this.onVolumeUpdate) {
this.onVolumeUpdate(this.volume);
}
console.log("volume : " + this.volume)
}
onBrightActionUpdate(event: GestureEvent) {
// if (!this.playerThis.volumeShow) {
// this.playerThis.brightShow = true;
// let changeBright = (this.positionY - event.offsetY) / globalThis.screenHeight;
// let currentBright = this.playerThis.bright + changeBright;
// let brightMinFlag = currentBright <= 0;
// let brightMaxFlag = currentBright > 1;
// this.playerThis.bright = brightMinFlag ? 0 :
// (brightMaxFlag ? 1 : currentBright);
// this.setBright();
// this.positionY = event.offsetY;
// }
}
onActionEnd() {
setTimeout(() => {
this.positionY = 0;
}, 200);
}
watchStatus() {
console.log('watchStatus', this.status)
if (this.onStatusChange) {
this.onStatusChange(this.status)
}
// if (this.status === PlayConstants.STATUS_START) {
// globalThis.windowClass.setWindowKeepScreenOn(true);
// } else {
// globalThis.windowClass.setWindowKeepScreenOn(false);
// }
}
playError(msg?: string) {
prompt.showToast({
duration: 3000,
message: msg ? msg : "请检查地址输入正确且网络正常"
});
}
setStartTime(time?: number) {
this.startTime = time ?? 0;
}
}
\ No newline at end of file
... ...
import { AliPlayerFactory, AliPlayer, InfoBean, UrlSource, ErrorInfo, InfoCode } from 'premierlibrary';
import {
idle,
initalized,
prepared,
started,
paused,
stopped,
completion,
error} from 'premierlibrary/src/main/ets/com/aliyun/player/IPlayer';
import { initGlobalPlayerSettings, setupPlayerConfig } from '../utils/GlobalSetting';
import prompt from '@ohos.promptAction';
import { Logger } from '../utils/Logger';
import { PlayerConstants, AVPlayerStatus, Events } from '../constants/PlayerConstants';
/*
* 此播放器为阿里播放器鸿蒙版本封装,可播放单个视频、或直播
* 列表上下滑场景用:WDListPlayerController
*
* 阿里文档链接:https://help.aliyun.com/zh/apsara-video-sdk/developer-reference/integrated-hongmeng-harmonyos-next-framework-player-sdk
*/
@Observed
export class WDAliPlayerController {
private initPromise: Promise<void>;
private avPlayer?: AliPlayer;
// 内部播放器状态
private avPlayerStatus: number = idle
private duration: number = 0;
private status: number = PlayerConstants.STATUS_IDLE;
private loop: boolean = false;
private url: string = '';
private surfaceId: string = '';
private playSpeed: number = 1;
private seekTime: number = 0;
private positionY: number = 0;
private startTime: number = 0
public errorCode?: number
public errorMesage?: string
public onVideoSizeChange?: (width: number, height: number) => void;
public onBufferUpdate?: (buffered: number, duration: number) => void;
public onTimeUpdate?: (position: number, duration: number) => void;
public onVolumeUpdate?: (volume: number) => void;
// 播放完成,决定是否继续播放回调
public continue?: () => void;
// 准备完成,决定是否播放回调。如果不实现,则自动播放
public onCanplay?: () => void;
public onStatusChange?: (status: number) => void;
public onFirstFrameDisplay?: () => void
constructor() {
Logger.info("初始化")
initGlobalPlayerSettings()
this.initPromise = this.createAVPlayer();
}
/**
* 创建 videoPlayer对象
*/
private createAVPlayer(): Promise<void> {
return new Promise((resolve, reject) => {
Logger.debug("开始创建")
let traceId = ''
this.avPlayer = AliPlayerFactory.createAliPlayer(getContext(), traceId)
if (this.avPlayer) {
Logger.debug("创建完成1")
setupPlayerConfig(this.avPlayer!)
this.bindState();
resolve();
} else {
Logger.error("创建完成0")
Logger.error('[WDPlayerController] createAvPlayer fail!');
reject();
}
});
}
public destory() {
Logger.debug("播放器销毁")
this.avPlayer?.stop()
this.avPlayer?.release()
}
/**
* AliPlayer 绑定事件.
*/
private bindState() {
this.avPlayer?.setOnPreparedListener({
// 当调用play()方法后,会调用
onPrepared: () => {
this.duration = this.avPlayer?.getDuration();
Logger.debug("已准备好", `${this.duration}`)
}
}
);
this.avPlayer?.setOnRenderingStartListener({
onRenderingStart: () => {
Logger.debug("首帧开始显示")
if (this.onFirstFrameDisplay) {
this.onFirstFrameDisplay()
}
}
});
this.avPlayer?.setOnCompletionListener({
onCompletion: () => {
Logger.debug("播放完成")
}
});
this.avPlayer?.setOnInfoListener({
onInfo: (bean: InfoBean) => {
if (bean.getCode() === InfoCode.CurrentPosition) {
let position : number = bean.getExtraValue()
Logger.debug(`播放进度条:${position}/ ${this.duration}`)
this.initProgress(position);
} else if (bean.getCode() === InfoCode.BufferedPosition) {
let buffer : number = bean.getExtraValue()
if (this.onBufferUpdate) {
this.onBufferUpdate(buffer, this.duration)
}
} else if (bean.getCode() === InfoCode.SwitchToSoftwareVideoDecoder) {
Logger.debug(`DOWNGRADE TO SOFTWARE DECODE`)
// this.mSwitchedToSoftListener?.onSwitched();
}
}
});
this.avPlayer?.setOnStateChangedListener({
onStateChanged: (status: number) => {
this.avPlayerStatus = status
Logger.debug("status update:" + `${this.getStatusStringWith(status)}`)
switch (status) {
case initalized: {
//this.avPlayer?.prepare();
} break
case prepared: {
if (this.startTime) {
this.setSeekTime(this.startTime, SliderChangeMode.Begin);
}
this.duration = this.avPlayer?.getDuration();
if (this.onVideoSizeChange) {
this.onVideoSizeChange(this.avPlayer?.getVideoWidth(), this.avPlayer?.getVideoHeight());
}
if (this.onCanplay) {
this.onCanplay()
} else {
this.play()
}
} break
case started: {
this.setBright();
this.status = PlayerConstants.STATUS_START;
this.watchStatus();
} break
case paused: {
this.status = PlayerConstants.STATUS_PAUSE;
this.watchStatus();
} break
case stopped: {
this.status = PlayerConstants.STATUS_STOP;
this.watchStatus();
} break
case completion: {
this.status = PlayerConstants.STATUS_COMPLETION;
this.watchStatus();
if (this.continue) {
this.continue();
} else {
//TODO:
//this.duration = 0;
//this.url = this.avPlayer.url || '';
//this.avPlayer.reset();
}
} break
case error: {
// 这里拿不到错误信息
// this.status = PlayerConstants.STATUS_ERROR;
// this.watchStatus();
}
}
}
});
this.avPlayer?.setOnErrorListener({
onError:(errorInfo) => {
Logger.error("播放错误", JSON.stringify(errorInfo))
this.errorCode = errorInfo.getCode()
this.errorMesage = errorInfo.getMsg()
this.status = PlayerConstants.STATUS_ERROR;
this.watchStatus();
}
});
this.avPlayer?.setOnLoadingStatusListener({
onLoadingBegin: () => {
// Logger.error("开始加载。。。")
},
onLoadingProgress: (percent: number, netSpeed: number) => {
// this.loadingProgress = percent;
// this.loadingSpeed = netSpeed;
},
onLoadingEnd: () => {
// Logger.error("结束加载")
// this.showLoadingScene = false;
// this.loadingProgress = 0;
// this.loadingSpeed = 0;
}
});
this.avPlayer?.setOnSeekCompleteListener({
onSeekComplete: () => {
this.initProgress(this.avPlayer?.getCurrentPosition());
}
})
}
private setAliPlayerURL(url: string) {
let urlSource : UrlSource = new UrlSource()
urlSource.setUri(url)
this.avPlayer?.setUrlDataSource(urlSource)
}
private getStatusStringWith(status: number) : string {
switch (status) {
case idle: return 'idle'
case initalized: return 'initalized'
case prepared: return 'prepared'
case started: return 'started'
case paused: return 'paused'
case stopped: return 'stopped'
case completion: return 'completion'
case error: return 'error'
}
return 'unknow'
}
setXComponentController(controller: XComponentController) {
this.setSurfaceId(controller.getXComponentSurfaceId())
}
setSurfaceId(surfaceId: string) {
this.surfaceId = surfaceId
}
async firstPlay(url: string) {
this.url = url;
if (this.avPlayer == null) {
Logger.info("等待播放器初始化")
await this.initPromise;
} else {
if (this.avPlayerStatus != idle) {
this.destory()
this.initPromise = this.createAVPlayer();
await this.initPromise;
}
}
if (this.avPlayer == null) {
return
}
this.duration = 0
this.errorCode = undefined
this.errorMesage = undefined
this.avPlayerStatus = idle
this.status = PlayerConstants.STATUS_IDLE
this.avPlayer?.setAutoPlay(false)
Logger.debug("开始播放", this.url)
this.setAliPlayerURL(this.url);
Logger.info("设置SurfaceId" + this.surfaceId)
this.avPlayer?.setSurfaceId(this.surfaceId)
this.avPlayer?.prepare()
}
release() {
if (this.avPlayer == null) {
return
}
this.avPlayer.release()
this.avPlayer = undefined
}
pause() {
Logger.debug("暂停", this.url)
this.avPlayer?.pause();
}
play() {
Logger.debug("播放", this.url)
this.avPlayer?.start();
}
stop() {
Logger.debug("停止", this.url)
this.avPlayer?.stop();
}
setLoop(loop: boolean) {
this.loop = loop;
this.avPlayer?.setLoop(loop);
}
setMute(mute: boolean) {
this.avPlayer?.setMute(mute)
}
setSpeed(playSpeed: number) {
this.playSpeed = playSpeed;
this.avPlayer?.setSpeed(this.playSpeed);
}
switchPlayOrPause() {
if (this.avPlayerStatus == started) {
this.avPlayer?.pause();
} else if (this.avPlayerStatus == completion) {
this.avPlayer?.seekTo(0, 0)
this.avPlayer?.start()
} else {
this.avPlayer?.start();
}
}
setSeekTime(value: number, mode: SliderChangeMode) {
// if (this.avPlayer == null) {
// await this.initPromise;
// }
// if (this.avPlayer == null) {
// return
// }
// if (mode == SliderChangeMode.Begin) {
// this.seekTime = value * 1000;
// this.avPlayer?.seek(this.seekTime, media.SeekMode.SEEK_PREV_SYNC);
// }
if (mode === SliderChangeMode.Moving) {
// this.progressThis.progressVal = value;
// this.progressThis.currentTime = DateFormatUtil.secondToTime(Math.floor(value * this.duration /
// 100 / 1000));
}
if (mode === SliderChangeMode.End) {
this.seekTime = Math.floor(value * this.duration / 100);
this.avPlayer?.seekTo(this.seekTime, 0);
}
}
setBright() {
// globalThis.windowClass.setWindowBrightness(this.playerThis.bright)
}
getStatus() {
return this.status;
}
getPlayer() {
return this.avPlayer != undefined
}
initProgress(time: number) {
if (this.onTimeUpdate) {
this.onTimeUpdate(time, this.duration);
}
}
resetProgress() {
this.seekTime = 0;
this.duration = 0;
}
onVolumeActionStart(event: GestureEvent) {
this.positionY = event.offsetY;
}
onBrightActionStart(event: GestureEvent) {
this.positionY = event.offsetY;
}
volume: number = 1
onVolumeActionUpdate(event: GestureEvent) {
if (!this.avPlayer) {
return
}
if (this.avPlayerStatus != prepared &&
this.avPlayerStatus != started &&
this.avPlayerStatus != paused &&
this.avPlayerStatus != completion) {
return;
}
let changeVolume = (event.offsetY - this.positionY) / 300;
let currentVolume = this.volume - changeVolume;
if (currentVolume > 1) {
currentVolume = 1;
}
if (currentVolume <= 0) {
currentVolume = 0;
}
this.volume = currentVolume;
this.avPlayer?.setVolume(this.volume);
this.positionY = event.offsetY;
if (this.onVolumeUpdate) {
this.onVolumeUpdate(this.volume);
}
console.log("volume : " + this.volume)
}
onBrightActionUpdate(event: GestureEvent) {
// if (!this.playerThis.volumeShow) {
// this.playerThis.brightShow = true;
// let changeBright = (this.positionY - event.offsetY) / globalThis.screenHeight;
// let currentBright = this.playerThis.bright + changeBright;
// let brightMinFlag = currentBright <= 0;
// let brightMaxFlag = currentBright > 1;
// this.playerThis.bright = brightMinFlag ? 0 :
// (brightMaxFlag ? 1 : currentBright);
// this.setBright();
// this.positionY = event.offsetY;
// }
}
onActionEnd() {
setTimeout(() => {
this.positionY = 0;
}, 200);
}
watchStatus() {
console.log('watchStatus', this.status)
if (this.onStatusChange) {
this.onStatusChange(this.status)
}
// if (this.status === PlayConstants.STATUS_START) {
// globalThis.windowClass.setWindowKeepScreenOn(true);
// } else {
// globalThis.windowClass.setWindowKeepScreenOn(false);
// }
}
playError(msg?: string) {
prompt.showToast({
duration: 3000,
message: msg ? msg : "请检查地址输入正确且网络正常"
});
}
setStartTime(time?: number) {
this.startTime = time ?? 0;
}
}
\ No newline at end of file
... ...
... ... @@ -144,6 +144,10 @@ export class WDPlayerController {
this.xComponentController = controller
}
setSurfaceId(surfaceId: string) {
this.surfaceId = surfaceId
}
async firstPlay(url: string) {
this.url = url;
if (this.avPlayer == null) {
... ...
... ... @@ -2,6 +2,7 @@ import componentUtils from '@ohos.arkui.componentUtils';
import { WDPlayerController } from '../controller/WDPlayerController'
import { WindowModel } from 'wdKit';
import { Logger } from '../utils/Logger';
import { enableAliPlayer } from '../utils/GlobalSetting';
class Size {
width: Length = "100%";
... ... @@ -74,8 +75,9 @@ export struct WDPlayerRenderLiveView {
Row() {
// 设置为“surface“类型时XComponent组件可以和其他组件一起进行布局和渲染。
XComponent({
id: 'xComponentId',
type: 'surface',
id: enableAliPlayer ? this.insId : 'xComponentId',
type: XComponentType.SURFACE,
libraryname: enableAliPlayer ? "premierlibrary" : undefined,
controller: this.xComponentController
})
.onLoad(async (event) => {
... ... @@ -87,7 +89,11 @@ export struct WDPlayerRenderLiveView {
surfaceWidth: 1920,
surfaceHeight: 720
});
this.playerController?.setXComponentController(this.xComponentController)
if (enableAliPlayer) {
this.playerController?.setSurfaceId(this.insId)
} else {
this.playerController?.setXComponentController(this.xComponentController)
}
if (this.onLoad) {
this.onLoad(event)
}
... ...
... ... @@ -2,6 +2,7 @@ import componentUtils from '@ohos.arkui.componentUtils';
import { WDPlayerController } from '../controller/WDPlayerController'
import { WindowModel } from 'wdKit';
import { Logger } from '../utils/Logger';
import { enableAliPlayer } from '../utils/GlobalSetting';
class Size {
width: Length = "100%";
... ... @@ -73,8 +74,9 @@ export struct WDPlayerRenderVLiveView {
Row() {
// 设置为“surface“类型时XComponent组件可以和其他组件一起进行布局和渲染。
XComponent({
id: 'xComponentId',
type: 'surface',
id: enableAliPlayer ? this.insId : 'xComponentId',
type: XComponentType.SURFACE,
libraryname: enableAliPlayer ? "premierlibrary" : undefined,
controller: this.xComponentController
})
.onLoad(async (event) => {
... ... @@ -84,7 +86,11 @@ export struct WDPlayerRenderVLiveView {
surfaceWidth: 1920,
surfaceHeight: 1080
});
this.playerController?.setXComponentController(this.xComponentController)
if (enableAliPlayer) {
this.playerController?.setSurfaceId(this.insId)
} else {
this.playerController?.setXComponentController(this.xComponentController)
}
if (this.onLoad) {
this.onLoad(event)
}
... ...
... ... @@ -2,6 +2,7 @@ import componentUtils from '@ohos.arkui.componentUtils';
import { WDPlayerController } from '../controller/WDPlayerController'
import { WindowModel } from 'wdKit';
import { Logger } from '../utils/Logger';
import { enableAliPlayer } from '../utils/GlobalSetting';
class Size {
width: Length = "100%";
... ... @@ -77,6 +78,7 @@ export struct WDPlayerRenderView {
XComponent({
id: this.insId,
type: XComponentType.SURFACE,
libraryname: enableAliPlayer ? "premierlibrary" : undefined,
controller: this.xComponentController
})
.onLoad(async (event) => {
... ... @@ -85,7 +87,11 @@ export struct WDPlayerRenderView {
surfaceWidth: 1920,
surfaceHeight: 1080
});
this.playerController?.setXComponentController(this.xComponentController)
if (enableAliPlayer) {
this.playerController?.setSurfaceId(this.insId)
} else {
this.playerController?.setXComponentController(this.xComponentController)
}
if (this.onLoad) {
this.onLoad(event)
}
... ...
import { AliPlayerGlobalSettings, AliPlayer } from 'premierlibrary';
import fs from '@ohos.file.fs';
import common from '@ohos.app.ability.common';
import { error } from 'premierlibrary/src/main/ets/com/aliyun/player/IPlayer';
import { BusinessError } from '@kit.BasicServicesKit';
let currentContext = getContext() as common.UIAbilityContext
export function initGlobalPlayerSettings(context?: common.UIAbilityContext) {
AliPlayerGlobalSettings.setUseHttp2(true);
let filesDir = (context != undefined ? context : currentContext).filesDir;
let cachePath = filesDir + "/player-cache"
fs.stat(cachePath).catch((error: BusinessError) => {
if (error.code = 13900002) {
fs.mkdirSync(cachePath)
}
})
AliPlayerGlobalSettings.enableLocalCache(true,1 * 1024, cachePath)
AliPlayerGlobalSettings.setCacheFileClearConfig(3 * 24 * 6, 1024, 300)
}
export function setupPlayerConfig(player: AliPlayer) {
let config = player.getConfig()
if (config) {
config.mMaxDelayTime = 500
config.mMaxBufferDuration = 50000
config.mHighBufferDuration = 3000
config.mStartBufferDuration = 50
player.setConfig(config)
}
}
/*
* 开启前注意:
* 1、配置好包名对应的license文件
* 2、页面组件播放器控制器使用WDAliPlayerController
* 3、WDAliListPlayerController 暂时由于SDK问题,不能使用
* 4、
* */
export const enableAliPlayer = false
\ No newline at end of file
... ...
... ... @@ -9,6 +9,22 @@
"2in1"
],
"deliveryWithInstall": true,
"pages": "$profile:main_pages"
"pages": "$profile:main_pages",
"metadata": [
{
"name": "com.aliyun.alivc_license.licensekey",
"value": "IoKwpV6clXePXoR4rf67e402d71b34952ac19b24d13ecf8c5"
},
{
"name": "com.aliyun.alivc_license.licensefile",
"value": "AliVideoCert-com_peopledailychina_hosactivity-20240514172039.crt"
},
{
"name": "com.aliyun.alivc_license.service_env",
// "value": "PreRelease"
"value": "Release"
}
]
}
}
\ No newline at end of file
... ...
... ... @@ -75,7 +75,7 @@ export struct UpgradeTipDialog {
Row().width("100%").height(1).backgroundColor("#50E6E6E6")
Button() {
Text("立即升级").fontColor(Color.White)
Text("立即更新").fontColor(Color.White)
}.borderRadius(4)
.buttonStyle(ButtonStyleMode.NORMAL)
... ...
... ... @@ -41,7 +41,7 @@
"requestPermissions": [
{
"name": "ohos.permission.CAMERA",
"reason": "$string:EntryAbility_desc",
"reason": "$string:permission_camera_tip",
"usedScene": {
"abilities": [
"FormAbility"
... ... @@ -51,7 +51,7 @@
},
{
"name": "ohos.permission.READ_MEDIA",
"reason": "$string:EntryAbility_desc",
"reason": "$string:permission_photo_tip",
"usedScene": {
"abilities": [
"FormAbility"
... ... @@ -61,7 +61,7 @@
},
{
"name": "ohos.permission.WRITE_MEDIA",
"reason": "$string:EntryAbility_desc",
"reason": "$string:permission_photo_tip",
"usedScene": {
"abilities": [
"FormAbility"
... ... @@ -71,7 +71,7 @@
},
{
"name": "ohos.permission.APPROXIMATELY_LOCATION",
"reason": "$string:EntryAbility_desc",
"reason": "$string:permission_location_tip",
"usedScene": {
"abilities": [
"FormAbility"
... ... @@ -81,7 +81,7 @@
},
{
"name": "ohos.permission.MICROPHONE",
"reason": "$string:EntryAbility_desc",
"reason": "$string:permission_microphone_tip",
"usedScene": {
"abilities": [
"FormAbility"
... ...
... ... @@ -13,6 +13,22 @@
"value": "$string:app_name"
},
{
"name": "permission_photo_tip",
"value": "开启之后即可用于保存新闻图片到相册、发视频、设置封面、设置头像、缓存图片和视频来展示内容等功能"
},
{
"name": "permission_camera_tip",
"value": "开启之后即可用于拍摄视频、拍摄头像、扫一扫功能"
},
{
"name": "permission_location_tip",
"value": "开启之后可为你推荐你可能感兴趣的内容及附近的相关信息,以提升浏览体验。不授权该权限不影响APP正常使用。"
},
{
"name": "permission_microphone_tip",
"value": "开启之后即可用于收录声音进行拍摄视频、语音搜索、语音评论功能,"
},
{
"name": "dialog_text_title",
"value": "个人隐私保护指引"
},
... ...
-----BEGIN ALI VIDEO CERT-----
LmlsQS5jaUwAAWRjY2FhYTU1OTAxNzE0NDg2OWJlOGJkNzczZTc5ZjAzM2YwMDhiO
WY5ODUwNTc5MGY4NDEyOTRiMzNjMmZiYjg1NGUxZThlNjAwNzRmNTgxZTU0MDY2Mj
RiMGFiM2JkNWVmOTE3ZDE0MDJlNDQ0ZDUwNmExMTc5ZjFlYjYyODQ2MDRiYzdiYjA
zOTI2ZjYyOTE1OWVjYjY0ZDk1ZDhhN2Q5ZWZlOTRjOTdkMTA0Yzc1MWU5OGEwNGY3
OTdkOTdiYTAzMWEyMDFlMzc2Mjg0NGI1MTEyYWRkZDQzNTgyZDA2NTJkYTk0MDk1Y
TIxYjY2NWJmYjY0ZTkwMWQyZGNjNmVjMjY1ODFkYmJjZjBhY2ZmZjFhNDU3NTJjND
QwNTMzZmJlZDk3YTIzMmMyOWQ4YWVkZDY0YmZhZDc2ZDY1MTRiZGU5MmM3YTdjMGZ
iYjI3OTNhNjZiMDEzMjBkODgxYzBhMjA1YTExN2Q1YmU3ZTgyMzYyYzI5MDJhZDNk
MmFiZTcxNTQ5NzI2YzI4NTVjOTc5MWVmZDVjMGU4ND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