Skip to content

Commit 665f2f1

Browse files
authored
Merge pull request #1033 from wechat-miniprogram/feat/APIV2_Video
Feat/apiv2 video
2 parents 87cc689 + a0eb8bd commit 665f2f1

File tree

19 files changed

+372
-2113
lines changed

19 files changed

+372
-2113
lines changed

Demo/API_V2/Assets/API/Media/MediaSO.asset

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ MonoBehaviour:
2020
- {fileID: 11400000, guid: 1055cfc5cdda7407298fa2ff9997d0c6, type: 2}
2121
- {fileID: 11400000, guid: 480646e3cd4d6a948a7538d483c1b043, type: 2}
2222
- {fileID: 11400000, guid: ad04526c3748b4e2b8498f998dfea973, type: 2}
23+
- {fileID: 11400000, guid: 74a62098b548c4c9e985d91d4f60bcb9, type: 2}
2324
- {fileID: 11400000, guid: 38b7b2300105146ce94a785a915252de, type: 2}
2425
- {fileID: 11400000, guid: 04a7c5dbfc2464252841043ba677dcab, type: 2}
2526
categoryOrder: 9

Demo/API_V2/Assets/API/NativeVideo/WXVideo.meta renamed to Demo/API_V2/Assets/API/Media/Video.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
using System;
2+
using LitJson;
3+
using UnityEngine;
4+
using WeChatWASM;
5+
6+
public class Video : Details
7+
{
8+
private WXVideo _video;
9+
10+
private readonly Action _onEnded = () =>
11+
{
12+
const string result = "【Video】OnEnded";
13+
GameManager.Instance.detailsController.AddResult(
14+
new ResultData() { initialContentText = result }
15+
);
16+
};
17+
private readonly Action<WXVideoError> _onError = (res) =>
18+
{
19+
var result = "【Video】OnError: " + JsonMapper.ToJson(res);
20+
GameManager.Instance.detailsController.AddResult(
21+
new ResultData() { initialContentText = result }
22+
);
23+
};
24+
private readonly Action _onPause = () =>
25+
{
26+
const string result = "【Video】OnPause";
27+
GameManager.Instance.detailsController.AddResult(
28+
new ResultData() { initialContentText = result }
29+
);
30+
};
31+
private readonly Action _onPlay = () =>
32+
{
33+
const string result = "【Video】OnPlay";
34+
GameManager.Instance.detailsController.AddResult(
35+
new ResultData() { initialContentText = result }
36+
);
37+
};
38+
private readonly Action<WXVideoProgress> _onProgress = (res) =>
39+
{
40+
var result = "【Video】OnProgress: " + JsonMapper.ToJson(res);
41+
GameManager.Instance.detailsController.AddResult(
42+
new ResultData() { initialContentText = result }
43+
);
44+
};
45+
private readonly Action<WXVideoTimeUpdate> _onTimeUpdate = (res) =>
46+
{
47+
var result = "【Video】OnTimeUpdate: " + JsonMapper.ToJson(res);
48+
GameManager.Instance.detailsController.AddResult(
49+
new ResultData() { initialContentText = result }
50+
);
51+
};
52+
private readonly Action _onWaiting = () =>
53+
{
54+
const string result = "【Video】OnWaiting";
55+
GameManager.Instance.detailsController.AddResult(
56+
new ResultData() { initialContentText = result }
57+
);
58+
};
59+
60+
private void Start()
61+
{
62+
GameManager.Instance.detailsController.BindExtraButtonAction(0, ChangeMuteState);
63+
}
64+
65+
// 创建视频
66+
protected override void TestAPI(string[] args)
67+
{
68+
if (_video != null)
69+
{
70+
_video.Destroy();
71+
}
72+
var createVideoOption = new CreateVideoOption()
73+
{
74+
x = GetOptionValue<double>(0),
75+
y = GetOptionValue<double>(1),
76+
width = GetOptionValue<double>(2),
77+
height = GetOptionValue<double>(3),
78+
src = args[4] == "示例视频" ? "http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400" : "",
79+
poster = args[5] == "示例封面" ? "https://mmgame.qpic.cn/image/b4e70a6cba5ccad456667d85c3c0ea3c02e4f879a9705ed75071595a3e9f4ca0/0" : "",
80+
initialTime = GetOptionValue<double>(6),
81+
playbackRate = GetOptionValue<double>(7),
82+
live = GetOptionValue<bool>(8),
83+
objectFit = GetOptionString(9),
84+
controls = GetOptionValue<bool>(10),
85+
showProgress = GetOptionValue<bool>(11),
86+
showProgressInControlMode = GetOptionValue<bool>(12),
87+
backgroundColor = GetOptionString(13),
88+
autoplay = GetOptionValue<bool>(14),
89+
loop = GetOptionValue<bool>(15),
90+
muted = GetOptionValue<bool>(16),
91+
obeyMuteSwitch = GetOptionValue<bool>(17),
92+
enableProgressGesture = GetOptionValue<bool>(18),
93+
enablePlayGesture = GetOptionValue<bool>(19),
94+
showCenterPlayBtn = GetOptionValue<bool>(20),
95+
underGameView = GetOptionValue<bool>(21),
96+
autoPauseIfNavigate = GetOptionValue<bool>(22),
97+
autoPauseIfOpenNative = GetOptionValue<bool>(23),
98+
};
99+
_video = WX.CreateVideo(createVideoOption);
100+
_video.OnEnded(_onEnded);
101+
_video.OnError(_onError);
102+
_video.OnPause(_onPause);
103+
_video.OnPlay(_onPlay);
104+
_video.OnProgress(_onProgress);
105+
_video.OnTimeUpdate(_onTimeUpdate);
106+
_video.OnWaiting(_onWaiting);
107+
}
108+
109+
private void ChangeMuteState()
110+
{
111+
if (_video == null)
112+
{
113+
WX.ShowModal(new ShowModalOption() { content = "请先创建视频" });
114+
return;
115+
}
116+
117+
// 确保 muted 属性存在
118+
_video.muted ??= false;
119+
120+
_video.muted = !_video.muted.Value;
121+
GameManager.Instance.detailsController.ChangeExtraButtonText(0, _video.muted.Value ? "取消静音" : "静音");
122+
var result = "【Video】Mute state changed: " + _video.muted.Value;
123+
WX.ShowModal(new ShowModalOption() { content = result });
124+
}
125+
126+
private void OnDestroy()
127+
{
128+
if (_video != null)
129+
{
130+
_video.Destroy();
131+
}
132+
}
133+
}

Demo/API_V2/Assets/API/NativeVideo/WXVideo/WXVideo.cs.meta renamed to Demo/API_V2/Assets/API/Media/Video/Video.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!114 &11400000
4+
MonoBehaviour:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
m_GameObject: {fileID: 0}
10+
m_Enabled: 1
11+
m_EditorHideFlags: 0
12+
m_Script: {fileID: 11500000, guid: 57c8415214254e23a63d9bfb8c6bbf62, type: 3}
13+
m_Name: VideoSO
14+
m_EditorClassIdentifier:
15+
entryName: "\u89C6\u9891"
16+
entryOrder: 0
17+
entryScriptTypeName: Video
18+
entryAPI: CreateVideo
19+
entryDescription: "\u521B\u5EFA\u89C6\u9891"
20+
optionList:
21+
- optionName: x
22+
availableOptions:
23+
- null
24+
- 0
25+
- 100
26+
- optionName: y
27+
availableOptions:
28+
- null
29+
- 0
30+
- 100
31+
- optionName: width
32+
availableOptions:
33+
- null
34+
- 0
35+
- 100
36+
- optionName: height
37+
availableOptions:
38+
- null
39+
- 0
40+
- 100
41+
- optionName: src
42+
availableOptions:
43+
- "\u793A\u4F8B\u89C6\u9891"
44+
- optionName: poster
45+
availableOptions:
46+
- null
47+
- "\u793A\u4F8B\u5C01\u9762"
48+
- optionName: initialTime
49+
availableOptions:
50+
- null
51+
- 0
52+
- 100
53+
- optionName: playbackRate
54+
availableOptions:
55+
- null
56+
- 0.5
57+
- 0.8
58+
- 1.0
59+
- 1.25
60+
- 1.5
61+
- optionName: live
62+
availableOptions:
63+
- null
64+
- false
65+
- true
66+
- optionName: objectFit
67+
availableOptions:
68+
- null
69+
- fill
70+
- contain
71+
- cover
72+
- optionName: controls
73+
availableOptions:
74+
- null
75+
- false
76+
- true
77+
- optionName: showProgress
78+
availableOptions:
79+
- null
80+
- false
81+
- true
82+
- optionName: showProgressInControlMode
83+
availableOptions:
84+
- null
85+
- false
86+
- true
87+
- optionName: backgroundColor
88+
availableOptions:
89+
- null
90+
- '#000000'
91+
- '#FFFFFFF'
92+
- '#07C160'
93+
- optionName: autoplay
94+
availableOptions:
95+
- null
96+
- false
97+
- true
98+
- optionName: loop
99+
availableOptions:
100+
- null
101+
- false
102+
- true
103+
- optionName: muted
104+
availableOptions:
105+
- null
106+
- false
107+
- true
108+
- optionName: obeyMuteSwitch
109+
availableOptions:
110+
- null
111+
- false
112+
- true
113+
- optionName: enableProgressGesture
114+
availableOptions:
115+
- null
116+
- false
117+
- true
118+
- optionName: enablePlayGesture
119+
availableOptions:
120+
- null
121+
- false
122+
- true
123+
- optionName: showCenterPlayBtn
124+
availableOptions:
125+
- null
126+
- false
127+
- true
128+
- optionName: underGameView
129+
availableOptions:
130+
- null
131+
- false
132+
- true
133+
- optionName: autoPauseIfNavigate
134+
availableOptions:
135+
- null
136+
- false
137+
- true
138+
- optionName: autoPauseIfOpenNative
139+
availableOptions:
140+
- null
141+
- false
142+
- true
143+
initialButtonText: "\u521B\u5EFA\u89C6\u9891"
144+
extraButtonList:
145+
- buttonText: "\u9759\u97F3"
146+
initialResultList: []

Demo/API_V2/Assets/API/NativeVideo/WXVideo/WXVideoSO.asset.meta renamed to Demo/API_V2/Assets/API/Media/Video/VideoSO.asset.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Demo/API_V2/Assets/API/NativeInputField/InputField/TmpTextInit.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ private void Start()
1919
// 如果 GameManager 的字体已经加载,直接设置 Text 的字体
2020
if (GameManager.Instance.font != null)
2121
{
22-
_text.font = GameManager.Instance.fonts;
22+
_text.font = GameManager.Instance.TMP_font;
2323
}
2424
else
2525
{

Demo/API_V2/Assets/API/NativeVideo/NativeVideoSO.asset

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,4 @@ MonoBehaviour:
1818
entryList:
1919
- {fileID: 11400000, guid: 5073e277b29d95642abb3c49fe94eea0, type: 2}
2020
- {fileID: 11400000, guid: 27654a238f98e4f7e8756e4caed418e1, type: 2}
21-
- {fileID: 11400000, guid: ebd496025e81f434bb6b5b487cfbf2ed, type: 2}
2221
categoryOrder: 0

Demo/API_V2/Assets/API/NativeVideo/WXVideo/WXVideo.cs

Lines changed: 0 additions & 57 deletions
This file was deleted.

Demo/API_V2/Assets/API/NativeVideo/WXVideo/WXVideoSO.asset

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)