Skip to content

补充一下videoPlayer.loopPointReached #927

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

Merged
merged 8 commits into from
Jan 10, 2025
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
2 changes: 1 addition & 1 deletion Demo/API_V2/Assets/API/APISO.asset
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ MonoBehaviour:
- {fileID: 11400000, guid: 9977a581037b84833a32b508e00eb1a2, type: 2}
- {fileID: 11400000, guid: 56f316e0e10ba419bbf19bd7a68bfc4c, type: 2}
- {fileID: 11400000, guid: 6f0972f5fdc56c543b23c9873d760bf5, type: 2}
- {fileID: 11400000, guid: a461b8cd70d9e4e23ad1cc953bec31e9, type: 2}
- {fileID: 11400000, guid: 7ef06699cee7846b7823e4cc421418eb, type: 2}
- {fileID: 11400000, guid: a461b8cd70d9e4e23ad1cc953bec31e9, type: 2}
- {fileID: 11400000, guid: 55de20d536f8c4689bbd80553d87fe46, type: 2}
- {fileID: 11400000, guid: f2c56d751bb7c4c398db7c1db352517d, type: 2}
- {fileID: 11400000, guid: b4a6196f623dd4435a4f3bd70af92d06, type: 2}
Expand Down
4 changes: 2 additions & 2 deletions Demo/API_V2/Assets/API/Facility/FacilitySO.asset
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ MonoBehaviour:
categoryName: "\u8BBE\u5907"
categorySprite: {fileID: 21300000, guid: 53dd2b1922e5142ec8a53037f362fc56, type: 3}
entryList:
- {fileID: 11400000, guid: bbbc9b983d6d34ad3bac2921509f612f, type: 2}
- {fileID: 11400000, guid: c17ae0ce755f04419b700825b20fd386, type: 2}
- {fileID: 11400000, guid: a24af43ae51914d26b0bf637c283dab2, type: 2}
- {fileID: 11400000, guid: 4eba2c9f2f2064e4081be74302ca4c33, type: 2}
- {fileID: 11400000, guid: bbbc9b983d6d34ad3bac2921509f612f, type: 2}
- {fileID: 11400000, guid: c17ae0ce755f04419b700825b20fd386, type: 2}
- {fileID: 11400000, guid: ac09abff5d8bc48bbabd08bde820b58b, type: 2}
- {fileID: 11400000, guid: 3bf339b994c544db3860ddf0a0dc8e20, type: 2}
- {fileID: 11400000, guid: e92d94924be504167a342e42e1162f21, type: 2}
Expand Down
1 change: 1 addition & 0 deletions Demo/API_V2/Assets/API/Facility/Screen/ScreenSO.asset
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ MonoBehaviour:
- buttonText: "\u67E5\u8BE2\u7528\u6237\u662F\u5426\u5728\u5F55\u5C4F"
- buttonText: "\u83B7\u53D6\u5C4F\u5E55\u4EAE\u5EA6"
initialResultList: []
entryOrder: 0
2 changes: 1 addition & 1 deletion Demo/API_V2/Assets/API/FileSystem/FileSystemSO.asset
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ MonoBehaviour:
- {fileID: 11400000, guid: 65ab1b01a722b4542a14fcf9decca3de, type: 2}
- {fileID: 11400000, guid: 19b80cb144f0c4ea28a4ddca7a2c2f09, type: 2}
- {fileID: 11400000, guid: 0aa5d76237c844275add1612c47bddaa, type: 2}
- {fileID: 11400000, guid: 73c05fc1ffae94ec1b69a00ee261d529, type: 2}
- {fileID: 11400000, guid: 65a826f5f949544d8990e673231bb80f, type: 2}
- {fileID: 11400000, guid: 73c05fc1ffae94ec1b69a00ee261d529, type: 2}
- {fileID: 11400000, guid: 3a901e80b59ad4aafbe373ee6a8df2d8, type: 2}
- {fileID: 11400000, guid: e7ea0be62dc6543b0a8dc629489c5e7e, type: 2}
categoryOrder: 11
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ MonoBehaviour:
initialButtonText: "\u4E8B\u4EF6\u4E0A\u62A5"
extraButtonList: []
initialResultList: []
entryOrder: 0
1 change: 1 addition & 0 deletions Demo/API_V2/Assets/API/Share/ShareEvent/ShareEventSO.asset
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ MonoBehaviour:
- buttonText: "\u76D1\u542Csharetofriend"
- buttonText: "\u76D1\u542C\u53F3\u4E0A\u89D2\u83DC\u5355\u7684\u8F6C\u53D1"
initialResultList: []
entryOrder: 0
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ MonoBehaviour:
- buttonText: "\u83B7\u53D6\u8F6C\u53D1\u8BE6\u7EC6\u4FE1\u606F"
- buttonText: "\u9A8C\u8BC1\u79C1\u5BC6\u6D88\u606F"
initialResultList: []
entryOrder: 0
70 changes: 70 additions & 0 deletions Demo/API_V2/Assets/API/Video/VideoController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,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(); // 播放下一个视频
}
}
11 changes: 11 additions & 0 deletions Demo/API_V2/Assets/API/Video/VideoController.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 68 additions & 0 deletions Demo/API_V2/Assets/API/Video/VideoPlayerSliderController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Video;

public class VideoPlayerSliderController : MonoBehaviour
{
public VideoPlayer m_player;
public Slider m_slider;
public bool m_bMouseUp = true;
void Start()
{
m_slider.onValueChanged.AddListener((float value) =>
{
if (!m_bMouseUp)
{
SliderEvent(value);
}
});
}

private void FixedUpdate()
{
if (m_bMouseUp)
{
m_slider.value = m_player.frame / (m_player.frameCount * 1.0f);
}
}

public void PointerDown()
{
m_player.Pause();
m_bMouseUp = false;
}

public void PointerUp()
{
m_player.Play();
m_bMouseUp = true;
}

public void SliderEvent(float value)
{
m_player.frame = long.Parse((value * m_player.frameCount).ToString("0."));
}

public void PointerClick()
{
// 暂停视频
m_player.Pause();

// 获取点击位置相对于滑动条的比例
RectTransform rt = m_slider.GetComponent<RectTransform>();
Vector2 localPoint;
RectTransformUtility.ScreenPointToLocalPointInRectangle(rt, Input.mousePosition, null, out localPoint);

// 计算点击位置对应的值
float percentage = (localPoint.x - rt.rect.xMin) / rt.rect.width;
percentage = Mathf.Clamp01(percentage);

// 设置视频帧
m_player.frame = long.Parse((percentage * m_player.frameCount).ToString("0."));
// 更新滑动条值
m_slider.value = percentage;

// 继续播放视频
m_player.Play();
}
}
11 changes: 11 additions & 0 deletions Demo/API_V2/Assets/API/Video/VideoPlayerSliderController.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading