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.

205 lines
7.0KB

  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. #ifndef JUCE_VIDEOCOMPONENT_H_INCLUDED
  18. #define JUCE_VIDEOCOMPONENT_H_INCLUDED
  19. namespace juce
  20. {
  21. //==============================================================================
  22. /**
  23. A component that can play a movie.
  24. Use the load() method to open a video once you've added this component to
  25. a parent (or put it on the desktop).
  26. @tags{Video}
  27. */
  28. class JUCE_API VideoComponent : public Component,
  29. private Timer
  30. {
  31. public:
  32. //==============================================================================
  33. /** Creates an empty VideoComponent.
  34. Use the loadAsync() or load() method to open a video once you've added
  35. this component to a parent (or put it on the desktop).
  36. If useNativeControlsIfAvailable is enabled and a target OS has a video view with
  37. dedicated controls for transport etc, that view will be used. In opposite
  38. case a bare video view without any controls will be presented, allowing you to
  39. tailor your own UI. Currently this flag is used on iOS and 64bit macOS.
  40. Android, Windows and 32bit macOS will always use plain video views without
  41. dedicated controls.
  42. */
  43. VideoComponent (bool useNativeControlsIfAvailable);
  44. /** Destructor. */
  45. ~VideoComponent();
  46. //==============================================================================
  47. /** Tries to load a video from a local file.
  48. This function is supported on macOS and Windows. For iOS and Android, use
  49. loadAsync() instead.
  50. @returns an error if the file failed to be loaded correctly
  51. @see loadAsync
  52. */
  53. Result load (const File& file);
  54. /** Tries to load a video from a URL.
  55. This function is supported on macOS and Windows. For iOS and Android, use
  56. loadAsync() instead.
  57. @returns an error if the file failed to be loaded correctly
  58. @see loadAsync
  59. */
  60. Result load (const URL& url);
  61. /** Tries to load a video from a URL asynchronously. When finished, invokes the
  62. callback supplied to the function on the message thread.
  63. This is the preferred way of loading content, since it works not only on
  64. macOS and Windows, but also on iOS and Android. On Windows, it will internally
  65. call load().
  66. @see load
  67. */
  68. void loadAsync (const URL& url, std::function<void (const URL&, Result)> loadFinishedCallback);
  69. /** Closes the video and resets the component. */
  70. void closeVideo();
  71. /** Returns true if a video is currently open. */
  72. bool isVideoOpen() const;
  73. /** Returns the last file that was loaded.
  74. If nothing is open, or if it was a URL rather than a file, this will return File().
  75. */
  76. File getCurrentVideoFile() const;
  77. /** Returns the last URL that was loaded.
  78. If nothing is open, or if it was a file rather than a URL, this will return URL().
  79. */
  80. URL getCurrentVideoURL() const;
  81. //==============================================================================
  82. /** Returns the length of the video, in seconds. */
  83. double getVideoDuration() const;
  84. /** Returns the video's natural size, in pixels.
  85. If no video is loaded, an empty rectangle will be returned.
  86. */
  87. Rectangle<int> getVideoNativeSize() const;
  88. /** Starts the video playing. */
  89. void play();
  90. /** Stops the video playing. */
  91. void stop();
  92. /** Returns true if the video is currently playing. */
  93. bool isPlaying() const;
  94. /** Sets the video's position to a given time. */
  95. void setPlayPosition (double newPositionSeconds);
  96. /** Returns the current play position of the video. */
  97. double getPlayPosition() const;
  98. /** Changes the video playback rate.
  99. A value of 1.0 is normal speed, greater values will play faster, smaller
  100. values play more slowly.
  101. */
  102. void setPlaySpeed (double newSpeed);
  103. /** Returns the current play speed of the video. */
  104. double getPlaySpeed() const;
  105. /** Changes the video's playback volume.
  106. @param newVolume the volume in the range 0 (silent) to 1.0 (full)
  107. */
  108. void setAudioVolume (float newVolume);
  109. /** Returns the video's playback volume.
  110. @returns the volume in the range 0 (silent) to 1.0 (full)
  111. */
  112. float getAudioVolume() const;
  113. #if JUCE_SYNC_VIDEO_VOLUME_WITH_OS_MEDIA_VOLUME
  114. /** Set this callback to be notified whenever OS global media volume changes.
  115. Currently used on Android only.
  116. */
  117. std::function<void()> onGlobalMediaVolumeChanged;
  118. #endif
  119. /** Set this callback to be notified whenever the playback starts. */
  120. std::function<void()> onPlaybackStarted;
  121. /** Set this callback to be notified whenever the playback stops. */
  122. std::function<void()> onPlaybackStopped;
  123. /** Set this callback to be notified whenever an error occurs. Upon error, you
  124. may need to load the video again. */
  125. std::function<void (const String& /*error*/)> onErrorOccurred;
  126. private:
  127. //==============================================================================
  128. struct Pimpl;
  129. std::unique_ptr<Pimpl> pimpl;
  130. void resized() override;
  131. void timerCallback() override;
  132. #if JUCE_ANDROID
  133. friend void juce_surfaceChangedNativeVideo (int64, void*);
  134. friend void juce_surfaceDestroyedNativeVideo (int64, void*);
  135. friend void juce_mediaSessionPause (int64);
  136. friend void juce_mediaSessionPlay (int64);
  137. friend void juce_mediaSessionPlayFromMediaId (int64, void*, void*);
  138. friend void juce_mediaSessionSeekTo (int64, int64);
  139. friend void juce_mediaSessionStop (int64);
  140. friend void juce_mediaControllerAudioInfoChanged (int64, void*);
  141. friend void juce_mediaControllerMetadataChanged (int64, void*);
  142. friend void juce_mediaControllerPlaybackStateChanged (int64, void*);
  143. friend void juce_mediaControllerSessionDestroyed (int64);
  144. friend void juce_mediaSessionSystemVolumeChanged (int64);
  145. #endif
  146. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (VideoComponent)
  147. };
  148. #endif
  149. } // namespace juce