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.

162 lines
4.7KB

  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_LINUX
  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. #elif JUCE_ANDROID
  25. #include "../native/juce_android_Video.h"
  26. #endif
  27. //==============================================================================
  28. VideoComponent::VideoComponent (bool useNativeControlsIfAvailable)
  29. : pimpl (new Pimpl (*this, useNativeControlsIfAvailable))
  30. {
  31. addAndMakeVisible (pimpl.get());
  32. }
  33. VideoComponent::~VideoComponent()
  34. {
  35. pimpl.reset();
  36. }
  37. Result VideoComponent::load (const File& file)
  38. {
  39. #if JUCE_ANDROID || JUCE_IOS
  40. ignoreUnused (file);
  41. jassertfalse;
  42. return Result::fail ("load() is not supported on this platform. Use loadAsync() instead.");
  43. #else
  44. auto r = pimpl->load (file);
  45. resized();
  46. return r;
  47. #endif
  48. }
  49. Result VideoComponent::load (const URL& url)
  50. {
  51. #if JUCE_ANDROID || JUCE_IOS
  52. // You need to use loadAsync on Android & iOS.
  53. ignoreUnused (url);
  54. jassertfalse;
  55. return Result::fail ("load() is not supported on this platform. Use loadAsync() instead.");
  56. #else
  57. auto r = pimpl->load (url);
  58. resized();
  59. return r;
  60. #endif
  61. }
  62. void VideoComponent::loadAsync (const URL& url, std::function<void (const URL&, Result)> callback)
  63. {
  64. if (callback == nullptr)
  65. {
  66. jassertfalse;
  67. return;
  68. }
  69. #if JUCE_ANDROID || JUCE_IOS || JUCE_MAC
  70. pimpl->loadAsync (url, callback);
  71. #else
  72. auto result = load (url);
  73. callback (url, result);
  74. #endif
  75. }
  76. void VideoComponent::closeVideo()
  77. {
  78. pimpl->close();
  79. // Closing on Android is async and resized() will be called internally by pimpl once
  80. // close operation finished.
  81. #if ! JUCE_ANDROID// TODO JUCE_IOS too?
  82. resized();
  83. #endif
  84. }
  85. bool VideoComponent::isVideoOpen() const { return pimpl->isOpen(); }
  86. File VideoComponent::getCurrentVideoFile() const { return pimpl->currentFile; }
  87. URL VideoComponent::getCurrentVideoURL() const { return pimpl->currentURL; }
  88. double VideoComponent::getVideoDuration() const { return pimpl->getDuration(); }
  89. Rectangle<int> VideoComponent::getVideoNativeSize() const { return pimpl->getNativeSize(); }
  90. void VideoComponent::play() { pimpl->play(); }
  91. void VideoComponent::stop() { pimpl->stop(); }
  92. bool VideoComponent::isPlaying() const { return pimpl->isPlaying(); }
  93. void VideoComponent::setPlayPosition (double newPos) { pimpl->setPosition (newPos); }
  94. double VideoComponent::getPlayPosition() const { return pimpl->getPosition(); }
  95. void VideoComponent::setPlaySpeed (double newSpeed) { pimpl->setSpeed (newSpeed); }
  96. double VideoComponent::getPlaySpeed() const { return pimpl->getSpeed(); }
  97. void VideoComponent::setAudioVolume (float newVolume) { pimpl->setVolume (newVolume); }
  98. float VideoComponent::getAudioVolume() const { return pimpl->getVolume(); }
  99. void VideoComponent::resized()
  100. {
  101. auto r = getLocalBounds();
  102. if (isVideoOpen() && ! r.isEmpty())
  103. {
  104. auto nativeSize = getVideoNativeSize();
  105. if (nativeSize.isEmpty())
  106. {
  107. // if we've just opened the file and are still waiting for it to
  108. // figure out the size, start our timer..
  109. if (! isTimerRunning())
  110. startTimer (50);
  111. }
  112. else
  113. {
  114. r = RectanglePlacement (RectanglePlacement::centred).appliedTo (nativeSize, r);
  115. stopTimer();
  116. }
  117. }
  118. else
  119. {
  120. stopTimer();
  121. }
  122. pimpl->setBounds (r);
  123. }
  124. void VideoComponent::timerCallback()
  125. {
  126. resized();
  127. }
  128. #endif
  129. } // namespace juce