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.

191 lines
6.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  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 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. #ifndef JUCE_VIDEOCOMPONENT_H_INCLUDED
  19. #define JUCE_VIDEOCOMPONENT_H_INCLUDED
  20. namespace juce
  21. {
  22. //==============================================================================
  23. /**
  24. A component that can play a movie.
  25. Use the load() method to open a video once you've added this component to
  26. a parent (or put it on the desktop).
  27. @tags{Video}
  28. */
  29. class JUCE_API VideoComponent : public Component,
  30. private Timer
  31. {
  32. public:
  33. //==============================================================================
  34. /** Creates an empty VideoComponent.
  35. Use the loadAsync() or load() method to open a video once you've added
  36. this component to a parent (or put it on the desktop).
  37. If useNativeControlsIfAvailable is enabled and a target OS has a video view with
  38. dedicated controls for transport etc, that view will be used. In opposite
  39. case a bare video view without any controls will be presented, allowing you to
  40. tailor your own UI. Currently this flag is used on iOS and 64bit macOS.
  41. Android, Windows and 32bit macOS will always use plain video views without
  42. dedicated controls.
  43. */
  44. VideoComponent (bool useNativeControlsIfAvailable);
  45. /** Destructor. */
  46. ~VideoComponent() override;
  47. //==============================================================================
  48. /** Tries to load a video from a local file.
  49. This function is supported on macOS and Windows. For iOS and Android, use
  50. loadAsync() instead.
  51. @returns an error if the file failed to be loaded correctly
  52. @see loadAsync
  53. */
  54. Result load (const File& file);
  55. /** Tries to load a video from a URL.
  56. This function is supported on macOS and Windows. For iOS and Android, use
  57. loadAsync() instead.
  58. @returns an error if the file failed to be loaded correctly
  59. @see loadAsync
  60. */
  61. Result load (const URL& url);
  62. /** Tries to load a video from a URL asynchronously. When finished, invokes the
  63. callback supplied to the function on the message thread.
  64. This is the preferred way of loading content, since it works not only on
  65. macOS and Windows, but also on iOS and Android. On Windows, it will internally
  66. call load().
  67. @see load
  68. */
  69. void loadAsync (const URL& url, std::function<void (const URL&, Result)> loadFinishedCallback);
  70. /** Closes the video and resets the component. */
  71. void closeVideo();
  72. /** Returns true if a video is currently open. */
  73. bool isVideoOpen() const;
  74. /** Returns the last file that was loaded.
  75. If nothing is open, or if it was a URL rather than a file, this will return File().
  76. */
  77. File getCurrentVideoFile() const;
  78. /** Returns the last URL that was loaded.
  79. If nothing is open, or if it was a file rather than a URL, this will return URL().
  80. */
  81. URL getCurrentVideoURL() const;
  82. //==============================================================================
  83. /** Returns the length of the video, in seconds. */
  84. double getVideoDuration() const;
  85. /** Returns the video's natural size, in pixels.
  86. If no video is loaded, an empty rectangle will be returned.
  87. */
  88. Rectangle<int> getVideoNativeSize() const;
  89. /** Starts the video playing. */
  90. void play();
  91. /** Stops the video playing. */
  92. void stop();
  93. /** Returns true if the video is currently playing. */
  94. bool isPlaying() const;
  95. /** Sets the video's position to a given time. */
  96. void setPlayPosition (double newPositionSeconds);
  97. /** Returns the current play position of the video. */
  98. double getPlayPosition() const;
  99. /** Changes the video playback rate.
  100. A value of 1.0 is normal speed, greater values will play faster, smaller
  101. values play more slowly.
  102. */
  103. void setPlaySpeed (double newSpeed);
  104. /** Returns the current play speed of the video. */
  105. double getPlaySpeed() const;
  106. /** Changes the video's playback volume.
  107. @param newVolume the volume in the range 0 (silent) to 1.0 (full)
  108. */
  109. void setAudioVolume (float newVolume);
  110. /** Returns the video's playback volume.
  111. @returns the volume in the range 0 (silent) to 1.0 (full)
  112. */
  113. float getAudioVolume() const;
  114. #if JUCE_SYNC_VIDEO_VOLUME_WITH_OS_MEDIA_VOLUME
  115. /** Set this callback to be notified whenever OS global media volume changes.
  116. Currently used on Android only.
  117. */
  118. std::function<void()> onGlobalMediaVolumeChanged;
  119. #endif
  120. /** Set this callback to be notified whenever the playback starts. */
  121. std::function<void()> onPlaybackStarted;
  122. /** Set this callback to be notified whenever the playback stops. */
  123. std::function<void()> onPlaybackStopped;
  124. /** Set this callback to be notified whenever an error occurs. Upon error, you
  125. may need to load the video again. */
  126. std::function<void (const String& /*error*/)> onErrorOccurred;
  127. private:
  128. //==============================================================================
  129. struct Pimpl;
  130. std::unique_ptr<Pimpl> pimpl;
  131. void resized() override;
  132. void timerCallback() override;
  133. template <class FileOrURL>
  134. Result loadInternal (const FileOrURL&, bool);
  135. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (VideoComponent)
  136. };
  137. #endif
  138. } // namespace juce