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.

164 lines
4.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. namespace juce
  20. {
  21. #if ! (JUCE_LINUX || JUCE_PROJUCER_LIVE_BUILD)
  22. #if JUCE_MAC || JUCE_IOS
  23. #include "../native/juce_mac_Video.h"
  24. #elif JUCE_WINDOWS
  25. #include "../native/juce_win32_Video.h"
  26. #elif JUCE_ANDROID
  27. #include "../native/juce_android_Video.h"
  28. #endif
  29. //==============================================================================
  30. VideoComponent::VideoComponent (bool useNativeControlsIfAvailable)
  31. : pimpl (new Pimpl (*this, useNativeControlsIfAvailable))
  32. {
  33. addAndMakeVisible (pimpl.get());
  34. }
  35. VideoComponent::~VideoComponent()
  36. {
  37. pimpl.reset();
  38. }
  39. Result VideoComponent::load (const File& file)
  40. {
  41. #if JUCE_ANDROID || JUCE_IOS
  42. ignoreUnused (file);
  43. jassertfalse;
  44. return Result::fail ("load() is not supported on this platform. Use loadAsync() instead.");
  45. #else
  46. auto r = pimpl->load (file);
  47. resized();
  48. return r;
  49. #endif
  50. }
  51. Result VideoComponent::load (const URL& url)
  52. {
  53. #if JUCE_ANDROID || JUCE_IOS
  54. // You need to use loadAsync on Android & iOS.
  55. ignoreUnused (url);
  56. jassertfalse;
  57. return Result::fail ("load() is not supported on this platform. Use loadAsync() instead.");
  58. #else
  59. auto r = pimpl->load (url);
  60. resized();
  61. return r;
  62. #endif
  63. }
  64. void VideoComponent::loadAsync (const URL& url, std::function<void(const URL&, Result)> callback)
  65. {
  66. if (callback == nullptr)
  67. {
  68. jassertfalse;
  69. return;
  70. }
  71. #if JUCE_ANDROID || JUCE_IOS || JUCE_MAC
  72. pimpl->loadAsync (url, callback);
  73. #else
  74. auto result = load (url);
  75. callback (url, result);
  76. #endif
  77. }
  78. void VideoComponent::closeVideo()
  79. {
  80. pimpl->close();
  81. // Closing on Android is async and resized() will be called internally by pimpl once
  82. // close operation finished.
  83. #if ! JUCE_ANDROID// TODO JUCE_IOS too?
  84. resized();
  85. #endif
  86. }
  87. bool VideoComponent::isVideoOpen() const { return pimpl->isOpen(); }
  88. File VideoComponent::getCurrentVideoFile() const { return pimpl->currentFile; }
  89. URL VideoComponent::getCurrentVideoURL() const { return pimpl->currentURL; }
  90. double VideoComponent::getVideoDuration() const { return pimpl->getDuration(); }
  91. Rectangle<int> VideoComponent::getVideoNativeSize() const { return pimpl->getNativeSize(); }
  92. void VideoComponent::play() { pimpl->play(); }
  93. void VideoComponent::stop() { pimpl->stop(); }
  94. bool VideoComponent::isPlaying() const { return pimpl->isPlaying(); }
  95. void VideoComponent::setPlayPosition (double newPos) { pimpl->setPosition (newPos); }
  96. double VideoComponent::getPlayPosition() const { return pimpl->getPosition(); }
  97. void VideoComponent::setPlaySpeed (double newSpeed) { pimpl->setSpeed (newSpeed); }
  98. double VideoComponent::getPlaySpeed() const { return pimpl->getSpeed(); }
  99. void VideoComponent::setAudioVolume (float newVolume) { pimpl->setVolume (newVolume); }
  100. float VideoComponent::getAudioVolume() const { return pimpl->getVolume(); }
  101. void VideoComponent::resized()
  102. {
  103. auto r = getLocalBounds();
  104. if (isVideoOpen() && ! r.isEmpty())
  105. {
  106. auto nativeSize = getVideoNativeSize();
  107. if (nativeSize.isEmpty())
  108. {
  109. // if we've just opened the file and are still waiting for it to
  110. // figure out the size, start our timer..
  111. if (! isTimerRunning())
  112. startTimer (50);
  113. }
  114. else
  115. {
  116. r = RectanglePlacement (RectanglePlacement::centred).appliedTo (nativeSize, r);
  117. stopTimer();
  118. }
  119. }
  120. else
  121. {
  122. stopTimer();
  123. }
  124. pimpl->setBounds (r);
  125. }
  126. void VideoComponent::timerCallback()
  127. {
  128. resized();
  129. }
  130. #endif
  131. } // namespace juce