Skip to content

Commit

Permalink
Merge pull request #99 from fankw1/sig
Browse files Browse the repository at this point in the history
fix:修复controls 为 true,不循环播放的时候,视频播放完再点击播放,视频画面在最后一帧卡着不动
  • Loading branch information
fankw1 authored Dec 3, 2024
2 parents 561b466 + 65af113 commit 1a96b53
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 17 deletions.
4 changes: 4 additions & 0 deletions harmony/rn_video/src/main/ets/RNCVideo.ets
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ export struct RNCVideo {
}

onVideoEnd(): void {
if(this.repeat == undefined || this.repeat == false)
{
this.paused = true
}
if (this.ctx) {
this.ctx.rnInstance.emitComponentEvent(this.descriptor.tag, RNC_VIDEO_TYPE, {
type: "onVideoEnd"
Expand Down
53 changes: 36 additions & 17 deletions harmony/rn_video/src/main/ets/view/PlayPlayer.ets
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ const TAG: string = 'RNOH in ctrl'

@Component
export struct PlayPlayer {
private playVideoModel: VideoController | undefined = undefined;
@Consume('srcVar') @Watch("onSrcChanged") srcParam: string; // 视频src
@Consume index: number;
@Consume('mutedVar') @Watch("onMutedChanged") muted: boolean;
Expand All @@ -72,17 +71,13 @@ export struct PlayPlayer {
/* 不需要显示 */
@State volumeShow: boolean = PlayConstants.PLAY_PAGE.VOLUME_SHOW;
@State brightShow: boolean = PlayConstants.PLAY_PAGE.BRIGHT_SHOW;
private xComponentController: XComponentController = new XComponentController();
private surfaceID: number = 0;
@Consume videoHeight: number | string;
@Consume videoWidth: number | string;
@State videoJustifyContent: FlexAlign = FlexAlign.Center;
@State videoAlignItems: HorizontalAlign = HorizontalAlign.Center;
@State matrix: object = Matrix4.identity();
private previousSrc: fs.File | string | undefined = undefined
viewWidth: number = 0;
viewHeight: number = 0;
private orientationChange: boolean = true;
listener = mediaquery.matchMediaSync('(orientation: landscape)');
@State sliderWidth: number | string = '80%'
screenWidth: number = 0
Expand All @@ -95,6 +90,13 @@ export struct PlayPlayer {
INACTIVITY_THRESHOLD = 5000
@Consume
isUserPaused: boolean
private playVideoModel: VideoController | undefined = undefined;
private xComponentController: XComponentController = new XComponentController();
private surfaceID: number = 0;
private previousSrc: fs.File | string | undefined = undefined
private orientationChange: boolean = true;
private isProgressSliding: boolean = false
private sliderTimer: number = 0

aboutToAppear(): void {
if (this.controls == true) {
Expand Down Expand Up @@ -345,21 +347,38 @@ export struct PlayPlayer {
.margin({ left: 5 })
.onChange((value: number, mode: SliderChangeMode) => {
let seekValue: number = value
if (this.repeat && value == this.duration) {
return
}
if (this.repeat == false && value == this.duration) {
seekValue = 0
this.startSecond = seekValue
this.playVideoModel?.setSeekTime(seekValue)
this.paused = true
return
}
// 修复循环播放时卡在最后一帧
//滑块滑动结束后再设置seek
if (mode == SliderChangeMode.End || mode == SliderChangeMode.Click) {
if (this.repeat && value == this.duration) {
return
}
if ((this.repeat == undefined || this.repeat == false) && value == this.duration) {
seekValue = 0
//判断是否手动触发滑块,如果是就设置seek
if (this.isProgressSliding) {
this.startSecond = seekValue
this.playVideoModel?.setSeekTime(seekValue)
this.paused = true
return
//判断是否手动触发滑块,如果不是就直接返回
} else {
return
}
}
setTimeout(
() => this.playVideoModel?.setSeekTime(seekValue)
, 100)
, 100);
}
})
.onTouch((event: TouchEvent) => {
//判断手松开再设置seek,增加一个定时器
if (event.type === TouchType.Up) {
this.sliderTimer = setTimeout(() => {
this.isProgressSliding = false;
}, 200);
} else {
clearTimeout(this.sliderTimer);
this.isProgressSliding = true;
}
})

Expand Down

0 comments on commit 1a96b53

Please sign in to comment.