-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVideoController.cs
70 lines (61 loc) · 1.83 KB
/
VideoController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Video;
using WeChatWASM;
public class VideoController : MonoBehaviour
{
public VideoPlayer videoPlayer; // 关联 VideoPlayer 组件
public Button playButton; // 关联播放按钮
public Button pauseButton; // 关联暂停按钮
public string[] videoUrls; // 视频路径
private int currentVideoIndex = 0;
void Start()
{
// 设置视频路径
videoPlayer.url = videoUrls[currentVideoIndex];
// 添加按钮点击事件
playButton.onClick.AddListener(PlayVideo);
pauseButton.onClick.AddListener(PauseVideo);
// 添加视频播放完成事件
videoPlayer.loopPointReached += OnVideoEnd;
}
void PlayVideo()
{
if (videoPlayer.isPaused)
{
videoPlayer.Play(); // 如果视频已暂停,则继续播放
}
}
void PauseVideo()
{
if (videoPlayer.isPlaying)
{
videoPlayer.Pause(); // 暂停视频
}
}
// 视频播放完成时调用的方法
void OnVideoEnd(VideoPlayer vp)
{
WX.ShowModal(new ShowModalOption()
{
title = "提示",
content = "视频播放完成",
showCancel = false,
success = (res) => {
}
});
// 增加当前视频索引
currentVideoIndex++;
// 检查是否还有下一个视频
if (currentVideoIndex < videoUrls.Length)
{
videoPlayer.url = videoUrls[currentVideoIndex]; // 设置下一个视频的 URL
}
else
{
currentVideoIndex = 0; // 如果没有下一个视频,重置索引(可选)
}
videoPlayer.url = videoUrls[currentVideoIndex];
videoPlayer.Play(); // 播放下一个视频
}
}