Begin making video player widget useful; steal (othewise useless) musicplayer controls for now

This commit is contained in:
Paul Chote
2010-08-12 00:31:30 +12:00
parent 93a48c0cf1
commit c600239c54
4 changed files with 53 additions and 123 deletions

View File

@@ -19,15 +19,20 @@ namespace OpenRA.Widgets.Delegates
bg.GetWidget("BUTTON_PLAY").OnMouseUp = mi => bg.GetWidget("BUTTON_PLAY").OnMouseUp = mi =>
{ {
var foo = Widget.RootWidget.GetWidget<VqaPlayerWidget>("VIDEOPLAYER");
foo.Load("ally10.vqa");
foo.Play();
/*
if (Sound.MusicStopped) if (Sound.MusicStopped)
Sound.PlayMusic(GetSong()); Sound.PlayMusic(GetSong());
Sound.MusicStopped = false; Sound.MusicStopped = false;
Sound.MusicPaused = false; Sound.MusicPaused = false;
bg.GetWidget("BUTTON_PLAY").Visible = false; bg.GetWidget("BUTTON_PLAY").Visible = false;
bg.GetWidget("BUTTON_PAUSE").Visible = true; bg.GetWidget("BUTTON_PAUSE").Visible = true;
*/
return true; return true;
}; };
/*
bg.GetWidget("BUTTON_PAUSE").OnMouseUp = mi => bg.GetWidget("BUTTON_PAUSE").OnMouseUp = mi =>
{ {
Sound.MusicPaused = true; Sound.MusicPaused = true;
@@ -35,15 +40,19 @@ namespace OpenRA.Widgets.Delegates
bg.GetWidget("BUTTON_PLAY").Visible = true; bg.GetWidget("BUTTON_PLAY").Visible = true;
return true; return true;
}; };
*/
bg.GetWidget("BUTTON_STOP").OnMouseUp = mi => bg.GetWidget("BUTTON_STOP").OnMouseUp = mi =>
{ {
var foo = Widget.RootWidget.GetWidget<VqaPlayerWidget>("VIDEOPLAYER");
foo.Stop();
/*
Sound.MusicStopped = true; Sound.MusicStopped = true;
bg.GetWidget("BUTTON_PAUSE").Visible = false; bg.GetWidget("BUTTON_PAUSE").Visible = false;
bg.GetWidget("BUTTON_PLAY").Visible = true; bg.GetWidget("BUTTON_PLAY").Visible = true;
*/
return true; return true;
}; };
/*
bg.GetWidget("BUTTON_NEXT").OnMouseUp = mi => bg.GetWidget("BUTTON_NEXT").OnMouseUp = mi =>
{ {
Sound.PlayMusic(GetNextSong()); Sound.PlayMusic(GetNextSong());
@@ -63,6 +72,7 @@ namespace OpenRA.Widgets.Delegates
bg.GetWidget("BUTTON_PAUSE").Visible = true; bg.GetWidget("BUTTON_PAUSE").Visible = true;
return true; return true;
}; };
*/
} }
string GetNextSong() string GetNextSong()

View File

@@ -17,16 +17,18 @@ using OpenRA.Support;
namespace OpenRA.Widgets namespace OpenRA.Widgets
{ {
public class VqaPlayerWidget : Widget public class VqaPlayerWidget : Widget
{ {
public string Video = "";
float timestep; float timestep;
Sprite videoSprite; Sprite videoSprite;
VqaReader video = null; VqaReader video = null;
string cachedVideo;
float invLength; float invLength;
public void LoadVideo(string filename) public void Load(string filename)
{ {
if (filename == cachedVideo)
return;
cachedVideo = filename;
video = new VqaReader(FileSystem.Open(filename)); video = new VqaReader(FileSystem.Open(filename));
timestep = 1f/video.Framerate; timestep = 1f/video.Framerate;
invLength = video.Framerate*1f/video.Frames; invLength = video.Framerate*1f/video.Frames;
@@ -34,25 +36,20 @@ namespace OpenRA.Widgets
var size = OpenRA.Graphics.Util.NextPowerOf2(Math.Max(video.Width, video.Height)); var size = OpenRA.Graphics.Util.NextPowerOf2(Math.Max(video.Width, video.Height));
videoSprite = new Sprite(new Sheet(new Size(size,size)), new Rectangle( 0, 0, video.Width, video.Height ), TextureChannel.Alpha); videoSprite = new Sprite(new Sheet(new Size(size,size)), new Rectangle( 0, 0, video.Width, video.Height ), TextureChannel.Alpha);
} }
bool first = true; bool playing = false;
bool advanceNext = false;
Stopwatch sw = new Stopwatch(); Stopwatch sw = new Stopwatch();
bool first;
public override void DrawInner(World world) public override void DrawInner(World world)
{ {
if (video == null) if (!playing)
LoadVideo(Video); return;
var nextFrame = (int)float2.Lerp(0, video.Frames, (float)(sw.ElapsedTime()*invLength)); var nextFrame = (int)float2.Lerp(0, video.Frames, (float)(sw.ElapsedTime()*invLength));
if (first || nextFrame > video.Frames) if (nextFrame > video.Frames)
{ {
video.Reset(); Stop();
sw.Reset(); return;
Sound.PlayRaw(video.AudioData);
nextFrame = 0;
videoSprite.sheet.Texture.SetData(video.FrameData);
first = false;
} }
while (nextFrame > video.CurrentFrame) while (nextFrame > video.CurrentFrame)
@@ -64,5 +61,20 @@ namespace OpenRA.Widgets
Game.Renderer.RgbaSpriteRenderer.DrawSprite(videoSprite, new int2(RenderBounds.X,RenderBounds.Y), "chrome"); Game.Renderer.RgbaSpriteRenderer.DrawSprite(videoSprite, new int2(RenderBounds.X,RenderBounds.Y), "chrome");
} }
public void Play()
{
playing = true;
video.Reset();
videoSprite.sheet.Texture.SetData(video.FrameData);
sw.Reset();
Sound.PlayRaw(video.AudioData);
}
public void Stop()
{
playing = false;
// TODO: Stop audio
}
} }
} }

View File

@@ -1,11 +1,11 @@
Container@ROOT: Container@ROOT:
Children: Children:
# VqaPlayer: VqaPlayer:
# X:WINDOW_RIGHT - 400 Id:VIDEOPLAYER
# Y:WINDOW_BOTTOM - 200 X:WINDOW_RIGHT - 400
# Width:200 Y:WINDOW_BOTTOM - 250
# Height:200 Width:200
# Video:obel.vqa Height:200
Background@MAINMENU_BG: Background@MAINMENU_BG:
Id:MAINMENU_BG Id:MAINMENU_BG
X:(WINDOW_RIGHT - WIDTH)/2 X:(WINDOW_RIGHT - WIDTH)/2
@@ -98,7 +98,6 @@ Container@ROOT:
Children: Children:
Button@BUTTON_PLAY: Button@BUTTON_PLAY:
Id:BUTTON_PLAY Id:BUTTON_PLAY
Visible:false
X:50 X:50
Y:15 Y:15
Width:25 Width:25
@@ -112,21 +111,6 @@ Container@ROOT:
Height:25 Height:25
ImageCollection:music ImageCollection:music
ImageName:play ImageName:play
Button@BUTTON_PAUSE:
Id:BUTTON_PAUSE
X:50
Y:15
Width:25
Height:25
Children:
Image@IMAGE_PAUSE:
Id:IMAGE_PAUSE
X:0
Y:0
Width:25
Height:25
ImageCollection:music
ImageName:pause
Button@BUTTON_STOP: Button@BUTTON_STOP:
Id:BUTTON_STOP Id:BUTTON_STOP
X:85 X:85
@@ -141,34 +125,4 @@ Container@ROOT:
Width:25 Width:25
Height:25 Height:25
ImageCollection:music ImageCollection:music
ImageName:stop ImageName:stop
Button@BUTTON_NEXT:
Id:BUTTON_NEXT
X:120
Y:15
Width:25
Height:25
Children:
Image@IMAGE_NEXT:
Id:IMAGE_NEXT
X:0
Y:0
Width:25
Height:25
ImageCollection:music
ImageName:next
Button@BUTTON_PREV:
Id:BUTTON_PREV
X:15
Y:15
Width:25
Height:25
Children:
Image@IMAGE_PREV:
Id:IMAGE_PREV
X:0
Y:0
Width:25
Height:25
ImageCollection:music
ImageName:prev

View File

@@ -1,9 +1,9 @@
VqaPlayer: VqaPlayer:
Id:VIDEOPLAYER
X:WINDOW_RIGHT - 400 X:WINDOW_RIGHT - 400
Y:WINDOW_BOTTOM - 200 Y:WINDOW_BOTTOM - 250
Width:200 Width:200
Height:200 Height:200
Video:ally10.vqa
Background@MAINMENU_BG: Background@MAINMENU_BG:
Id:MAINMENU_BG Id:MAINMENU_BG
X:(WINDOW_RIGHT - WIDTH)/2 X:(WINDOW_RIGHT - WIDTH)/2
@@ -96,7 +96,6 @@ Background@MUSIC_BG:
Children: Children:
Button@BUTTON_PLAY: Button@BUTTON_PLAY:
Id:BUTTON_PLAY Id:BUTTON_PLAY
Visible:false
X:50 X:50
Y:15 Y:15
Width:25 Width:25
@@ -110,21 +109,6 @@ Background@MUSIC_BG:
Height:25 Height:25
ImageCollection:music ImageCollection:music
ImageName:play ImageName:play
Button@BUTTON_PAUSE:
Id:BUTTON_PAUSE
X:50
Y:15
Width:25
Height:25
Children:
Image@IMAGE_PAUSE:
Id:IMAGE_PAUSE
X:0
Y:0
Width:25
Height:25
ImageCollection:music
ImageName:pause
Button@BUTTON_STOP: Button@BUTTON_STOP:
Id:BUTTON_STOP Id:BUTTON_STOP
X:85 X:85
@@ -139,34 +123,4 @@ Background@MUSIC_BG:
Width:25 Width:25
Height:25 Height:25
ImageCollection:music ImageCollection:music
ImageName:stop ImageName:stop
Button@BUTTON_NEXT:
Id:BUTTON_NEXT
X:120
Y:15
Width:25
Height:25
Children:
Image@IMAGE_NEXT:
Id:IMAGE_NEXT
X:0
Y:0
Width:25
Height:25
ImageCollection:music
ImageName:next
Button@BUTTON_PREV:
Id:BUTTON_PREV
X:15
Y:15
Width:25
Height:25
Children:
Image@IMAGE_PREV:
Id:IMAGE_PREV
X:0
Y:0
Width:25
Height:25
ImageCollection:music
ImageName:prev