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.

220 lines
7.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_DIRECTSHOWCOMPONENT_JUCEHEADER__
  19. #define __JUCE_DIRECTSHOWCOMPONENT_JUCEHEADER__
  20. #if JUCE_DIRECTSHOW || DOXYGEN
  21. //==============================================================================
  22. /**
  23. A window that can play back a DirectShow video.
  24. @note Controller is not implemented
  25. */
  26. class JUCE_API DirectShowComponent : public Component
  27. {
  28. public:
  29. //==============================================================================
  30. /** DirectShow video renderer type.
  31. See MSDN for adivce about choosing the right renderer.
  32. */
  33. enum VideoRendererType
  34. {
  35. dshowDefault, /**< VMR7 for Windows XP, EVR for Windows Vista and later */
  36. dshowVMR7, /**< Video Mixing Renderer 7 */
  37. dshowEVR /**< Enhanced Video Renderer */
  38. };
  39. /** Creates a DirectShowComponent, initially blank.
  40. Use the loadMovie() method to load a video once you've added the
  41. component to a window, (or put it on the desktop as a heavyweight window).
  42. Loading a video when the component isn't visible can cause problems, as
  43. DirectShow needs a window handle to initialise properly.
  44. @see VideoRendererType
  45. */
  46. DirectShowComponent (VideoRendererType type = dshowDefault);
  47. /** Destructor. */
  48. ~DirectShowComponent();
  49. /** Returns true if DirectShow is installed and working on this machine. */
  50. static bool isDirectShowAvailable();
  51. //==============================================================================
  52. /** Tries to load a DirectShow video from a file or URL into the player.
  53. It's best to call this function once you've added the component to a window,
  54. (or put it on the desktop as a heavyweight window). Loading a video when the
  55. component isn't visible can cause problems, because DirectShow needs a window
  56. handle to do its stuff.
  57. @param fileOrURLPath the file or URL path to open
  58. @returns true if the video opens successfully
  59. */
  60. bool loadMovie (const String& fileOrURLPath);
  61. /** Tries to load a DirectShow video from a file into the player.
  62. It's best to call this function once you've added the component to a window,
  63. (or put it on the desktop as a heavyweight window). Loading a video when the
  64. component isn't visible can cause problems, because DirectShow needs a window
  65. handle to do its stuff.
  66. @param videoFile the video file to open
  67. @returns true if the video opens successfully
  68. */
  69. bool loadMovie (const File& videoFile);
  70. /** Tries to load a DirectShow video from a URL into the player.
  71. It's best to call this function once you've added the component to a window,
  72. (or put it on the desktop as a heavyweight window). Loading a video when the
  73. component isn't visible can cause problems, because DirectShow needs a window
  74. handle to do its stuff.
  75. @param videoURL the video URL to open
  76. @returns true if the video opens successfully
  77. */
  78. bool loadMovie (const URL& videoURL);
  79. /** Closes the video, if one is open. */
  80. void closeMovie();
  81. /** Returns the file path or URL from which the video file was loaded.
  82. If there isn't one, this returns an empty string.
  83. */
  84. File getCurrentMoviePath() const;
  85. /** Returns true if there's currently a video open. */
  86. bool isMovieOpen() const;
  87. /** Returns the length of the video, in seconds. */
  88. double getMovieDuration() const;
  89. /** Returns the video's natural size, in pixels.
  90. You can use this to resize the component to show the video at its preferred
  91. scale.
  92. If no video is loaded, the size returned will be 0 x 0.
  93. */
  94. void getMovieNormalSize (int& width, int& height) const;
  95. /** This will position the component within a given area, keeping its aspect
  96. ratio correct according to the video's normal size.
  97. The component will be made as large as it can go within the space, and will
  98. be aligned according to the justification value if this means there are gaps at
  99. the top or sides.
  100. @note Not implemented
  101. */
  102. void setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  103. const RectanglePlacement& placement);
  104. /** Starts the video playing. */
  105. void play();
  106. /** Stops the video playing. */
  107. void stop();
  108. /** Returns true if the video is currently playing. */
  109. bool isPlaying() const;
  110. /** Moves the video's position back to the start. */
  111. void goToStart();
  112. /** Sets the video's position to a given time. */
  113. void setPosition (double seconds);
  114. /** Returns the current play position of the video. */
  115. double getPosition() const;
  116. /** Changes the video playback rate.
  117. A value of 1 is normal speed, greater values play it proportionately faster,
  118. smaller values play it slower.
  119. */
  120. void setSpeed (float newSpeed);
  121. /** Changes the video's playback volume.
  122. @param newVolume the volume in the range 0 (silent) to 1.0 (full)
  123. */
  124. void setMovieVolume (float newVolume);
  125. /** Returns the video's playback volume.
  126. @returns the volume in the range 0 (silent) to 1.0 (full)
  127. */
  128. float getMovieVolume() const;
  129. /** Tells the video whether it should loop. */
  130. void setLooping (bool shouldLoop);
  131. /** Returns true if the video is currently looping.
  132. @see setLooping
  133. */
  134. bool isLooping() const;
  135. //==============================================================================
  136. /** @internal */
  137. void paint (Graphics& g);
  138. private:
  139. //==============================================================================
  140. String videoPath;
  141. bool videoLoaded, looping;
  142. class DirectShowContext;
  143. friend class DirectShowContext;
  144. friend class ScopedPointer <DirectShowContext>;
  145. ScopedPointer <DirectShowContext> context;
  146. class DirectShowComponentWatcher;
  147. friend class DirectShowComponentWatcher;
  148. friend class ScopedPointer <DirectShowComponentWatcher>;
  149. ScopedPointer <DirectShowComponentWatcher> componentWatcher;
  150. bool needToUpdateViewport, needToRecreateNativeWindow;
  151. //==============================================================================
  152. void updateContextPosition();
  153. void showContext (bool shouldBeVisible);
  154. void recreateNativeWindowAsync();
  155. //==============================================================================
  156. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DirectShowComponent);
  157. };
  158. #endif
  159. #endif // __JUCE_DIRECTSHOWCOMPONENT_JUCEHEADER__