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

View File

@@ -17,16 +17,18 @@ using OpenRA.Support;
namespace OpenRA.Widgets
{
public class VqaPlayerWidget : Widget
{
public string Video = "";
{
float timestep;
Sprite videoSprite;
VqaReader video = null;
string cachedVideo;
float invLength;
public void LoadVideo(string filename)
public void Load(string filename)
{
if (filename == cachedVideo)
return;
cachedVideo = filename;
video = new VqaReader(FileSystem.Open(filename));
timestep = 1f/video.Framerate;
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));
videoSprite = new Sprite(new Sheet(new Size(size,size)), new Rectangle( 0, 0, video.Width, video.Height ), TextureChannel.Alpha);
}
bool first = true;
bool advanceNext = false;
bool playing = false;
Stopwatch sw = new Stopwatch();
bool first;
public override void DrawInner(World world)
{
if (video == null)
LoadVideo(Video);
if (!playing)
return;
var nextFrame = (int)float2.Lerp(0, video.Frames, (float)(sw.ElapsedTime()*invLength));
if (first || nextFrame > video.Frames)
if (nextFrame > video.Frames)
{
video.Reset();
sw.Reset();
Sound.PlayRaw(video.AudioData);
nextFrame = 0;
videoSprite.sheet.Texture.SetData(video.FrameData);
first = false;
Stop();
return;
}
while (nextFrame > video.CurrentFrame)
@@ -64,5 +61,20 @@ namespace OpenRA.Widgets
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:
Children:
# VqaPlayer:
# X:WINDOW_RIGHT - 400
# Y:WINDOW_BOTTOM - 200
# Width:200
# Height:200
# Video:obel.vqa
VqaPlayer:
Id:VIDEOPLAYER
X:WINDOW_RIGHT - 400
Y:WINDOW_BOTTOM - 250
Width:200
Height:200
Background@MAINMENU_BG:
Id:MAINMENU_BG
X:(WINDOW_RIGHT - WIDTH)/2
@@ -98,7 +98,6 @@ Container@ROOT:
Children:
Button@BUTTON_PLAY:
Id:BUTTON_PLAY
Visible:false
X:50
Y:15
Width:25
@@ -112,21 +111,6 @@ Container@ROOT:
Height:25
ImageCollection:music
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:
Id:BUTTON_STOP
X:85
@@ -141,34 +125,4 @@ Container@ROOT:
Width:25
Height:25
ImageCollection:music
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
ImageName:stop

View File

@@ -1,9 +1,9 @@
VqaPlayer:
Id:VIDEOPLAYER
X:WINDOW_RIGHT - 400
Y:WINDOW_BOTTOM - 200
Y:WINDOW_BOTTOM - 250
Width:200
Height:200
Video:ally10.vqa
Background@MAINMENU_BG:
Id:MAINMENU_BG
X:(WINDOW_RIGHT - WIDTH)/2
@@ -96,7 +96,6 @@ Background@MUSIC_BG:
Children:
Button@BUTTON_PLAY:
Id:BUTTON_PLAY
Visible:false
X:50
Y:15
Width:25
@@ -110,21 +109,6 @@ Background@MUSIC_BG:
Height:25
ImageCollection:music
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:
Id:BUTTON_STOP
X:85
@@ -139,34 +123,4 @@ Background@MUSIC_BG:
Width:25
Height:25
ImageCollection:music
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
ImageName:stop