Skip to content

Feat/apiv2 video #1033

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 2 commits into from
Jul 25, 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
1 change: 1 addition & 0 deletions Demo/API_V2/Assets/API/Media/MediaSO.asset
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ MonoBehaviour:
- {fileID: 11400000, guid: 1055cfc5cdda7407298fa2ff9997d0c6, type: 2}
- {fileID: 11400000, guid: 480646e3cd4d6a948a7538d483c1b043, type: 2}
- {fileID: 11400000, guid: ad04526c3748b4e2b8498f998dfea973, type: 2}
- {fileID: 11400000, guid: 74a62098b548c4c9e985d91d4f60bcb9, type: 2}
- {fileID: 11400000, guid: 38b7b2300105146ce94a785a915252de, type: 2}
- {fileID: 11400000, guid: 04a7c5dbfc2464252841043ba677dcab, type: 2}
categoryOrder: 9

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

133 changes: 133 additions & 0 deletions Demo/API_V2/Assets/API/Media/Video/Video.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
using System;
using LitJson;
using UnityEngine;
using WeChatWASM;

public class Video : Details
{
private WXVideo _video;

private readonly Action _onEnded = () =>
{
const string result = "【Video】OnEnded";
GameManager.Instance.detailsController.AddResult(
new ResultData() { initialContentText = result }
);
};
private readonly Action<WXVideoError> _onError = (res) =>
{
var result = "【Video】OnError: " + JsonMapper.ToJson(res);
GameManager.Instance.detailsController.AddResult(
new ResultData() { initialContentText = result }
);
};
private readonly Action _onPause = () =>
{
const string result = "【Video】OnPause";
GameManager.Instance.detailsController.AddResult(
new ResultData() { initialContentText = result }
);
};
private readonly Action _onPlay = () =>
{
const string result = "【Video】OnPlay";
GameManager.Instance.detailsController.AddResult(
new ResultData() { initialContentText = result }
);
};
private readonly Action<WXVideoProgress> _onProgress = (res) =>
{
var result = "【Video】OnProgress: " + JsonMapper.ToJson(res);
GameManager.Instance.detailsController.AddResult(
new ResultData() { initialContentText = result }
);
};
private readonly Action<WXVideoTimeUpdate> _onTimeUpdate = (res) =>
{
var result = "【Video】OnTimeUpdate: " + JsonMapper.ToJson(res);
GameManager.Instance.detailsController.AddResult(
new ResultData() { initialContentText = result }
);
};
private readonly Action _onWaiting = () =>
{
const string result = "【Video】OnWaiting";
GameManager.Instance.detailsController.AddResult(
new ResultData() { initialContentText = result }
);
};

private void Start()
{
GameManager.Instance.detailsController.BindExtraButtonAction(0, ChangeMuteState);
}

// 创建视频
protected override void TestAPI(string[] args)
{
if (_video != null)
{
_video.Destroy();
}
var createVideoOption = new CreateVideoOption()
{
x = GetOptionValue<double>(0),
y = GetOptionValue<double>(1),
width = GetOptionValue<double>(2),
height = GetOptionValue<double>(3),
src = args[4] == "示例视频" ? "http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400" : "",
poster = args[5] == "示例封面" ? "https://mmgame.qpic.cn/image/b4e70a6cba5ccad456667d85c3c0ea3c02e4f879a9705ed75071595a3e9f4ca0/0" : "",
initialTime = GetOptionValue<double>(6),
playbackRate = GetOptionValue<double>(7),
live = GetOptionValue<bool>(8),
objectFit = GetOptionString(9),
controls = GetOptionValue<bool>(10),
showProgress = GetOptionValue<bool>(11),
showProgressInControlMode = GetOptionValue<bool>(12),
backgroundColor = GetOptionString(13),
autoplay = GetOptionValue<bool>(14),
loop = GetOptionValue<bool>(15),
muted = GetOptionValue<bool>(16),
obeyMuteSwitch = GetOptionValue<bool>(17),
enableProgressGesture = GetOptionValue<bool>(18),
enablePlayGesture = GetOptionValue<bool>(19),
showCenterPlayBtn = GetOptionValue<bool>(20),
underGameView = GetOptionValue<bool>(21),
autoPauseIfNavigate = GetOptionValue<bool>(22),
autoPauseIfOpenNative = GetOptionValue<bool>(23),
};
_video = WX.CreateVideo(createVideoOption);
_video.OnEnded(_onEnded);
_video.OnError(_onError);
_video.OnPause(_onPause);
_video.OnPlay(_onPlay);
_video.OnProgress(_onProgress);
_video.OnTimeUpdate(_onTimeUpdate);
_video.OnWaiting(_onWaiting);
}

private void ChangeMuteState()
{
if (_video == null)
{
WX.ShowModal(new ShowModalOption() { content = "请先创建视频" });
return;
}

// 确保 muted 属性存在
_video.muted ??= false;

_video.muted = !_video.muted.Value;
GameManager.Instance.detailsController.ChangeExtraButtonText(0, _video.muted.Value ? "取消静音" : "静音");
var result = "【Video】Mute state changed: " + _video.muted.Value;
WX.ShowModal(new ShowModalOption() { content = result });
}

private void OnDestroy()
{
if (_video != null)
{
_video.Destroy();
}
}
}

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

146 changes: 146 additions & 0 deletions Demo/API_V2/Assets/API/Media/Video/VideoSO.asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 57c8415214254e23a63d9bfb8c6bbf62, type: 3}
m_Name: VideoSO
m_EditorClassIdentifier:
entryName: "\u89C6\u9891"
entryOrder: 0
entryScriptTypeName: Video
entryAPI: CreateVideo
entryDescription: "\u521B\u5EFA\u89C6\u9891"
optionList:
- optionName: x
availableOptions:
- null
- 0
- 100
- optionName: y
availableOptions:
- null
- 0
- 100
- optionName: width
availableOptions:
- null
- 0
- 100
- optionName: height
availableOptions:
- null
- 0
- 100
- optionName: src
availableOptions:
- "\u793A\u4F8B\u89C6\u9891"
- optionName: poster
availableOptions:
- null
- "\u793A\u4F8B\u5C01\u9762"
- optionName: initialTime
availableOptions:
- null
- 0
- 100
- optionName: playbackRate
availableOptions:
- null
- 0.5
- 0.8
- 1.0
- 1.25
- 1.5
- optionName: live
availableOptions:
- null
- false
- true
- optionName: objectFit
availableOptions:
- null
- fill
- contain
- cover
- optionName: controls
availableOptions:
- null
- false
- true
- optionName: showProgress
availableOptions:
- null
- false
- true
- optionName: showProgressInControlMode
availableOptions:
- null
- false
- true
- optionName: backgroundColor
availableOptions:
- null
- '#000000'
- '#FFFFFFF'
- '#07C160'
- optionName: autoplay
availableOptions:
- null
- false
- true
- optionName: loop
availableOptions:
- null
- false
- true
- optionName: muted
availableOptions:
- null
- false
- true
- optionName: obeyMuteSwitch
availableOptions:
- null
- false
- true
- optionName: enableProgressGesture
availableOptions:
- null
- false
- true
- optionName: enablePlayGesture
availableOptions:
- null
- false
- true
- optionName: showCenterPlayBtn
availableOptions:
- null
- false
- true
- optionName: underGameView
availableOptions:
- null
- false
- true
- optionName: autoPauseIfNavigate
availableOptions:
- null
- false
- true
- optionName: autoPauseIfOpenNative
availableOptions:
- null
- false
- true
initialButtonText: "\u521B\u5EFA\u89C6\u9891"
extraButtonList:
- buttonText: "\u9759\u97F3"
initialResultList: []

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

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private void Start()
// 如果 GameManager 的字体已经加载,直接设置 Text 的字体
if (GameManager.Instance.font != null)
{
_text.font = GameManager.Instance.fonts;
_text.font = GameManager.Instance.TMP_font;
}
else
{
Expand Down
1 change: 0 additions & 1 deletion Demo/API_V2/Assets/API/NativeVideo/NativeVideoSO.asset
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ MonoBehaviour:
entryList:
- {fileID: 11400000, guid: 5073e277b29d95642abb3c49fe94eea0, type: 2}
- {fileID: 11400000, guid: 27654a238f98e4f7e8756e4caed418e1, type: 2}
- {fileID: 11400000, guid: ebd496025e81f434bb6b5b487cfbf2ed, type: 2}
categoryOrder: 0
57 changes: 0 additions & 57 deletions Demo/API_V2/Assets/API/NativeVideo/WXVideo/WXVideo.cs

This file was deleted.

16 changes: 0 additions & 16 deletions Demo/API_V2/Assets/API/NativeVideo/WXVideo/WXVideoSO.asset

This file was deleted.

Loading
Loading