Skip to content

Commit

Permalink
修改时间和暂停bug
Browse files Browse the repository at this point in the history
  • Loading branch information
renzhenhua-good-boy committed Jan 30, 2024
1 parent a0b7297 commit 89cb00f
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 76 deletions.
Binary file modified harmony/rn_video.har
Binary file not shown.
26 changes: 13 additions & 13 deletions harmony/rn_video/src/main/ets/RNCVideo.ets
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,16 @@ export struct RNCVideo {
viewHeight:number = 0

aboutToAppear() {
Logger.info(`RNOH in RNCVideo aboutToAppear !}`);
Logger.debug(`RNOH in RNCVideo aboutToAppear !}`);
this.descriptor = this.ctx.descriptorRegistry.getDescriptor<VideoViewDescriptor>(this.tag)
Logger.info(`RNOH in RNCVideo descriptor props, ${JSON.stringify(this.descriptor.props)}`);
Logger.info(`RNOH in RNCVideo descriptor layoutMetrics, ${JSON.stringify(this.descriptor.layoutMetrics)}`);
Logger.debug(`RNOH in RNCVideo descriptor props, ${JSON.stringify(this.descriptor.props)}`);
Logger.debug(`RNOH in RNCVideo descriptor layoutMetrics, ${JSON.stringify(this.descriptor.layoutMetrics)}`);
this.unregisterDescriptorChangesListener = this.ctx.descriptorRegistry.subscribeToDescriptorChanges(this.tag,
(newDescriptor) => {
this.descriptor = (newDescriptor as VideoViewDescriptor)
/*------ 当RN侧属性props有更改 -------*/
Logger.info(`RNOH in RNCVideo descriptor change, `);
Logger.info(`RNOH in RNCVideo newDescriptor props, ${JSON.stringify(this.descriptor.props)}`);
Logger.debug(`RNOH in RNCVideo descriptor change, `);
Logger.debug(`RNOH in RNCVideo newDescriptor props, ${JSON.stringify(this.descriptor.props)}`);
this.updatePropFromDesc()
this.preparePlayer();
}
Expand All @@ -151,9 +151,9 @@ export struct RNCVideo {
(command, args:(string|number)[]) => {
if (command === 'seek') {
//seek
Logger.info(`RNOH in RNCVideo: seek, ${JSON.stringify(args)}`)
Logger.info(`RNOH in RNCVideo: seek, time: ${args[0]}`)
Logger.info(`RNOH in RNCVideo: seek, tolerance: ${args[1]}`)
Logger.debug(`RNOH in RNCVideo: seek, ${JSON.stringify(args)}`)
Logger.debug(`RNOH in RNCVideo: seek, time: ${args[0]}`)
Logger.debug(`RNOH in RNCVideo: seek, tolerance: ${args[1]}`)
this.playVideoModel.setSeekTime(Number(args[0]))
}
});
Expand Down Expand Up @@ -280,22 +280,22 @@ export struct RNCVideo {
}

async getFd(){
Logger.info(`RNOH in RNCVideo getFd, ${(this.src)}`);
Logger.debug(`RNOH in RNCVideo getFd, ${(this.src)}`);
}

async preparePlayer() {
Logger.info(`RNOH in RNCVideo,preparePlayer src= ${(this.srcParam)}`);
Logger.debug(`RNOH in RNCVideo,preparePlayer src= ${(this.srcParam)}`);
if (this.srcParam.startsWith('http')) {
this.type = CommonConstants.TYPE_INTERNET
this.src = this.srcParam
Logger.info(`RNOH in RNCVideo startsWith, finalsrc: ${(this.src)}`);
Logger.debug(`RNOH in RNCVideo startsWith, finalsrc: ${(this.src)}`);
} else {
Logger.info(`RNOH in RNCVideo local, finalsrc: ${(this.src)}`);
Logger.debug(`RNOH in RNCVideo local, finalsrc: ${(this.src)}`);
}
}

onPageHide() {
Logger.info(`RNOH in RNCVideo onPageHide.`);
Logger.debug(`RNOH in RNCVideo onPageHide.`);
this.playVideoModel.pause();
this.isResume = true;
}
Expand Down
2 changes: 1 addition & 1 deletion harmony/rn_video/src/main/ets/common/util/Logger.ets
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ class Logger {
}
}

export default new Logger('VideoPlayer', 0xFF00, true)
export default new Logger('VideoPlayer', 0xFF00, false)
102 changes: 51 additions & 51 deletions harmony/rn_video/src/main/ets/controller/VideoController.ets
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ export class VideoController {
createAVPlayer() {
media.createAVPlayer().then((avPlayer) => {
if (avPlayer) {
Logger.info(`RNOH in ctrl, createAVPlayer isNull: ${avPlayer == null}`);
Logger.debug(`RNOH in ctrl, createAVPlayer isNull: ${avPlayer == null}`);
this.avPlayer = avPlayer;
this.bindState();
Logger.info(`RNOH in ctrl, createAVPlayer after bind`);
Logger.debug(`RNOH in ctrl, createAVPlayer after bind`);
if (this.flagtd) {
this.flagtd = false;
this.avPlayer.url = this.url;
Logger.info(`RNOH in ctrl, createAVPlayer need toplay url,after bind:` + this.url);
Logger.debug(`RNOH in ctrl, createAVPlayer need toplay url,after bind:` + this.url);
} else {
Logger.info(`RNOH in ctrl, createAVPlayer noneed toplay url,after bind`);
Logger.debug(`RNOH in ctrl, createAVPlayer noneed toplay url,after bind`);
}
} else {
Logger.error('RNOH in ctrl, [PlayVideoModel] createAvPlayer fail!');
Expand All @@ -84,7 +84,7 @@ export class VideoController {
* AVPlayer binding event.
*/
bindState() {
Logger.info(`RNOH in ctrl, bindState`);
Logger.debug(`RNOH in ctrl, bindState`);
if (this.avPlayer){

this.onStateChange();
Expand All @@ -94,23 +94,23 @@ export class VideoController {
});

this.avPlayer.on(Events.DURATION_UPDATE, (durationA) => {
Logger.info('RNOH in ctrl,durationUpdate success,new duration is :' + durationA)
Logger.debug('RNOH in ctrl,durationUpdate success,new duration is :' + durationA)
this.duration = durationA == 0 ? 0 : Math.floor(durationA / 1000); // ms->s
})

this.avPlayer.on(Events.ERROR, (error) => {
Logger.info(`RNOH in ctrl, event error: ${JSON.stringify(error)}`);
Logger.debug(`RNOH in ctrl, event error: ${JSON.stringify(error)}`);
this.playError(JSON.stringify(error));
})

this.avPlayer.on(Events.END_OF_STREAM, () => {
Logger.info('RNOH in ctrl, END_OF_STREAM')
Logger.debug('RNOH in ctrl, END_OF_STREAM')
this.onVideoEnd();
})

this.avPlayer.on(Events.BUFFERING_UPDATE, (infoType: media.BufferingInfoType, value: number) => {
/* 播放缓存事件回调方法。BufferingInfoType为BUFFERING_PERCENT或CACHED_DURATION时,value值有效,否则固定为0。 */
Logger.info('RNOH in ctrl, BUFFERING_UPDATE')
Logger.debug('RNOH in ctrl, BUFFERING_UPDATE')
switch (infoType) {
case media.BufferingInfoType.BUFFERING_START: // 表示缓存开始,
this.onVideoPlaybackStalled();
Expand All @@ -124,7 +124,7 @@ export class VideoController {
/* 此时的value有值,表示缓存百分比*/
break;
case media.BufferingInfoType.CACHED_DURATION: // 表示缓存时长,毫秒(ms)。
Logger.info(`RNOH in ctrl, onVideoProgress CACHED_DURATION value = ${value}`);
Logger.debug(`RNOH in ctrl, onVideoProgress CACHED_DURATION value = ${value}`);
this.mVideoBufferedDuration = Math.floor(value / 1000) // ms--?s
break;
default:
Expand All @@ -133,10 +133,10 @@ export class VideoController {
})

this.avPlayer.on(Events.SEEK_DONE, (seekDoneTime: number) => {
Logger.info(`RNOH in ctrl, seekDone success,and seek time is: ${seekDoneTime} `)
Logger.debug(`RNOH in ctrl, seekDone success,and seek time is: ${seekDoneTime} `)
})
}
Logger.info(`RNOH in ctrl, bindState end`);
Logger.debug(`RNOH in ctrl, bindState end`);
}

/**
Expand Down Expand Up @@ -214,7 +214,7 @@ export class VideoController {
if (this.avPlayer && this.avPlayer.state == 'idle') {
this.avPlayer.url = this.url;
} else {
Logger.info(`RNOH in ctrl, avPlayer no`);
Logger.debug(`RNOH in ctrl, avPlayer no`);
this.flagtd = true;
}
}
Expand Down Expand Up @@ -258,35 +258,35 @@ export class VideoController {
* @return
*/
switchVideo(newUrl: string) {
Logger.info(`RNOH in ctrl switchVideo, state ${JSON.stringify(this.avPlayer.state)}`);
Logger.debug(`RNOH in ctrl switchVideo, state ${JSON.stringify(this.avPlayer.state)}`);
this.bindState();
Logger.info(`RNOH in ctrl switchVideo, 100`);
Logger.info(`RNOH in ctrl switchVideo, state ${JSON.stringify(this.url)},new: ${JSON.stringify(newUrl)}`);
Logger.debug(`RNOH in ctrl switchVideo, 100`);
Logger.debug(`RNOH in ctrl switchVideo, state ${JSON.stringify(this.url)},new: ${JSON.stringify(newUrl)}`);
this.url = newUrl;
Logger.info(`RNOH in ctrl switchVideo, 200`);
Logger.debug(`RNOH in ctrl switchVideo, 200`);
if (this.surfaceId == 0 || this.surfaceId == undefined) {
Logger.info(`RNOH in ctrl switchVideo, 210`);
Logger.debug(`RNOH in ctrl switchVideo, 210`);
return;
}

if ('idle' == (this.avPlayer.state)) {
Logger.info(`RNOH in ctrl switchVideo, 201 ,${this.url}`);
Logger.debug(`RNOH in ctrl switchVideo, 201 ,${this.url}`);
this.avPlayer.url = this.url;
} else {
Logger.info(`RNOH in ctrl switchVideo, 202 ,reset`);
Logger.debug(`RNOH in ctrl switchVideo, 202 ,reset`);
this.avPlayer.reset();
Logger.info(`RNOH in ctrl switchVideo, 202 ,${this.url}`);
Logger.debug(`RNOH in ctrl switchVideo, 202 ,${this.url}`);
}
Logger.info(`RNOH in ctrl switchVideo, 300`);
Logger.info(`RNOH in ctrl switchVideo, state11 ${JSON.stringify(this.avPlayer.state)}`);
Logger.debug(`RNOH in ctrl switchVideo, 300`);
Logger.debug(`RNOH in ctrl switchVideo, state11 ${JSON.stringify(this.avPlayer.state)}`);
}

/**
* Switching Between Video Play and Pause.
*/
switchPlayOrPause(paused: boolean) {
Logger.info(`RNOH in ctrl switchPlayOrPause,state out= ${this.avPlayer.state};paused= ${JSON.stringify(paused)}`);
if (this.status === CommonConstants.STATUS_START && paused) {
Logger.debug(`RNOH in ctrl switchPlayOrPause,state out= ${this.avPlayer.state};paused= ${JSON.stringify(paused)}`);
if (paused) {
this.avPlayer.pause();
} else {
this.avPlayer.play();
Expand All @@ -295,15 +295,15 @@ export class VideoController {

switchRepeat(repeat: boolean) {
this.loop = repeat
Logger.info(`RNOH in ctrl, switchRepeat, ${JSON.stringify(repeat)}`);
Logger.info(`RNOH in ctrl, switchRepeat, ${JSON.stringify(this.playerThis.repeat)}`);
Logger.debug(`RNOH in ctrl, switchRepeat, ${JSON.stringify(repeat)}`);
Logger.debug(`RNOH in ctrl, switchRepeat, ${JSON.stringify(this.playerThis.repeat)}`);
if (this.status === CommonConstants.STATUS_PREPARED ||
this.status === CommonConstants.STATUS_START ||
this.status === CommonConstants.STATUS_PAUSE ||
this.status === CommonConstants.STATUS_COMPLETED
) {
this.avPlayer.loop = this.loop;
Logger.info(`RNOH in ctrl, switchRepeat2, ${JSON.stringify(repeat)}`);
Logger.debug(`RNOH in ctrl, switchRepeat2, ${JSON.stringify(repeat)}`);
}
}

Expand All @@ -323,18 +323,18 @@ export class VideoController {
currentVolume = 1.0
}
}
Logger.info(`RNOH in ctrl, switchMuted, ${JSON.stringify(muted)} ,currentVolume= ${JSON.stringify(currentVolume)}`);
Logger.debug(`RNOH in ctrl, switchMuted, ${JSON.stringify(muted)} ,currentVolume= ${JSON.stringify(currentVolume)}`);
if (this.status === CommonConstants.STATUS_PREPARED ||
this.status === CommonConstants.STATUS_START ||
this.status === CommonConstants.STATUS_PAUSE ||
this.status === CommonConstants.STATUS_COMPLETED
) {
this.avPlayer.setVolume(currentVolume);
Logger.info(`RNOH in ctrl, switchMuted2,currentVolume= ${JSON.stringify(currentVolume)}`);
Logger.debug(`RNOH in ctrl, switchMuted2,currentVolume= ${JSON.stringify(currentVolume)}`);
}

this.avPlayer.on('volumeChange', (vol: number) => {
Logger.info('RNOH in ctrl volumeChange success,and new volume is :' + vol)
Logger.debug('RNOH in ctrl volumeChange success,and new volume is :' + vol)
this.avPlayer.off('volumeChange')
})
}
Expand All @@ -354,24 +354,24 @@ export class VideoController {
* @return
*/
setSeekTime(value: number) {
Logger.info(`RNOH in ctrl setSeekTime== ${JSON.stringify(value)}`);
Logger.debug(`RNOH in ctrl setSeekTime== ${JSON.stringify(value)}`);
this.seekTime = value*1000;
Logger.info(`RNOH in ctrl setSeekTime== ${this.seekTime}`);
Logger.debug(`RNOH in ctrl setSeekTime== ${this.seekTime}`);
/* seek 只能在prepared/playing/paused/complete状态调用 毫秒(ms)*/
if (this.status === CommonConstants.STATUS_PREPARED ||
this.status === CommonConstants.STATUS_START ||
this.status === CommonConstants.STATUS_PAUSE ||
this.status === CommonConstants.STATUS_COMPLETED
) {
this.avPlayer.seek(this.seekTime);
Logger.info(`RNOH in ctrl avPlayer.seek`);
Logger.debug(`RNOH in ctrl avPlayer.seek`);
}
}

/* 初始化播放器状态 */
initProps() {

Logger.info(`RNOH in ctrl, initProps repeat, ${JSON.stringify(this.playerThis.repeat)}`);
Logger.debug(`RNOH in ctrl, initProps repeat, ${JSON.stringify(this.playerThis.repeat)}`);
this.avPlayer.loop = this.playerThis.repeat;

this.mMuted = this.playerThis.muted
Expand All @@ -386,15 +386,15 @@ export class VideoController {
updateProp() {
/* 设置 需要特定状态下设置*/
if (this.avPlayer != null) {
Logger.info(`RNOH in ctrl, updateProp volume, ${JSON.stringify(this.playerThis.volume)}`);
Logger.debug(`RNOH in ctrl, updateProp volume, ${JSON.stringify(this.playerThis.volume)}`);
this.avPlayer.setVolume(this.playerThis.volume); /* 更新音量 */
Logger.info(`RNOH in ctrl, updateProp resizeMode, ${JSON.stringify(this.playerThis.resizeMode)}`);
Logger.debug(`RNOH in ctrl, updateProp resizeMode, ${JSON.stringify(this.playerThis.resizeMode)}`);
/* 更新 resizeMode */
this.convertResizeMode(this.playerThis.resizeMode)
/* 更新音频流类型 */
this.watchStatus();
} else {
Logger.info(`RNOH in ctrl, updateProp : ${JSON.stringify(this.avPlayer)}`);
Logger.debug(`RNOH in ctrl, updateProp : ${JSON.stringify(this.avPlayer)}`);
}

}
Expand Down Expand Up @@ -473,7 +473,7 @@ export class VideoController {
*/
initPlayerThis(playerThis:IPlayPlayer) {
if (playerThis == null) {
Logger.info(`RNOH in ctrl, initPlayerThis is null .`);
Logger.debug(`RNOH in ctrl, initPlayerThis is null .`);
}
this.playerThis = playerThis;
}
Expand All @@ -484,7 +484,7 @@ export class VideoController {
* @param cUri: 当前视频URL
*/
onVideoLoadStart(cUri: string) {
Logger.info(`RNOH in ctrl, onVideoLoadStart URL: ${cUri}`);
Logger.debug(`RNOH in ctrl, onVideoLoadStart URL: ${cUri}`);
this.playPageThis.onVideoLoadStart(cUri);
}

Expand All @@ -495,7 +495,7 @@ export class VideoController {
* @return null
*/
onReadyForDisplay() {
Logger.info(`RNOH in ctrl, onReadyForDisplay`);
Logger.debug(`RNOH in ctrl, onReadyForDisplay`);
this.playPageThis.onReadyForDisplay();
}

Expand All @@ -505,13 +505,13 @@ export class VideoController {
* @param time Current video playback time.
*/
onVideoProgress(currentTime: number) {
Logger.info(`RNOH in ctrl, onVideoProgress currentTime = ${currentTime}`);
let sec = currentTime == 0 ? 0 : Math.floor(currentTime / 1000)
Logger.debug(`RNOH in ctrl, onVideoProgress currentTime = ${currentTime}`);
let sec = currentTime == 0 ? 0 : currentTime / 1000
let playableDuration = this.mVideoBufferedDuration == 0 ? 0 : this.mVideoBufferedDuration
Logger.info(`RNOH in ctrl, onVideoProgress playableDuration = ${playableDuration}`);
Logger.debug(`RNOH in ctrl, onVideoProgress playableDuration = ${playableDuration}`);
let seekableDuration = this.duration == 0 ? 0 : this.duration
Logger.info(`RNOH in ctrl, onVideoProgress duration = ${this.duration}`);
Logger.info(`RNOH in ctrl, onVideoProgress seekableDuration = ${seekableDuration}`);
Logger.debug(`RNOH in ctrl, onVideoProgress duration = ${this.duration}`);
Logger.debug(`RNOH in ctrl, onVideoProgress seekableDuration = ${seekableDuration}`);
this.playPageThis.onVideoProgress(sec, playableDuration, seekableDuration);
}

Expand Down Expand Up @@ -543,7 +543,7 @@ export class VideoController {
this.playPageThis.onVideoLoad(startSecond, this.duration, this.avPlayer.width, this.avPlayer.height, orientationIn)

} else {
Logger.info(`RNOH in ctrl getTrackDescription fail, error:${error}`);
Logger.debug(`RNOH in ctrl getTrackDescription fail, error:${error}`);
}
});
}
Expand All @@ -554,23 +554,23 @@ export class VideoController {
* @param isBuffering Boolean indicating whether buffering is active
*/
onVideoBuffer(isBuffering: boolean) {
Logger.info(`RNOH in ctrl ,onVideoBuffer out:${JSON.stringify(isBuffering)}`);
Logger.debug(`RNOH in ctrl ,onVideoBuffer out:${JSON.stringify(isBuffering)}`);
this.playPageThis.onVideoBuffer(isBuffering)
}

/**
* event video onBuffering start
*/
onVideoPlaybackStalled() {
Logger.info(`RNOH in ctrl ,onVideoPlaybackStalled`);
Logger.debug(`RNOH in ctrl ,onVideoPlaybackStalled`);
this.playPageThis.onVideoPlaybackStalled()
}

/**
* event video onBuffering end
*/
onVideoPlaybackResume() {
Logger.info(`RNOH in ctrl ,onVideoPlaybackResume`);
Logger.debug(`RNOH in ctrl ,onVideoPlaybackResume`);
this.playPageThis.onVideoPlaybackResume()
}

Expand Down Expand Up @@ -633,7 +633,7 @@ export class VideoController {
* An error is reported during network video playback.
*/
playError(errMsg: string) {
Logger.info(`RNOH in ctrl ,onVideoError:${JSON.stringify(errMsg)}`);
Logger.debug(`RNOH in ctrl ,onVideoError:${JSON.stringify(errMsg)}`);
if (this.playPageThis) {
this.playPageThis.onVideoError(errMsg)
}
Expand Down
Loading

0 comments on commit 89cb00f

Please sign in to comment.