Video pausing support; sync video to audio nicer.
This commit is contained in:
@@ -78,13 +78,25 @@ namespace OpenRA
|
||||
Play(name, pos);
|
||||
}
|
||||
|
||||
public static void PlayVideoSoundtrack(byte[] raw)
|
||||
public static void PlayVideo(byte[] raw)
|
||||
{
|
||||
rawSource = LoadSoundRaw(raw);
|
||||
video = soundEngine.Play2D(rawSource, false, true, float2.Zero, SoundVolume);
|
||||
}
|
||||
|
||||
public static void StopVideoSoundtrack()
|
||||
public static void PlayVideo()
|
||||
{
|
||||
if (video != null)
|
||||
soundEngine.PauseSound(video, false);
|
||||
}
|
||||
|
||||
public static void PauseVideo()
|
||||
{
|
||||
if (video != null)
|
||||
soundEngine.PauseSound(video, true);
|
||||
}
|
||||
|
||||
public static void StopVideo()
|
||||
{
|
||||
if (video != null)
|
||||
soundEngine.StopSound(video);
|
||||
@@ -153,6 +165,11 @@ namespace OpenRA
|
||||
get { return (music != null)? music.SeekPosition : 0; }
|
||||
}
|
||||
|
||||
public static float VideoSeekPosition
|
||||
{
|
||||
get { return (video != null)? video.SeekPosition : 0; }
|
||||
}
|
||||
|
||||
// Returns true if it played a phrase
|
||||
public static bool PlayVoice(string phrase, Actor voicedUnit)
|
||||
{
|
||||
@@ -412,8 +429,8 @@ namespace OpenRA
|
||||
get
|
||||
{
|
||||
float pos;
|
||||
Al.alGetSourcef(source, Al.AL_SEC_OFFSET, out pos);
|
||||
return pos;
|
||||
Al.alGetSourcef(source, Al.AL_SAMPLE_OFFSET, out pos);
|
||||
return pos/22050f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,12 +21,21 @@ namespace OpenRA.Widgets.Delegates
|
||||
{
|
||||
var bg = Widget.RootWidget.GetWidget("VIDEOPLAYER_MENU");
|
||||
var player = bg.GetWidget<VqaPlayerWidget>("VIDEOPLAYER");
|
||||
bg.GetWidget("BUTTON_PLAY").OnMouseUp = mi =>
|
||||
|
||||
var pp = bg.GetWidget("BUTTON_PLAYPAUSE");
|
||||
pp.OnMouseUp = mi =>
|
||||
{
|
||||
player.Play();
|
||||
if (player.Paused)
|
||||
player.Play();
|
||||
else
|
||||
player.Pause();
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
pp.GetWidget("PLAY").IsVisible = () => player.Paused;
|
||||
pp.GetWidget("PAUSE").IsVisible = () => !player.Paused;
|
||||
|
||||
bg.GetWidget("BUTTON_STOP").OnMouseUp = mi =>
|
||||
{
|
||||
player.Stop();
|
||||
|
||||
@@ -24,21 +24,24 @@ namespace OpenRA.Widgets
|
||||
float invLength;
|
||||
float2 videoOrigin, videoSize;
|
||||
int[,] overlay;
|
||||
public bool DrawOverlay = true;
|
||||
bool stopped;
|
||||
bool paused;
|
||||
|
||||
public bool Paused { get { return paused; } }
|
||||
|
||||
public bool DrawOverlay = true;
|
||||
public void Load(string filename)
|
||||
{
|
||||
if (filename == cachedVideo)
|
||||
return;
|
||||
|
||||
if (playing)
|
||||
{
|
||||
playing = false;
|
||||
Sound.StopVideoSoundtrack();
|
||||
}
|
||||
|
||||
stopped = true;
|
||||
paused = true;
|
||||
Sound.StopVideo();
|
||||
|
||||
cachedVideo = filename;
|
||||
video = new VqaReader(FileSystem.Open(filename));
|
||||
|
||||
invLength = video.Framerate*1f/video.Frames;
|
||||
|
||||
var size = Math.Max(video.Width, video.Height);
|
||||
@@ -63,16 +66,14 @@ namespace OpenRA.Widgets
|
||||
overlaySprite.sheet.Texture.SetData(overlay);
|
||||
}
|
||||
|
||||
bool playing = false;
|
||||
Stopwatch sw = new Stopwatch();
|
||||
public override void DrawInner(World world)
|
||||
{
|
||||
if (video == null)
|
||||
return;
|
||||
|
||||
if (playing)
|
||||
if (!(stopped || paused))
|
||||
{
|
||||
var nextFrame = (int)float2.Lerp(0, video.Frames, (float)(sw.ElapsedTime()*invLength));
|
||||
var nextFrame = (int)float2.Lerp(0, video.Frames, Sound.VideoSeekPosition*invLength);
|
||||
if (nextFrame > video.Frames)
|
||||
{
|
||||
Stop();
|
||||
@@ -86,6 +87,7 @@ namespace OpenRA.Widgets
|
||||
videoSprite.sheet.Texture.SetData(video.FrameData);
|
||||
}
|
||||
}
|
||||
|
||||
Game.Renderer.RgbaSpriteRenderer.DrawSprite(videoSprite, videoOrigin, "chrome", videoSize);
|
||||
|
||||
if (DrawOverlay)
|
||||
@@ -94,21 +96,34 @@ namespace OpenRA.Widgets
|
||||
|
||||
public void Play()
|
||||
{
|
||||
if (playing || video == null)
|
||||
if (video == null)
|
||||
return;
|
||||
|
||||
playing = true;
|
||||
sw.Reset();
|
||||
Sound.PlayVideoSoundtrack(video.AudioData);
|
||||
if (stopped)
|
||||
Sound.PlayVideo(video.AudioData);
|
||||
else
|
||||
Sound.PlayVideo();
|
||||
|
||||
stopped = paused = false;
|
||||
}
|
||||
|
||||
public void Pause()
|
||||
{
|
||||
if (stopped || paused || video == null)
|
||||
return;
|
||||
|
||||
paused = true;
|
||||
Sound.PauseVideo();
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
if (!playing || video == null)
|
||||
if (stopped || video == null)
|
||||
return;
|
||||
|
||||
playing = false;
|
||||
Sound.StopVideoSoundtrack();
|
||||
stopped = true;
|
||||
paused = true;
|
||||
Sound.StopVideo();
|
||||
video.Reset();
|
||||
videoSprite.sheet.Texture.SetData(video.FrameData);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user