Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refine script to fix videoplayer some play issue #824

Merged
merged 1 commit into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why need to check the status before playing? VideoPlayer will not check the status?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, it may cause to replay.

Copy link
Contributor Author

@mmyduckx mmyduckx Jul 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, we do not have this check in VideoPlayer. And different platform have different strategies when repeatly call play. So I think it's a foolproof way to check in script.

}

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same as above.

}
}

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