Skip to content

Instantly share code, notes, and snippets.

@rcurtis
Created July 9, 2014 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rcurtis/c78d5f33b9fe9f0ef66e to your computer and use it in GitHub Desktop.
Save rcurtis/c78d5f33b9fe9f0ef66e to your computer and use it in GitHub Desktop.
using System;
using MotionNET;
using SFML.Graphics;
using SFML.Window;
namespace MotionTest
{
class Program
{
private RenderWindow window;
private DataSource dataSource;
private VideoPlayback videoPlayback;
private AudioPlayback audioPlayback;
private bool playing;
public Program()
{
window = new RenderWindow(new VideoMode(1280, 800), "Motion test");
window.SetVerticalSyncEnabled(true);
dataSource = new DataSource();
if (!dataSource.LoadFromFile("jetBot.mov"))
{
Console.WriteLine("Could not load video");
}
videoPlayback = new VideoPlayback(dataSource, Color.Transparent);
audioPlayback = new AudioPlayback(dataSource);
dataSource.EndofFileReached += HandleEndOfFile;
window.Closed += (sender, e) => window.Close();
window.MouseButtonPressed += (sender, args) =>
{
playing = true;
dataSource.Play();
};
while (window.IsOpen)
{
window.DispatchEvents();
window.Clear();
if (playing)
{
dataSource.Update();
window.Draw(videoPlayback);
}
window.Display();
}
}
private void HandleEndOfFile(DataSource obj)
{
playing = false;
audioPlayback.Dispose();
videoPlayback.Dispose();
dataSource.EndofFileReached -= HandleEndOfFile;
dataSource.Dispose();
}
static void Main(string[] args)
{
Program program = new Program();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment