The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

156 lines
4.8KB

  1. #include "../jucedemo_headers.h"
  2. #if JUCE_DIRECTSHOW
  3. //==============================================================================
  4. class DirectShowWindowWithFileBrowser : public Component,
  5. public FilenameComponentListener
  6. {
  7. public:
  8. DirectShowWindowWithFileBrowser (DirectShowComponent::VideoRendererType type)
  9. : fileChooser ("movie", File::nonexistent, true, false, false,
  10. "*", String::empty, "(choose a video file to play)"),
  11. dshowComp (type)
  12. {
  13. addAndMakeVisible (&dshowComp);
  14. addAndMakeVisible (&fileChooser);
  15. fileChooser.addListener (this);
  16. fileChooser.setBrowseButtonText ("browse");
  17. }
  18. void resized()
  19. {
  20. dshowComp.setBounds (0, 0, getWidth(), getHeight() - 60);
  21. if (transportControl != 0)
  22. transportControl->setBounds (0, dshowComp.getBottom() + 4, getWidth(), 26);
  23. fileChooser.setBounds (0, getHeight() - 24, getWidth(), 24);
  24. }
  25. void filenameComponentChanged (FilenameComponent*)
  26. {
  27. // this is called when the user changes the filename in the file chooser box
  28. if (dshowComp.loadMovie (fileChooser.getCurrentFile()))
  29. {
  30. addAndMakeVisible (transportControl = new TransportControl (dshowComp));
  31. resized();
  32. dshowComp.play();
  33. }
  34. else
  35. {
  36. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  37. "Couldn't load the file!",
  38. "Sorry, DirectShow didn't manage to load that file!");
  39. }
  40. }
  41. private:
  42. DirectShowComponent dshowComp;
  43. FilenameComponent fileChooser;
  44. //==============================================================================
  45. // A quick-and-dirty transport control, containing a play button and a position slider..
  46. class TransportControl : public Component,
  47. public ButtonListener,
  48. public SliderListener,
  49. public Timer
  50. {
  51. public:
  52. TransportControl (DirectShowComponent& dshowComp_)
  53. : playButton ("Play/Pause"),
  54. position (String::empty),
  55. dshowComp (dshowComp_)
  56. {
  57. addAndMakeVisible (&playButton);
  58. playButton.addListener (this);
  59. addAndMakeVisible (&position);
  60. position.setRange (0, dshowComp.getMovieDuration(), 0);
  61. position.setSliderStyle (Slider::LinearHorizontal);
  62. position.setTextBoxStyle (Slider::NoTextBox, false, 80, 20);
  63. position.addListener (this);
  64. startTimer (1000 / 50);
  65. }
  66. void buttonClicked (Button* buttonThatWasClicked)
  67. {
  68. if (dshowComp.isPlaying())
  69. dshowComp.stop();
  70. else
  71. dshowComp.play();
  72. }
  73. void sliderValueChanged (Slider* sliderThatWasMoved)
  74. {
  75. dshowComp.setPosition (position.getValue());
  76. }
  77. void resized()
  78. {
  79. const int playButtonWidth = 90;
  80. playButton.setBounds (0, 0, playButtonWidth, getHeight());
  81. position.setBounds (playButtonWidth, 0, getWidth() - playButtonWidth, getHeight());
  82. }
  83. void timerCallback()
  84. {
  85. if (! position.isMouseButtonDown())
  86. position.setValue (dshowComp.getPosition(), false);
  87. }
  88. private:
  89. TextButton playButton;
  90. Slider position;
  91. DirectShowComponent& dshowComp;
  92. };
  93. ScopedPointer<TransportControl> transportControl;
  94. };
  95. //==============================================================================
  96. class DirectShowDemo : public Component
  97. {
  98. public:
  99. //==============================================================================
  100. DirectShowDemo()
  101. : dsComp1 (DirectShowComponent::dshowVMR7),
  102. dsComp2 (DirectShowComponent::dshowEVR)
  103. {
  104. setName ("DirectShow");
  105. // add a movie component..
  106. addAndMakeVisible (&dsComp1);
  107. addAndMakeVisible (&dsComp2);
  108. }
  109. ~DirectShowDemo()
  110. {
  111. dsComp1.setVisible (false);
  112. dsComp2.setVisible (false);
  113. }
  114. void resized()
  115. {
  116. dsComp1.setBoundsRelative (0.05f, 0.05f, 0.425f, 0.9f);
  117. dsComp2.setBoundsRelative (0.525f, 0.05f, 0.425f, 0.9f);
  118. }
  119. private:
  120. //==============================================================================
  121. DirectShowWindowWithFileBrowser dsComp1, dsComp2;
  122. };
  123. //==============================================================================
  124. Component* createDirectShowDemo()
  125. {
  126. return new DirectShowDemo();
  127. }
  128. #endif