123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using Iisu;
- using bbiwarg.Utility;
- namespace bbiwarg.Input.InputProviding
- {
- public delegate void MovieRestartedEventHandler(object sender, EventArgs e);
- class VideoInputProvider : InputProvider
- {
- private IParameterHandle<int> currentMovieFrame;
- private IParameterHandle<int> frameCount;
- private IParameterHandle<int> playStep;
- public override int CurrentFrameID { get { return currentMovieFrame.Value; } }
- public String MoviePath { get; private set; }
- public bool IsPaused { get; private set; }
- public event MovieRestartedEventHandler MovieRestartedEvent;
- public VideoInputProvider(String moviePath)
- {
- MoviePath = moviePath;
- }
- protected override IDeviceConfiguration createDeviceConfiguration()
- {
- IDeviceConfiguration conf = base.createDeviceConfiguration();
- conf.MoviePath = MoviePath;
- return conf;
- }
- protected override void registerHandles()
- {
- base.registerHandles();
- device.RegisterParameterHandle<int>("SOURCE.MOVIE.PlayMode").Value = 1; // 0=once, 1=loop, 2=pingPong
- currentMovieFrame = device.RegisterParameterHandle<int>("SOURCE.MOVIE.CurrentFrame");
- frameCount = device.RegisterParameterHandle<int>("SOURCE.MOVIE.FrameCount");
- playStep = device.RegisterParameterHandle<int>("SOURCE.MOVIE.PlayStep");
- }
- public void pause()
- {
- IsPaused = true;
- }
- public void play()
- {
- IsPaused = false;
- }
- public void goToNextFrame()
- {
- nextFrame();
- }
- public void goToPreviousFrame()
- {
- playStep.Value = -1;
- nextFrame();
- playStep.Value = 1;
- }
- protected override void run() {
- while (IsActive) {
- if (!IsPaused)
- nextFrame();
- else
- Thread.Sleep((int)(1000 / frameRate.Value));
- }
- }
- protected override void nextFrame()
- {
- base.nextFrame();
- if(CurrentFrameID == 0 && MovieRestartedEvent != null)
- MovieRestartedEvent(this, new EventArgs());
- }
- }
- }
|