Skip to content

Commit 6de7682

Browse files
committed
videodecoder-demo
1 parent 5c93f2d commit 6de7682

File tree

7 files changed

+557
-0
lines changed

7 files changed

+557
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ MonoBehaviour:
1717
entryList:
1818
- {fileID: 11400000, guid: 1d998af43281d4eee9e1effc8f83bddd, type: 2}
1919
- {fileID: 11400000, guid: ad04526c3748b4e2b8498f998dfea973, type: 2}
20+
- {fileID: 11400000, guid: 38b7b2300105146ce94a785a915252de, type: 2}

Demo/API_V2/Assets/API/Media/VideoDecoder.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using LitJson;
4+
using UnityEngine;
5+
using WeChatWASM;
6+
using UnityEngine.UI;
7+
8+
9+
public class VideoDecoder : Details
10+
{
11+
private WXVideoDecoder _videoDecoder;
12+
13+
private readonly Action<string> _onStart = (res) => {
14+
Debug.Log("videodecoder onStart " + JsonUtility.ToJson(res));
15+
};
16+
17+
private readonly Action<string> _onStop = (res) => {
18+
Debug.Log("videodecoder onStop " + JsonUtility.ToJson(res));
19+
};
20+
21+
private readonly Action<string> _onSeek = (res) => {
22+
Debug.Log("videodecoder onSeek " + JsonUtility.ToJson(res));
23+
};
24+
25+
private readonly Action<string> _onBufferchange = (res) => {
26+
Debug.Log("videodecoder onBufferchange " + JsonUtility.ToJson(res));
27+
};
28+
29+
private readonly Action<string> _onEnded = (res) => {
30+
// ended = true;
31+
Debug.Log("videodecoder onEnded " + JsonUtility.ToJson(res));
32+
};
33+
34+
private void Start()
35+
{
36+
if (_videoDecoder == null)
37+
{
38+
_videoDecoder = WX.CreateVideoDecoder();
39+
}
40+
41+
_videoDecoder.On("start", _onStart);
42+
_videoDecoder.On("stop", _onStop);
43+
_videoDecoder.On("seek", _onSeek);
44+
_videoDecoder.On("bufferchange", _onBufferchange);
45+
_videoDecoder.On("ended", _onEnded);
46+
47+
48+
GameManager.Instance.detailsController.BindExtraButtonAction(0, stop);
49+
GameManager.Instance.detailsController.BindExtraButtonAction(1, seek);
50+
GameManager.Instance.detailsController.BindExtraButtonAction(2, getFrameData);
51+
}
52+
53+
// 开始
54+
protected override void TestAPI(string[] args)
55+
{
56+
_videoDecoder.Start(new VideoDecoderStartOption()
57+
{
58+
source = "https://res.wx.qq.com/wechatgame/product/webpack/userupload/20190812/video.mp4",
59+
mode = 1,
60+
abortAudio = false,
61+
abortVideo = false,
62+
});
63+
}
64+
65+
// 停止
66+
public void stop()
67+
{
68+
_videoDecoder.Stop();
69+
}
70+
71+
public void seek()
72+
{
73+
_videoDecoder.Seek(12000);
74+
}
75+
76+
public void getFrameData()
77+
{
78+
FrameDataOptions res = _videoDecoder.GetFrameData();
79+
Debug.Log(JsonMapper.ToJson(res.data));
80+
Debug.Log(res.pkPts);
81+
Debug.Log(res.pkDts);
82+
Debug.Log(res.width);
83+
Debug.Log(res.height);
84+
}
85+
86+
private void OnDestroy()
87+
{
88+
if (_videoDecoder != null)
89+
{
90+
_videoDecoder.Off("start");
91+
_videoDecoder.Off("stop");
92+
_videoDecoder.Off("seek");
93+
_videoDecoder.Off("bufferchange");
94+
_videoDecoder.Off("ended");
95+
_videoDecoder.Remove();
96+
}
97+
}
98+
}

Demo/API_V2/Assets/API/Media/VideoDecoder/VideoDecoder.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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: fb48e4613a53bb941a20036d7c08fefb, type: 3}
13+
m_Name: VideoDecoderSO
14+
m_EditorClassIdentifier:
15+
entryScriptTypeName: VideoDecoder
16+
entryName: "\u89C6\u9891\u89E3\u7801\u5668"
17+
entryAPI:
18+
entryDescription:
19+
optionList: []
20+
initialButtonText: "\u5F00\u59CB\u89E3\u7801"
21+
extraButtonList:
22+
- buttonText: "\u505C\u6B62\u89E3\u7801"
23+
- buttonText: "\u8DF3\u8F6C"
24+
- buttonText: "\u83B7\u5F97\u4E0B\u4E00\u5E27"
25+
initialResultList: []

Demo/API_V2/Assets/API/Media/VideoDecoder/VideoDecoderSO.asset.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)