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.

119 lines
3.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #if JUCE_MAC || JUCE_IOS || JUCE_MSVC
  18. #if JUCE_MAC || JUCE_IOS
  19. #include "../native/juce_mac_Video.h"
  20. #elif JUCE_WINDOWS
  21. #include "../native/juce_win32_Video.h"
  22. #endif
  23. //==============================================================================
  24. VideoComponent::VideoComponent() : pimpl (new Pimpl())
  25. {
  26. addAndMakeVisible (pimpl);
  27. }
  28. VideoComponent::~VideoComponent()
  29. {
  30. pimpl = nullptr;
  31. }
  32. Result VideoComponent::load (const File& file)
  33. {
  34. Result r = pimpl->load (file);
  35. resized();
  36. return r;
  37. }
  38. Result VideoComponent::load (const URL& url)
  39. {
  40. Result r = pimpl->load (url);
  41. resized();
  42. return r;
  43. }
  44. void VideoComponent::closeVideo()
  45. {
  46. pimpl->close();
  47. resized();
  48. }
  49. bool VideoComponent::isVideoOpen() const { return pimpl->isOpen(); }
  50. File VideoComponent::getCurrentVideoFile() const { return pimpl->currentFile; }
  51. URL VideoComponent::getCurrentVideoURL() const { return pimpl->currentURL; }
  52. double VideoComponent::getVideoDuration() const { return pimpl->getDuration(); }
  53. Rectangle<int> VideoComponent::getVideoNativeSize() const { return pimpl->getNativeSize(); }
  54. void VideoComponent::play() { pimpl->play(); }
  55. void VideoComponent::stop() { pimpl->stop(); }
  56. bool VideoComponent::isPlaying() const { return pimpl->isPlaying(); }
  57. void VideoComponent::setPlayPosition (double newPos) { pimpl->setPosition (newPos); }
  58. double VideoComponent::getPlayPosition() const { return pimpl->getPosition(); }
  59. void VideoComponent::setPlaySpeed (double newSpeed) { pimpl->setSpeed (newSpeed); }
  60. void VideoComponent::setAudioVolume (float newVolume) { pimpl->setVolume (newVolume); }
  61. float VideoComponent::getAudioVolume() const { return pimpl->getVolume(); }
  62. void VideoComponent::resized()
  63. {
  64. Rectangle<int> r = getLocalBounds();
  65. if (isVideoOpen() && ! r.isEmpty())
  66. {
  67. Rectangle<int> nativeSize = getVideoNativeSize();
  68. if (nativeSize.isEmpty())
  69. {
  70. // if we've just opened the file and are still waiting for it to
  71. // figure out the size, start our timer..
  72. if (! isTimerRunning())
  73. startTimer (50);
  74. }
  75. else
  76. {
  77. r = RectanglePlacement (RectanglePlacement::centred).appliedTo (nativeSize, r);
  78. stopTimer();
  79. }
  80. }
  81. else
  82. {
  83. stopTimer();
  84. }
  85. pimpl->setBounds (r);
  86. }
  87. void VideoComponent::timerCallback()
  88. {
  89. resized();
  90. }
  91. #endif