Skip to content

Commit

Permalink
refine script to fix videoplayer some play issue (#824)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmyduckx authored Jul 20, 2023
1 parent c1d813b commit ac7553b
Show file tree
Hide file tree
Showing 2 changed files with 213 additions and 54 deletions.
27 changes: 7 additions & 20 deletions assets/cases/ui/21.video-player/video-player-ctrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ export class VideoPlayerCtrl extends Component {
@type(VideoPlayer)
public videoPlayer: VideoPlayer = null!;
@type(Label)
public eventType: Label = null!;
@type(Label)
public playbackRate: Label = null!;
@type(Label)
public stayOnBottom: Label = null!;
Expand Down Expand Up @@ -43,7 +41,6 @@ export class VideoPlayerCtrl extends Component {
break;
}
this.platform.string = `platform: ${sys.platform}`;
this.eventType.string = 'nothing';
}

onStayOnBottom () {
Expand All @@ -65,32 +62,22 @@ export class VideoPlayerCtrl extends Component {

onPlayLocalVideo () {
this.videoPlayer.resourceType = VideoPlayer.ResourceType.LOCAL;
if (this.videoPlayer.clip === this.videClip) {
this.videoPlayer.play();
}
else {
if (this.videoPlayer.clip !== this.videClip){
this.videoPlayer.clip = this.videClip;
}
if (!this.videoPlayer.isPlaying) {
this.videoPlayer.play();
}
}

onPlayRemoteVideo () {
this.videoPlayer.resourceType = VideoPlayer.ResourceType.REMOTE;
const remoteURL = 'https://download.cocos.org/CocosTest/test-case/movie.mp4';
if (this.videoPlayer.remoteURL === remoteURL) {
this.videoPlayer.play();
}
else {
if (this.videoPlayer.remoteURL !== remoteURL) {
this.videoPlayer.remoteURL = remoteURL;
}
}

onEventType (target: VideoPlayerCtrl, type: string) {
this.eventType.string = type;
switch (type) {
case VideoPlayer.EventType.READY_TO_PLAY:
case VideoPlayer.EventType.META_LOADED:
this.videoPlayer.play();
break;
if (!this.videoPlayer.isPlaying) {
this.videoPlayer.play();
}
}

Expand Down
Loading

0 comments on commit ac7553b

Please sign in to comment.