VideoInputProvider.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6. using Iisu;
  7. using bbiwarg.Utility;
  8. namespace bbiwarg.Input.InputProviding
  9. {
  10. public delegate void MovieRestartedEventHandler(object sender, EventArgs e);
  11. class VideoInputProvider : InputProvider
  12. {
  13. private IParameterHandle<int> currentMovieFrame;
  14. private IParameterHandle<int> frameCount;
  15. private IParameterHandle<int> playStep;
  16. public override int CurrentFrameID { get { return currentMovieFrame.Value; } }
  17. public String MoviePath { get; private set; }
  18. public bool IsPaused { get; private set; }
  19. public event MovieRestartedEventHandler MovieRestartedEvent;
  20. public VideoInputProvider(String moviePath)
  21. {
  22. MoviePath = moviePath;
  23. }
  24. protected override IDeviceConfiguration createDeviceConfiguration()
  25. {
  26. IDeviceConfiguration conf = base.createDeviceConfiguration();
  27. conf.MoviePath = MoviePath;
  28. return conf;
  29. }
  30. protected override void registerHandles()
  31. {
  32. base.registerHandles();
  33. device.RegisterParameterHandle<int>("SOURCE.MOVIE.PlayMode").Value = 1; // 0=once, 1=loop, 2=pingPong
  34. currentMovieFrame = device.RegisterParameterHandle<int>("SOURCE.MOVIE.CurrentFrame");
  35. frameCount = device.RegisterParameterHandle<int>("SOURCE.MOVIE.FrameCount");
  36. playStep = device.RegisterParameterHandle<int>("SOURCE.MOVIE.PlayStep");
  37. }
  38. public void pause()
  39. {
  40. IsPaused = true;
  41. }
  42. public void play()
  43. {
  44. IsPaused = false;
  45. }
  46. public void goToNextFrame()
  47. {
  48. nextFrame();
  49. }
  50. public void goToPreviousFrame()
  51. {
  52. playStep.Value = -1;
  53. nextFrame();
  54. playStep.Value = 1;
  55. }
  56. protected override void run() {
  57. while (IsActive) {
  58. if (!IsPaused)
  59. nextFrame();
  60. else
  61. Thread.Sleep((int)(1000 / frameRate.Value));
  62. }
  63. }
  64. protected override void nextFrame()
  65. {
  66. base.nextFrame();
  67. if(CurrentFrameID == 0 && MovieRestartedEvent != null)
  68. MovieRestartedEvent(this, new EventArgs());
  69. }
  70. }
  71. }