PlayQueueDemo.cs
2.74 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
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class PlayQueueDemo : MonoBehaviour
{
public AVProWindowsMediaMovie _movieA;
public AVProWindowsMediaMovie _movieB;
public string _folder;
public List<string> _filenames;
private AVProWindowsMediaMovie[] _movies;
private int _moviePlayIndex;
private int _movieLoadIndex;
private int _index = -1;
private bool _loadSuccess = true;
private int _playItemIndex = -1;
public AVProWindowsMediaMovie PlayingMovie { get { return _movies[_moviePlayIndex]; } }
public AVProWindowsMediaMovie LoadingMovie { get { return _movies[_movieLoadIndex]; } }
public int PlayingItemIndex { get { return _playItemIndex; } }
public bool IsPaused { get { if (PlayingMovie.MovieInstance != null) return !PlayingMovie.MovieInstance.IsPlaying; return false; } }
void Start()
{
_movieA._loop = false;
_movieB._loop = false;
_movies = new AVProWindowsMediaMovie[2];
_movies[0] = _movieA;
_movies[1] = _movieB;
_moviePlayIndex = 0;
_movieLoadIndex = 1;
NextMovie();
}
void Update()
{
if (PlayingMovie.MovieInstance != null)
{
if ((int)PlayingMovie.MovieInstance.PositionFrames >= (PlayingMovie.MovieInstance.DurationFrames - 1))
{
NextMovie();
}
}
if (!_loadSuccess)
{
_loadSuccess = true;
NextMovie();
}
}
void OnGUI()
{
AVProWindowsMediaMovie activeMovie = PlayingMovie;
if (activeMovie.OutputTexture == null)
activeMovie = LoadingMovie; // Display the previous video until the current one has loaded the first frame
Texture texture = activeMovie.OutputTexture;
if (texture != null)
{
Rect rect = new Rect(0, 0, Screen.width, Screen.height);
if (activeMovie.MovieInstance.RequiresFlipY)
{
GUIUtility.ScaleAroundPivot(new Vector2(1f, -1f), new Vector2(0, rect.y + (rect.height / 2)));
}
GUI.DrawTexture(rect, texture, ScaleMode.ScaleToFit, false);
}
}
public void Next()
{
NextMovie();
}
public void Previous()
{
_index -= 2;
if (_index < 0)
_index += _filenames.Count;
NextMovie();
}
public void Pause()
{
if (PlayingMovie != null)
{
PlayingMovie.Pause();
}
}
public void Unpause()
{
if (PlayingMovie != null)
{
PlayingMovie.Play();
}
}
private void NextMovie()
{
Pause();
if (_filenames.Count > 0)
{
_index = (Mathf.Max(0, _index+1))%_filenames.Count;
}
else
_index = -1;
if (_index < 0)
return;
LoadingMovie._folder = _folder;
LoadingMovie._filename = _filenames[_index];
LoadingMovie._useStreamingAssetsPath = true;
LoadingMovie._playOnStart = true;
_loadSuccess = LoadingMovie.LoadMovie(true);
_playItemIndex = _index;
_moviePlayIndex = (_moviePlayIndex + 1)%2;
_movieLoadIndex = (_movieLoadIndex + 1)%2;
}
}