AVProWindowsMediaMaterialMappingDemo.cs
4.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
using UnityEngine;
using System.Collections;
public class AVProWindowsMediaMaterialMappingDemo : MonoBehaviour
{
public GUISkin _skin;
public AVProWindowsMediaMovie _movie;
private bool _visible = true;
private float _alpha = 1.0f;
public void OnGUI()
{
GUI.skin = _skin;
if (_visible)
{
GUI.color = new Color(1f, 1f, 1f, _alpha);
GUILayout.BeginArea(new Rect(0, 0, 740, 300), GUI.skin.box);
ControlWindow(0);
GUILayout.EndArea();
}
GUI.color = new Color(1f, 1f, 1f, 1f - _alpha);
GUI.Box(new Rect(0, 0, 128, 32), "Demo Controls");
}
void Update()
{
Rect r = new Rect(0, 0, 740, 310);
if (r.Contains(new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y)))
{
_visible = true;
_alpha = 1.0f;
}
else
{
_alpha -= Time.deltaTime * 4f;
if (_alpha <= 0.0f)
{
_alpha = 0.0f;
_visible = false;
}
}
}
public void ControlWindow(int id)
{
if (_movie == null)
return;
GUILayout.Space(16f);
GUILayout.BeginVertical();
GUILayout.BeginHorizontal();
GUILayout.Label("Folder: ", GUILayout.Width(80));
_movie._folder = GUILayout.TextField(_movie._folder, 192);
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Label("File: ", GUILayout.Width(80));
_movie._filename = GUILayout.TextField(_movie._filename, 128, GUILayout.Width(440));
if (GUILayout.Button("Load File", GUILayout.Width(90)))
{
_movie.LoadMovie(true);
}
GUILayout.EndHorizontal();
bool alphaBlend = _movie._colourFormat == AVProWindowsMediaMovie.ColourFormat.RGBA32;
if (alphaBlend)
alphaBlend = GUILayout.Toggle(alphaBlend, "Render with Transparency (requires movie reload)");
else
alphaBlend = GUILayout.Toggle(alphaBlend, "Render without Transparency");
if (alphaBlend)
{
_movie._colourFormat = AVProWindowsMediaMovie.ColourFormat.RGBA32;
}
else
{
_movie._colourFormat = AVProWindowsMediaMovie.ColourFormat.YCbCr_HD;
}
AVProWindowsMedia moviePlayer = _movie.MovieInstance;
if (moviePlayer != null)
{
GUILayout.BeginHorizontal();
GUILayout.Label("Info:", GUILayout.Width(80f));
GUILayout.Label(moviePlayer.Width + "x" + moviePlayer.Height + " @ " + moviePlayer.FrameRate.ToString("F2") + " FPS");
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Label("Volume ", GUILayout.Width(80));
float volume = _movie._volume;
float newVolume = GUILayout.HorizontalSlider(volume, 0.0f, 1.0f, GUILayout.Width(200));
if (volume != newVolume)
{
_movie._volume = newVolume;
}
GUILayout.Label(_movie._volume.ToString("F1"));
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Label("Balance ", GUILayout.Width(80));
float balance = moviePlayer.AudioBalance;
float newBalance = GUILayout.HorizontalSlider(balance, -1.0f, 1.0f, GUILayout.Width(200));
if (balance != newBalance)
{
moviePlayer.AudioBalance = newBalance;
}
GUILayout.Label(moviePlayer.AudioBalance.ToString("F1"));
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Label("Time ", GUILayout.Width(80));
float position = moviePlayer.PositionSeconds;
float newPosition = GUILayout.HorizontalSlider(position, 0.0f, moviePlayer.DurationSeconds, GUILayout.Width(200));
if (position != newPosition)
{
moviePlayer.PositionSeconds = newPosition;
}
GUILayout.Label(moviePlayer.PositionSeconds.ToString("F1") + " / " + moviePlayer.DurationSeconds.ToString("F1") + "s");
if (GUILayout.Button("Play"))
{
moviePlayer.Play();
}
if (GUILayout.Button("Pause"))
{
moviePlayer.Pause();
}
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Label("Frame", GUILayout.Width(80f));
GUILayout.Label(moviePlayer.PositionFrames.ToString() + " / " + moviePlayer.DurationFrames.ToString());
if (GUILayout.Button("<", GUILayout.Width(50)))
{
moviePlayer.Pause();
if (moviePlayer.PositionFrames > 0)
{
moviePlayer.PositionFrames--;
}
}
if (GUILayout.Button(">", GUILayout.Width(50)))
{
moviePlayer.Pause();
if (moviePlayer.PositionFrames < moviePlayer.DurationFrames)
{
moviePlayer.PositionFrames++;
}
}
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Label("Rate ", GUILayout.Width(80f));
GUILayout.Label(moviePlayer.PlaybackRate.ToString("F2") + "x");
if (GUILayout.Button("-", GUILayout.Width(50)))
{
moviePlayer.PlaybackRate = moviePlayer.PlaybackRate * 0.5f;
}
if (GUILayout.Button("+", GUILayout.Width(50)))
{
moviePlayer.PlaybackRate = moviePlayer.PlaybackRate * 2.0f;
}
GUILayout.EndHorizontal();
}
GUILayout.EndVertical();
}
}