Skip to content

Commit 4698e53

Browse files
authored
Merge pull request #927 from VincentWSZ/Video
补充一下videoPlayer.loopPointReached
2 parents ef91f17 + 1e84b0a commit 4698e53

File tree

12 files changed

+1191
-44
lines changed

12 files changed

+1191
-44
lines changed

Diff for: Demo/API_V2/Assets/API/APISO.asset

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ MonoBehaviour:
1919
- {fileID: 11400000, guid: 9977a581037b84833a32b508e00eb1a2, type: 2}
2020
- {fileID: 11400000, guid: 56f316e0e10ba419bbf19bd7a68bfc4c, type: 2}
2121
- {fileID: 11400000, guid: 6f0972f5fdc56c543b23c9873d760bf5, type: 2}
22-
- {fileID: 11400000, guid: a461b8cd70d9e4e23ad1cc953bec31e9, type: 2}
2322
- {fileID: 11400000, guid: 7ef06699cee7846b7823e4cc421418eb, type: 2}
23+
- {fileID: 11400000, guid: a461b8cd70d9e4e23ad1cc953bec31e9, type: 2}
2424
- {fileID: 11400000, guid: 55de20d536f8c4689bbd80553d87fe46, type: 2}
2525
- {fileID: 11400000, guid: f2c56d751bb7c4c398db7c1db352517d, type: 2}
2626
- {fileID: 11400000, guid: b4a6196f623dd4435a4f3bd70af92d06, type: 2}

Diff for: Demo/API_V2/Assets/API/Facility/FacilitySO.asset

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ MonoBehaviour:
1515
categoryName: "\u8BBE\u5907"
1616
categorySprite: {fileID: 21300000, guid: 53dd2b1922e5142ec8a53037f362fc56, type: 3}
1717
entryList:
18-
- {fileID: 11400000, guid: bbbc9b983d6d34ad3bac2921509f612f, type: 2}
19-
- {fileID: 11400000, guid: c17ae0ce755f04419b700825b20fd386, type: 2}
2018
- {fileID: 11400000, guid: a24af43ae51914d26b0bf637c283dab2, type: 2}
2119
- {fileID: 11400000, guid: 4eba2c9f2f2064e4081be74302ca4c33, type: 2}
20+
- {fileID: 11400000, guid: bbbc9b983d6d34ad3bac2921509f612f, type: 2}
21+
- {fileID: 11400000, guid: c17ae0ce755f04419b700825b20fd386, type: 2}
2222
- {fileID: 11400000, guid: ac09abff5d8bc48bbabd08bde820b58b, type: 2}
2323
- {fileID: 11400000, guid: 3bf339b994c544db3860ddf0a0dc8e20, type: 2}
2424
- {fileID: 11400000, guid: e92d94924be504167a342e42e1162f21, type: 2}

Diff for: Demo/API_V2/Assets/API/Facility/Screen/ScreenSO.asset

+1
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ MonoBehaviour:
2626
- buttonText: "\u67E5\u8BE2\u7528\u6237\u662F\u5426\u5728\u5F55\u5C4F"
2727
- buttonText: "\u83B7\u53D6\u5C4F\u5E55\u4EAE\u5EA6"
2828
initialResultList: []
29+
entryOrder: 0

Diff for: Demo/API_V2/Assets/API/FileSystem/FileSystemSO.asset

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ MonoBehaviour:
2424
- {fileID: 11400000, guid: 65ab1b01a722b4542a14fcf9decca3de, type: 2}
2525
- {fileID: 11400000, guid: 19b80cb144f0c4ea28a4ddca7a2c2f09, type: 2}
2626
- {fileID: 11400000, guid: 0aa5d76237c844275add1612c47bddaa, type: 2}
27-
- {fileID: 11400000, guid: 73c05fc1ffae94ec1b69a00ee261d529, type: 2}
2827
- {fileID: 11400000, guid: 65a826f5f949544d8990e673231bb80f, type: 2}
28+
- {fileID: 11400000, guid: 73c05fc1ffae94ec1b69a00ee261d529, type: 2}
2929
- {fileID: 11400000, guid: 3a901e80b59ad4aafbe373ee6a8df2d8, type: 2}
3030
- {fileID: 11400000, guid: e7ea0be62dc6543b0a8dc629489c5e7e, type: 2}
3131
categoryOrder: 11

Diff for: Demo/API_V2/Assets/API/Report/ReportEvent/ReportEventSO.asset

+1
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ MonoBehaviour:
2828
initialButtonText: "\u4E8B\u4EF6\u4E0A\u62A5"
2929
extraButtonList: []
3030
initialResultList: []
31+
entryOrder: 0

Diff for: Demo/API_V2/Assets/API/Share/ShareEvent/ShareEventSO.asset

+1
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ MonoBehaviour:
2828
- buttonText: "\u76D1\u542Csharetofriend"
2929
- buttonText: "\u76D1\u542C\u53F3\u4E0A\u89D2\u83DC\u5355\u7684\u8F6C\u53D1"
3030
initialResultList: []
31+
entryOrder: 0

Diff for: Demo/API_V2/Assets/API/Share/ShareEvent2/ShareEvent2SO.asset

+1
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ MonoBehaviour:
2424
- buttonText: "\u83B7\u53D6\u8F6C\u53D1\u8BE6\u7EC6\u4FE1\u606F"
2525
- buttonText: "\u9A8C\u8BC1\u79C1\u5BC6\u6D88\u606F"
2626
initialResultList: []
27+
entryOrder: 0

Diff for: Demo/API_V2/Assets/API/Video/VideoController.cs

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

Diff for: Demo/API_V2/Assets/API/Video/VideoController.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using UnityEngine;
2+
using UnityEngine.UI;
3+
using UnityEngine.Video;
4+
5+
public class VideoPlayerSliderController : MonoBehaviour
6+
{
7+
public VideoPlayer m_player;
8+
public Slider m_slider;
9+
public bool m_bMouseUp = true;
10+
void Start()
11+
{
12+
m_slider.onValueChanged.AddListener((float value) =>
13+
{
14+
if (!m_bMouseUp)
15+
{
16+
SliderEvent(value);
17+
}
18+
});
19+
}
20+
21+
private void FixedUpdate()
22+
{
23+
if (m_bMouseUp)
24+
{
25+
m_slider.value = m_player.frame / (m_player.frameCount * 1.0f);
26+
}
27+
}
28+
29+
public void PointerDown()
30+
{
31+
m_player.Pause();
32+
m_bMouseUp = false;
33+
}
34+
35+
public void PointerUp()
36+
{
37+
m_player.Play();
38+
m_bMouseUp = true;
39+
}
40+
41+
public void SliderEvent(float value)
42+
{
43+
m_player.frame = long.Parse((value * m_player.frameCount).ToString("0."));
44+
}
45+
46+
public void PointerClick()
47+
{
48+
// 暂停视频
49+
m_player.Pause();
50+
51+
// 获取点击位置相对于滑动条的比例
52+
RectTransform rt = m_slider.GetComponent<RectTransform>();
53+
Vector2 localPoint;
54+
RectTransformUtility.ScreenPointToLocalPointInRectangle(rt, Input.mousePosition, null, out localPoint);
55+
56+
// 计算点击位置对应的值
57+
float percentage = (localPoint.x - rt.rect.xMin) / rt.rect.width;
58+
percentage = Mathf.Clamp01(percentage);
59+
60+
// 设置视频帧
61+
m_player.frame = long.Parse((percentage * m_player.frameCount).ToString("0."));
62+
// 更新滑动条值
63+
m_slider.value = percentage;
64+
65+
// 继续播放视频
66+
m_player.Play();
67+
}
68+
}

Diff for: Demo/API_V2/Assets/API/Video/VideoPlayerSliderController.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)