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.

168 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. //==============================================================================
  18. #define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD) \
  19. METHOD (play, "play", "()V") \
  20. METHOD (stop, "stop", "()V") \
  21. METHOD (close, "close", "()V") \
  22. METHOD (isPlaying, "isPlaying", "()Z") \
  23. METHOD (loadFile, "loadFile", "(Ljava/lang/String;)Z") \
  24. METHOD (loadURL, "loadURL", "(Ljava/lang/String;)Z") \
  25. METHOD (setCurrentPosition, "setCurrentPosition", "(D)V") \
  26. METHOD (getCurrentPosition, "getCurrentPosition", "()D") \
  27. METHOD (setSpeed, "setSpeed", "(D)V") \
  28. METHOD (getDuration, "getDuration", "()D") \
  29. METHOD (getVideoWidth, "getVideoWidth", "()I") \
  30. METHOD (getVideoHeight, "getVideoHeight", "()I") \
  31. METHOD (setVolume, "setVolume", "(F)V") \
  32. METHOD (getVolume, "getVolume", "()F") \
  33. DECLARE_JNI_CLASS (VideoView, JUCE_ANDROID_ACTIVITY_CLASSPATH "$VideoView")
  34. #undef JNI_CLASS_MEMBERS
  35. struct VideoComponent::Pimpl : public Component
  36. {
  37. Pimpl()
  38. {
  39. }
  40. ~Pimpl()
  41. {
  42. close();
  43. }
  44. Result load (const File& file)
  45. {
  46. if (isOpen() && videoView.callBooleanMethod (VideoView.loadFile, javaString (file.getFullPathName()).get()))
  47. {
  48. currentFile = file;
  49. return Result::ok();
  50. }
  51. return Result::fail ("Couldn't open file");
  52. }
  53. Result load (const URL& url)
  54. {
  55. if (isOpen() && videoView.callBooleanMethod (VideoView.loadFile, javaString (url.toString (true)).get()))
  56. {
  57. currentURL = url;
  58. return Result::ok();
  59. }
  60. return Result::fail ("Couldn't open file");
  61. }
  62. void close()
  63. {
  64. if (isOpen())
  65. videoView.callVoidMethod (VideoView.close);
  66. }
  67. bool isOpen() const
  68. {
  69. return videoView != nullptr;
  70. }
  71. bool isPlaying() const
  72. {
  73. return isOpen() && videoView.callBooleanMethod (VideoView.isPlaying);
  74. }
  75. void play()
  76. {
  77. if (isOpen())
  78. videoView.callVoidMethod (VideoView.play);
  79. }
  80. void stop()
  81. {
  82. if (isOpen())
  83. videoView.callVoidMethod (VideoView.stop);
  84. }
  85. void setPosition (double newPosition)
  86. {
  87. if (isOpen())
  88. videoView.callVoidMethod (VideoView.setCurrentPosition, (jdouble) newPosition);
  89. }
  90. double getPosition() const
  91. {
  92. if (isOpen())
  93. return videoView.callDoubleMethod (VideoView.getCurrentPosition);
  94. return 0.0;
  95. }
  96. void setSpeed (double newSpeed)
  97. {
  98. if (isOpen())
  99. videoView.callVoidMethod (VideoView.setSpeed, (jdouble) newSpeed);
  100. }
  101. Rectangle<int> getNativeSize() const
  102. {
  103. if (isOpen())
  104. {
  105. jint w = videoView.callIntMethod (VideoView.getVideoWidth);
  106. jint h = videoView.callIntMethod (VideoView.getVideoHeight);
  107. return Rectangle<int> (w, h);
  108. }
  109. return Rectangle<int>();
  110. }
  111. double getDuration() const
  112. {
  113. if (isOpen())
  114. return videoView.callDoubleMethod (VideoView.getDuration);
  115. return 0.0;
  116. }
  117. void setVolume (float newVolume)
  118. {
  119. if (isOpen())
  120. videoView.callVoidMethod (VideoView.setVolume, (jfloat) newVolume);
  121. }
  122. float getVolume() const
  123. {
  124. if (isOpen())
  125. return videoView.callFloatMethod (VideoView.getVolume);
  126. return 0.0f;
  127. }
  128. File currentFile;
  129. URL currentURL;
  130. GlobalRef videoView;
  131. };