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.

124 lines
3.6KB

  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. namespace juce
  18. {
  19. #if JUCE_MAC || JUCE_IOS || JUCE_MSVC
  20. #if JUCE_MAC || JUCE_IOS
  21. #include "../native/juce_mac_Video.h"
  22. #elif JUCE_WINDOWS
  23. #include "../native/juce_win32_Video.h"
  24. #endif
  25. //==============================================================================
  26. VideoComponent::VideoComponent() : pimpl (new Pimpl())
  27. {
  28. addAndMakeVisible (pimpl.get());
  29. }
  30. VideoComponent::~VideoComponent()
  31. {
  32. pimpl.reset();
  33. }
  34. Result VideoComponent::load (const File& file)
  35. {
  36. auto r = pimpl->load (file);
  37. resized();
  38. return r;
  39. }
  40. Result VideoComponent::load (const URL& url)
  41. {
  42. auto r = pimpl->load (url);
  43. resized();
  44. return r;
  45. }
  46. void VideoComponent::closeVideo()
  47. {
  48. pimpl->close();
  49. resized();
  50. }
  51. bool VideoComponent::isVideoOpen() const { return pimpl->isOpen(); }
  52. File VideoComponent::getCurrentVideoFile() const { return pimpl->currentFile; }
  53. URL VideoComponent::getCurrentVideoURL() const { return pimpl->currentURL; }
  54. double VideoComponent::getVideoDuration() const { return pimpl->getDuration(); }
  55. Rectangle<int> VideoComponent::getVideoNativeSize() const { return pimpl->getNativeSize(); }
  56. void VideoComponent::play() { pimpl->play(); }
  57. void VideoComponent::stop() { pimpl->stop(); }
  58. bool VideoComponent::isPlaying() const { return pimpl->isPlaying(); }
  59. void VideoComponent::setPlayPosition (double newPos) { pimpl->setPosition (newPos); }
  60. double VideoComponent::getPlayPosition() const { return pimpl->getPosition(); }
  61. void VideoComponent::setPlaySpeed (double newSpeed) { pimpl->setSpeed (newSpeed); }
  62. void VideoComponent::setAudioVolume (float newVolume) { pimpl->setVolume (newVolume); }
  63. float VideoComponent::getAudioVolume() const { return pimpl->getVolume(); }
  64. void VideoComponent::resized()
  65. {
  66. auto r = getLocalBounds();
  67. if (isVideoOpen() && ! r.isEmpty())
  68. {
  69. auto nativeSize = getVideoNativeSize();
  70. if (nativeSize.isEmpty())
  71. {
  72. // if we've just opened the file and are still waiting for it to
  73. // figure out the size, start our timer..
  74. if (! isTimerRunning())
  75. startTimer (50);
  76. }
  77. else
  78. {
  79. r = RectanglePlacement (RectanglePlacement::centred).appliedTo (nativeSize, r);
  80. stopTimer();
  81. }
  82. }
  83. else
  84. {
  85. stopTimer();
  86. }
  87. pimpl->setBounds (r);
  88. }
  89. void VideoComponent::timerCallback()
  90. {
  91. resized();
  92. }
  93. #endif
  94. } // namespace juce