react-native-theoplayer 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (287) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/LICENSE +21 -0
  3. package/README.md +54 -18
  4. package/android/build.gradle +90 -0
  5. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  6. package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
  7. package/android/gradlew +185 -0
  8. package/android/gradlew.bat +89 -0
  9. package/android/src/main/AndroidManifest.xml +6 -0
  10. package/android/src/main/java/com/theoplayer/PlayerConfigHelper.java +30 -0
  11. package/android/src/main/java/com/theoplayer/ReactTHEOplayerPackage.java +27 -0
  12. package/android/src/main/java/com/theoplayer/ReactTHEOplayerView.java +420 -0
  13. package/android/src/main/java/com/theoplayer/ReactTHEOplayerViewManager.java +114 -0
  14. package/android/src/main/java/com/theoplayer/SourceHelper.java +224 -0
  15. package/android/src/main/java/com/theoplayer/TimeUpdateRate.java +8 -0
  16. package/android/src/main/java/com/theoplayer/VideoEventEmitter.java +410 -0
  17. package/android/src/main/java/com/theoplayer/track/TextTrackCueEventType.java +11 -0
  18. package/android/src/main/java/com/theoplayer/track/TrackEventType.java +11 -0
  19. package/android/src/main/java/com/theoplayer/track/TrackListInfo.java +204 -0
  20. package/ios/THEOplayerRCTBridge.m +46 -0
  21. package/ios/THEOplayerRCTDebug.swift +16 -0
  22. package/ios/THEOplayerRCTMetadataAggregator.swift +169 -0
  23. package/ios/THEOplayerRCTView.swift +422 -0
  24. package/ios/THEOplayerRCTViewEventHandler.swift +493 -0
  25. package/ios/THEOplayerRCTViewManager.swift +23 -0
  26. package/ios/Theoplayer-Bridging-Header.h +5 -0
  27. package/ios/Theoplayer.xcodeproj/project.pbxproj +296 -0
  28. package/lib/commonjs/api/THEOplayerView.js +6 -0
  29. package/lib/commonjs/api/THEOplayerView.js.map +1 -0
  30. package/lib/commonjs/api/barrel.js +97 -0
  31. package/lib/commonjs/api/barrel.js.map +1 -0
  32. package/lib/commonjs/api/config/PlayerConfiguration.js +2 -0
  33. package/lib/commonjs/api/config/PlayerConfiguration.js.map +1 -0
  34. package/lib/commonjs/api/config/barrel.js +19 -0
  35. package/lib/commonjs/api/config/barrel.js.map +1 -0
  36. package/lib/commonjs/api/error/PlayerError.js +2 -0
  37. package/lib/commonjs/api/error/PlayerError.js.map +1 -0
  38. package/lib/commonjs/api/error/barrel.js +19 -0
  39. package/lib/commonjs/api/error/barrel.js.map +1 -0
  40. package/lib/commonjs/api/event/PlayerEvent.js +6 -0
  41. package/lib/commonjs/api/event/PlayerEvent.js.map +1 -0
  42. package/lib/commonjs/api/event/TrackEvent.js +22 -0
  43. package/lib/commonjs/api/event/TrackEvent.js.map +1 -0
  44. package/lib/commonjs/api/event/barrel.js +32 -0
  45. package/lib/commonjs/api/event/barrel.js.map +1 -0
  46. package/lib/commonjs/api/source/SourceDescription.js +6 -0
  47. package/lib/commonjs/api/source/SourceDescription.js.map +1 -0
  48. package/lib/commonjs/api/source/ads/Ads.js +2 -0
  49. package/lib/commonjs/api/source/ads/Ads.js.map +1 -0
  50. package/lib/commonjs/api/source/barrel.js +58 -0
  51. package/lib/commonjs/api/source/barrel.js.map +1 -0
  52. package/lib/commonjs/api/source/dash/DashPlaybackConfiguration.js +2 -0
  53. package/lib/commonjs/api/source/dash/DashPlaybackConfiguration.js.map +1 -0
  54. package/lib/commonjs/api/source/dash/barrel.js +19 -0
  55. package/lib/commonjs/api/source/dash/barrel.js.map +1 -0
  56. package/lib/commonjs/api/source/drm/DRMConfiguration.js +2 -0
  57. package/lib/commonjs/api/source/drm/DRMConfiguration.js.map +1 -0
  58. package/lib/commonjs/api/source/drm/barrel.js +19 -0
  59. package/lib/commonjs/api/source/drm/barrel.js.map +1 -0
  60. package/lib/commonjs/api/source/hls/HlsPlaybackConfiguration.js +2 -0
  61. package/lib/commonjs/api/source/hls/HlsPlaybackConfiguration.js.map +1 -0
  62. package/lib/commonjs/api/source/hls/barrel.js +19 -0
  63. package/lib/commonjs/api/source/hls/barrel.js.map +1 -0
  64. package/lib/commonjs/api/timeranges/TimeRange.js +2 -0
  65. package/lib/commonjs/api/timeranges/TimeRange.js.map +1 -0
  66. package/lib/commonjs/api/timeranges/barrel.js +19 -0
  67. package/lib/commonjs/api/timeranges/barrel.js.map +1 -0
  68. package/lib/commonjs/api/track/MediaTrack.js +6 -0
  69. package/lib/commonjs/api/track/MediaTrack.js.map +1 -0
  70. package/lib/commonjs/api/track/Quality.js +2 -0
  71. package/lib/commonjs/api/track/Quality.js.map +1 -0
  72. package/lib/commonjs/api/track/TextTrack.js +72 -0
  73. package/lib/commonjs/api/track/TextTrack.js.map +1 -0
  74. package/lib/commonjs/api/track/TextTrackCue.js +2 -0
  75. package/lib/commonjs/api/track/TextTrackCue.js.map +1 -0
  76. package/lib/commonjs/api/track/Track.js +2 -0
  77. package/lib/commonjs/api/track/Track.js.map +1 -0
  78. package/lib/commonjs/api/track/barrel.js +71 -0
  79. package/lib/commonjs/api/track/barrel.js.map +1 -0
  80. package/lib/commonjs/index.js +31 -0
  81. package/lib/commonjs/index.js.map +1 -0
  82. package/lib/commonjs/internal/THEOplayerView.js +274 -0
  83. package/lib/commonjs/internal/THEOplayerView.js.map +1 -0
  84. package/lib/commonjs/internal/THEOplayerView.style.js +22 -0
  85. package/lib/commonjs/internal/THEOplayerView.style.js.map +1 -0
  86. package/lib/commonjs/internal/THEOplayerView.web.js +512 -0
  87. package/lib/commonjs/internal/THEOplayerView.web.js.map +1 -0
  88. package/lib/commonjs/internal/web/TrackUtils.js +68 -0
  89. package/lib/commonjs/internal/web/TrackUtils.js.map +1 -0
  90. package/lib/module/api/THEOplayerView.js +2 -0
  91. package/lib/module/api/THEOplayerView.js.map +1 -0
  92. package/lib/module/api/barrel.js +8 -0
  93. package/lib/module/api/barrel.js.map +1 -0
  94. package/lib/module/api/config/PlayerConfiguration.js +2 -0
  95. package/lib/module/api/config/PlayerConfiguration.js.map +1 -0
  96. package/lib/module/api/config/barrel.js +2 -0
  97. package/lib/module/api/config/barrel.js.map +1 -0
  98. package/lib/module/api/error/PlayerError.js +2 -0
  99. package/lib/module/api/error/PlayerError.js.map +1 -0
  100. package/lib/module/api/error/barrel.js +2 -0
  101. package/lib/module/api/error/barrel.js.map +1 -0
  102. package/lib/module/api/event/PlayerEvent.js +2 -0
  103. package/lib/module/api/event/PlayerEvent.js.map +1 -0
  104. package/lib/module/api/event/TrackEvent.js +14 -0
  105. package/lib/module/api/event/TrackEvent.js.map +1 -0
  106. package/lib/module/api/event/barrel.js +3 -0
  107. package/lib/module/api/event/barrel.js.map +1 -0
  108. package/lib/module/api/source/SourceDescription.js +2 -0
  109. package/lib/module/api/source/SourceDescription.js.map +1 -0
  110. package/lib/module/api/source/ads/Ads.js +2 -0
  111. package/lib/module/api/source/ads/Ads.js.map +1 -0
  112. package/lib/module/api/source/barrel.js +5 -0
  113. package/lib/module/api/source/barrel.js.map +1 -0
  114. package/lib/module/api/source/dash/DashPlaybackConfiguration.js +2 -0
  115. package/lib/module/api/source/dash/DashPlaybackConfiguration.js.map +1 -0
  116. package/lib/module/api/source/dash/barrel.js +2 -0
  117. package/lib/module/api/source/dash/barrel.js.map +1 -0
  118. package/lib/module/api/source/drm/DRMConfiguration.js +2 -0
  119. package/lib/module/api/source/drm/DRMConfiguration.js.map +1 -0
  120. package/lib/module/api/source/drm/barrel.js +2 -0
  121. package/lib/module/api/source/drm/barrel.js.map +1 -0
  122. package/lib/module/api/source/hls/HlsPlaybackConfiguration.js +2 -0
  123. package/lib/module/api/source/hls/HlsPlaybackConfiguration.js.map +1 -0
  124. package/lib/module/api/source/hls/barrel.js +2 -0
  125. package/lib/module/api/source/hls/barrel.js.map +1 -0
  126. package/lib/module/api/timeranges/TimeRange.js +2 -0
  127. package/lib/module/api/timeranges/TimeRange.js.map +1 -0
  128. package/lib/module/api/timeranges/barrel.js +2 -0
  129. package/lib/module/api/timeranges/barrel.js.map +1 -0
  130. package/lib/module/api/track/MediaTrack.js +2 -0
  131. package/lib/module/api/track/MediaTrack.js.map +1 -0
  132. package/lib/module/api/track/Quality.js +2 -0
  133. package/lib/module/api/track/Quality.js.map +1 -0
  134. package/lib/module/api/track/TextTrack.js +47 -0
  135. package/lib/module/api/track/TextTrack.js.map +1 -0
  136. package/lib/module/api/track/TextTrackCue.js +2 -0
  137. package/lib/module/api/track/TextTrackCue.js.map +1 -0
  138. package/lib/module/api/track/Track.js +2 -0
  139. package/lib/module/api/track/Track.js.map +1 -0
  140. package/lib/module/api/track/barrel.js +6 -0
  141. package/lib/module/api/track/barrel.js.map +1 -0
  142. package/lib/module/index.js +3 -0
  143. package/lib/module/index.js.map +1 -0
  144. package/lib/module/internal/THEOplayerView.js +256 -0
  145. package/lib/module/internal/THEOplayerView.js.map +1 -0
  146. package/lib/module/internal/THEOplayerView.style.js +12 -0
  147. package/lib/module/internal/THEOplayerView.style.js.map +1 -0
  148. package/lib/module/internal/THEOplayerView.web.js +495 -0
  149. package/lib/module/internal/THEOplayerView.web.js.map +1 -0
  150. package/lib/module/internal/web/TrackUtils.js +57 -0
  151. package/lib/module/internal/web/TrackUtils.js.map +1 -0
  152. package/lib/typescript/babel.config.d.ts +1 -0
  153. package/lib/typescript/lib/commonjs/api/THEOplayerView.d.ts +1 -0
  154. package/lib/typescript/lib/commonjs/api/barrel.d.ts +1 -0
  155. package/lib/typescript/lib/commonjs/api/config/PlayerConfiguration.d.ts +0 -0
  156. package/lib/typescript/lib/commonjs/api/config/barrel.d.ts +1 -0
  157. package/lib/typescript/lib/commonjs/api/error/PlayerError.d.ts +0 -0
  158. package/lib/typescript/lib/commonjs/api/error/barrel.d.ts +1 -0
  159. package/lib/typescript/lib/commonjs/api/event/PlayerEvent.d.ts +1 -0
  160. package/lib/typescript/lib/commonjs/api/event/TrackEvent.d.ts +5 -0
  161. package/lib/typescript/lib/commonjs/api/event/barrel.d.ts +1 -0
  162. package/lib/typescript/lib/commonjs/api/source/SourceDescription.d.ts +1 -0
  163. package/lib/typescript/lib/commonjs/api/source/ads/Ads.d.ts +0 -0
  164. package/lib/typescript/lib/commonjs/api/source/barrel.d.ts +1 -0
  165. package/lib/typescript/lib/commonjs/api/source/dash/DashPlaybackConfiguration.d.ts +0 -0
  166. package/lib/typescript/lib/commonjs/api/source/dash/barrel.d.ts +1 -0
  167. package/lib/typescript/lib/commonjs/api/source/drm/DRMConfiguration.d.ts +0 -0
  168. package/lib/typescript/lib/commonjs/api/source/drm/barrel.d.ts +1 -0
  169. package/lib/typescript/lib/commonjs/api/source/hls/HlsPlaybackConfiguration.d.ts +0 -0
  170. package/lib/typescript/lib/commonjs/api/source/hls/barrel.d.ts +1 -0
  171. package/lib/typescript/lib/commonjs/api/timeranges/TimeRange.d.ts +0 -0
  172. package/lib/typescript/lib/commonjs/api/timeranges/barrel.d.ts +1 -0
  173. package/lib/typescript/lib/commonjs/api/track/MediaTrack.d.ts +1 -0
  174. package/lib/typescript/lib/commonjs/api/track/Quality.d.ts +0 -0
  175. package/lib/typescript/lib/commonjs/api/track/TextTrack.d.ts +21 -0
  176. package/lib/typescript/lib/commonjs/api/track/TextTrackCue.d.ts +0 -0
  177. package/lib/typescript/lib/commonjs/api/track/Track.d.ts +0 -0
  178. package/lib/typescript/lib/commonjs/api/track/barrel.d.ts +1 -0
  179. package/lib/typescript/lib/commonjs/index.d.ts +3 -0
  180. package/lib/typescript/lib/commonjs/internal/THEOplayerView.d.ts +14 -0
  181. package/lib/typescript/lib/commonjs/internal/THEOplayerView.style.d.ts +12 -0
  182. package/lib/typescript/lib/commonjs/internal/THEOplayerView.web.d.ts +17 -0
  183. package/lib/typescript/lib/commonjs/internal/web/TrackUtils.d.ts +30 -0
  184. package/lib/typescript/lib/module/api/THEOplayerView.d.ts +1 -0
  185. package/lib/typescript/lib/module/api/barrel.d.ts +7 -0
  186. package/lib/typescript/lib/module/api/config/PlayerConfiguration.d.ts +0 -0
  187. package/lib/typescript/lib/module/api/config/barrel.d.ts +1 -0
  188. package/lib/typescript/lib/module/api/error/PlayerError.d.ts +0 -0
  189. package/lib/typescript/lib/module/api/error/barrel.d.ts +1 -0
  190. package/lib/typescript/lib/module/api/event/PlayerEvent.d.ts +1 -0
  191. package/lib/typescript/lib/module/api/event/TrackEvent.d.ts +2 -0
  192. package/lib/typescript/lib/module/api/event/barrel.d.ts +2 -0
  193. package/lib/typescript/lib/module/api/source/SourceDescription.d.ts +1 -0
  194. package/lib/typescript/lib/module/api/source/ads/Ads.d.ts +0 -0
  195. package/lib/typescript/lib/module/api/source/barrel.d.ts +4 -0
  196. package/lib/typescript/lib/module/api/source/dash/DashPlaybackConfiguration.d.ts +0 -0
  197. package/lib/typescript/lib/module/api/source/dash/barrel.d.ts +1 -0
  198. package/lib/typescript/lib/module/api/source/drm/DRMConfiguration.d.ts +0 -0
  199. package/lib/typescript/lib/module/api/source/drm/barrel.d.ts +1 -0
  200. package/lib/typescript/lib/module/api/source/hls/HlsPlaybackConfiguration.d.ts +0 -0
  201. package/lib/typescript/lib/module/api/source/hls/barrel.d.ts +1 -0
  202. package/lib/typescript/lib/module/api/timeranges/TimeRange.d.ts +0 -0
  203. package/lib/typescript/lib/module/api/timeranges/barrel.d.ts +1 -0
  204. package/lib/typescript/lib/module/api/track/MediaTrack.d.ts +1 -0
  205. package/lib/typescript/lib/module/api/track/Quality.d.ts +0 -0
  206. package/lib/typescript/lib/module/api/track/TextTrack.d.ts +20 -0
  207. package/lib/typescript/lib/module/api/track/TextTrackCue.d.ts +0 -0
  208. package/lib/typescript/lib/module/api/track/Track.d.ts +0 -0
  209. package/lib/typescript/lib/module/api/track/barrel.d.ts +2 -0
  210. package/lib/typescript/lib/module/index.d.ts +2 -0
  211. package/lib/typescript/lib/module/internal/THEOplayerView.d.ts +9 -0
  212. package/lib/typescript/lib/module/internal/THEOplayerView.style.d.ts +11 -0
  213. package/lib/typescript/lib/module/internal/THEOplayerView.web.d.ts +10 -0
  214. package/lib/typescript/lib/module/internal/web/TrackUtils.d.ts +29 -0
  215. package/lib/typescript/src/api/THEOplayerView.d.ts +178 -0
  216. package/lib/typescript/src/api/barrel.d.ts +7 -0
  217. package/lib/typescript/src/api/config/PlayerConfiguration.d.ts +14 -0
  218. package/lib/typescript/src/api/config/barrel.d.ts +1 -0
  219. package/lib/typescript/src/api/error/PlayerError.d.ts +4 -0
  220. package/lib/typescript/src/api/error/barrel.d.ts +1 -0
  221. package/lib/typescript/src/api/event/PlayerEvent.d.ts +56 -0
  222. package/lib/typescript/src/api/event/TrackEvent.d.ts +46 -0
  223. package/lib/typescript/src/api/event/barrel.d.ts +2 -0
  224. package/lib/typescript/src/api/source/SourceDescription.d.ts +268 -0
  225. package/lib/typescript/src/api/source/ads/Ads.d.ts +94 -0
  226. package/lib/typescript/src/api/source/barrel.d.ts +4 -0
  227. package/lib/typescript/src/api/source/dash/DashPlaybackConfiguration.d.ts +44 -0
  228. package/lib/typescript/src/api/source/dash/barrel.d.ts +1 -0
  229. package/lib/typescript/src/api/source/drm/DRMConfiguration.d.ts +262 -0
  230. package/lib/typescript/src/api/source/drm/barrel.d.ts +1 -0
  231. package/lib/typescript/src/api/source/hls/HlsPlaybackConfiguration.d.ts +37 -0
  232. package/lib/typescript/src/api/source/hls/barrel.d.ts +1 -0
  233. package/lib/typescript/src/api/timeranges/TimeRange.d.ts +4 -0
  234. package/lib/typescript/src/api/timeranges/barrel.d.ts +1 -0
  235. package/lib/typescript/src/api/track/MediaTrack.d.ts +55 -0
  236. package/lib/typescript/src/api/track/Quality.d.ts +79 -0
  237. package/lib/typescript/src/api/track/TextTrack.d.ts +86 -0
  238. package/lib/typescript/src/api/track/TextTrackCue.d.ts +38 -0
  239. package/lib/typescript/src/api/track/Track.d.ts +43 -0
  240. package/lib/typescript/src/api/track/barrel.d.ts +5 -0
  241. package/lib/typescript/src/index.d.ts +2 -0
  242. package/lib/typescript/src/internal/THEOplayerView.d.ts +71 -0
  243. package/lib/typescript/src/internal/THEOplayerView.style.d.ts +11 -0
  244. package/lib/typescript/src/internal/THEOplayerView.web.d.ts +22 -0
  245. package/lib/typescript/src/internal/web/TrackUtils.d.ts +5 -0
  246. package/package.json +115 -9
  247. package/react-native-theoplayer.podspec +20 -0
  248. package/src/api/THEOplayerView.ts +221 -0
  249. package/src/api/barrel.ts +7 -0
  250. package/src/api/config/PlayerConfiguration.ts +16 -0
  251. package/src/api/config/barrel.ts +1 -0
  252. package/src/api/error/PlayerError.ts +4 -0
  253. package/src/api/error/barrel.ts +1 -0
  254. package/src/api/event/PlayerEvent.ts +66 -0
  255. package/src/api/event/TrackEvent.ts +55 -0
  256. package/src/api/event/barrel.ts +2 -0
  257. package/src/api/source/SourceDescription.ts +292 -0
  258. package/src/api/source/ads/Ads.ts +101 -0
  259. package/src/api/source/barrel.ts +4 -0
  260. package/src/api/source/dash/DashPlaybackConfiguration.ts +45 -0
  261. package/src/api/source/dash/barrel.ts +1 -0
  262. package/src/api/source/drm/DRMConfiguration.ts +287 -0
  263. package/src/api/source/drm/barrel.ts +1 -0
  264. package/src/api/source/hls/HlsPlaybackConfiguration.ts +38 -0
  265. package/src/api/source/hls/barrel.ts +1 -0
  266. package/src/api/timeranges/TimeRange.ts +5 -0
  267. package/src/api/timeranges/barrel.ts +1 -0
  268. package/src/api/track/MediaTrack.ts +65 -0
  269. package/src/api/track/Quality.ts +91 -0
  270. package/src/api/track/TextTrack.ts +133 -0
  271. package/src/api/track/TextTrackCue.ts +42 -0
  272. package/src/api/track/Track.ts +47 -0
  273. package/src/api/track/barrel.ts +5 -0
  274. package/src/index.tsx +2 -0
  275. package/src/internal/THEOplayerView.style.ts +12 -0
  276. package/src/internal/THEOplayerView.tsx +301 -0
  277. package/src/internal/THEOplayerView.web.tsx +399 -0
  278. package/src/internal/web/TrackUtils.ts +44 -0
  279. package/.gitattributes +0 -1
  280. package/index.js +0 -5
  281. package/ios/IOSNativeToast.h +0 -18
  282. package/ios/IOSNativeToast.m +0 -49
  283. package/ios/RNTheoplayer.h +0 -11
  284. package/ios/RNTheoplayer.m +0 -15
  285. package/ios/RNTheoplayer.podspec +0 -23
  286. package/ios/RNTheoplayer.xcodeproj/project.pbxproj +0 -417
  287. package/ios/RNTheoplayer.xcworkspace/contents.xcworkspacedata +0 -9
@@ -0,0 +1,420 @@
1
+ package com.theoplayer;
2
+
3
+ import android.annotation.SuppressLint;
4
+ import android.app.Activity;
5
+ import android.os.Build;
6
+ import android.os.Handler;
7
+ import android.util.Log;
8
+ import android.view.View;
9
+ import android.view.Window;
10
+ import android.widget.FrameLayout;
11
+
12
+ import androidx.annotation.NonNull;
13
+ import androidx.annotation.Nullable;
14
+
15
+ import com.facebook.react.bridge.Arguments;
16
+ import com.facebook.react.bridge.LifecycleEventListener;
17
+ import com.facebook.react.bridge.ReadableMap;
18
+ import com.facebook.react.bridge.WritableArray;
19
+ import com.facebook.react.bridge.WritableMap;
20
+ import com.facebook.react.uimanager.ThemedReactContext;
21
+ import com.theoplayer.android.api.THEOplayerConfig;
22
+ import com.theoplayer.android.api.THEOplayerView;
23
+ import com.theoplayer.android.api.ads.ima.GoogleImaIntegration;
24
+ import com.theoplayer.android.api.ads.ima.GoogleImaIntegrationFactory;
25
+ import com.theoplayer.android.api.player.Player;
26
+ import com.theoplayer.android.api.player.RequestCallback;
27
+ import com.theoplayer.android.api.player.track.mediatrack.MediaTrack;
28
+ import com.theoplayer.android.api.player.track.mediatrack.MediaTrackList;
29
+ import com.theoplayer.android.api.player.track.mediatrack.quality.AudioQuality;
30
+ import com.theoplayer.android.api.player.track.mediatrack.quality.VideoQuality;
31
+ import com.theoplayer.android.api.player.track.texttrack.TextTrack;
32
+ import com.theoplayer.android.api.player.track.texttrack.TextTrackList;
33
+ import com.theoplayer.android.api.player.track.texttrack.TextTrackMode;
34
+ import com.theoplayer.android.api.player.track.texttrack.cue.TextTrackCue;
35
+ import com.theoplayer.android.api.source.SourceDescription;
36
+ import com.theoplayer.android.api.timerange.TimeRanges;
37
+ import com.theoplayer.track.TrackListInfo;
38
+
39
+ @SuppressLint("ViewConstructor")
40
+ public class ReactTHEOplayerView extends FrameLayout implements LifecycleEventListener {
41
+
42
+ private static final String TAG = ReactTHEOplayerView.class.getName();
43
+
44
+ public static final long TIME_UNSET = Long.MIN_VALUE + 1;
45
+
46
+ private final VideoEventEmitter eventEmitter;
47
+
48
+ private final ThemedReactContext reactContext;
49
+
50
+ private THEOplayerView playerView;
51
+
52
+ private Player player;
53
+
54
+ private boolean paused;
55
+ private boolean muted = false;
56
+ private boolean fullscreen = false;
57
+ private double playbackRate = 1.0;
58
+ private double volume = 1.0;
59
+ private double seekTime = TIME_UNSET;
60
+ private SourceDescription sourceDescription;
61
+ private final Handler handler = new Handler();
62
+
63
+ public ReactTHEOplayerView(ThemedReactContext context) {
64
+ super(context);
65
+ this.reactContext = context;
66
+ this.eventEmitter = new VideoEventEmitter(context, this);
67
+ reactContext.addLifecycleEventListener(this);
68
+ }
69
+
70
+ public void initialize(@Nullable ReadableMap configProps) {
71
+ createViews(PlayerConfigHelper.fromProps(configProps));
72
+ }
73
+
74
+ @NonNull
75
+ public WritableArray getTextTrackInfo() {
76
+ if (player != null) {
77
+ return TrackListInfo.fromTextTrackList(player.getTextTracks());
78
+ }
79
+ return Arguments.createArray();
80
+ }
81
+
82
+ @NonNull
83
+ public WritableMap getTextTrackInfo(TextTrack track) {
84
+ if (player != null) {
85
+ return TrackListInfo.fromTextTrack(track);
86
+ }
87
+ return Arguments.createMap();
88
+ }
89
+
90
+ @NonNull
91
+ public WritableMap getTextTrackCueInfo(TextTrackCue cue) {
92
+ if (player != null) {
93
+ return TrackListInfo.fromTextTrackCue(cue);
94
+ }
95
+ return Arguments.createMap();
96
+ }
97
+
98
+ @NonNull
99
+ public WritableArray getAudioTrackInfo() {
100
+ if (player != null) {
101
+ return TrackListInfo.fromAudioTrackList(player.getAudioTracks());
102
+ }
103
+ return Arguments.createArray();
104
+ }
105
+
106
+ @NonNull
107
+ public WritableArray getVideoTrackInfo() {
108
+ if (player != null) {
109
+ return TrackListInfo.fromVideoTrackList(player.getVideoTracks());
110
+ }
111
+ return Arguments.createArray();
112
+ }
113
+
114
+ public double getDuration() {
115
+ return player != null? 1e03 * player.getDuration() : Double.NaN;
116
+ }
117
+
118
+ public void getSeekableRange(RequestCallback<TimeRanges> callback) {
119
+ if (player != null) {
120
+ player.requestSeekable(callback);
121
+ } else {
122
+ callback.handleResult(null);
123
+ }
124
+ }
125
+
126
+ public void getBufferedRange(RequestCallback<TimeRanges> callback) {
127
+ if (player != null) {
128
+ player.requestBuffered(callback);
129
+ } else {
130
+ callback.handleResult(null);
131
+ }
132
+ }
133
+
134
+ @Override
135
+ public void setId(int id) {
136
+ super.setId(id);
137
+ eventEmitter.setViewId(id);
138
+ }
139
+
140
+ private void createViews(@NonNull THEOplayerConfig playerConfig) {
141
+ if (BuildConfig.LOG_VIEW_EVENTS) {
142
+ Log.d(TAG, "Create views");
143
+ }
144
+
145
+ LayoutParams layoutParams = new LayoutParams(
146
+ LayoutParams.MATCH_PARENT,
147
+ LayoutParams.MATCH_PARENT);
148
+
149
+ playerView = new THEOplayerView(reactContext.getCurrentActivity(), playerConfig) {
150
+ private void measureAndLayout() {
151
+ measure(
152
+ View.MeasureSpec.makeMeasureSpec(getMeasuredWidth(), View.MeasureSpec.EXACTLY),
153
+ View.MeasureSpec.makeMeasureSpec(getMeasuredHeight(), View.MeasureSpec.EXACTLY));
154
+ layout(getLeft(), getTop(), getRight(), getBottom());
155
+ }
156
+
157
+ @Override
158
+ public void requestLayout() {
159
+ super.requestLayout();
160
+
161
+ // schedule a forced layout
162
+ handler.post(this::measureAndLayout);
163
+ }
164
+ };
165
+ playerView.setLayoutParams(layoutParams);
166
+
167
+ addView(playerView, 0, layoutParams);
168
+ addIntegrations(playerView);
169
+ }
170
+
171
+ private void addIntegrations(@NonNull final THEOplayerView playerView) {
172
+ GoogleImaIntegration googleImaIntegration = GoogleImaIntegrationFactory.createGoogleImaIntegration(playerView);
173
+ playerView.getPlayer().addIntegration(googleImaIntegration);
174
+ // Add other future integrations here.
175
+ }
176
+
177
+ @Override
178
+ protected void onAttachedToWindow() {
179
+ if (BuildConfig.LOG_VIEW_EVENTS) {
180
+ Log.d(TAG, "onAttachedToWindow");
181
+ }
182
+ super.onAttachedToWindow();
183
+ initializePlayer();
184
+ }
185
+
186
+ @Override
187
+ protected void onDetachedFromWindow() {
188
+ if (BuildConfig.LOG_VIEW_EVENTS) {
189
+ Log.d(TAG, "onDetachedFromWindow");
190
+ }
191
+ super.onDetachedFromWindow();
192
+ /* We want to be able to continue playing audio when switching tabs.
193
+ * Leave this here in case it causes issues.
194
+ */
195
+ // stopPlayback();
196
+ }
197
+
198
+ private void initializePlayer() {
199
+ // This ensures all props have been settled, to avoid async racing conditions.
200
+ new Handler().postDelayed(() -> {
201
+ if (player == null) {
202
+ player = playerView.getPlayer();
203
+ eventEmitter.attachListeners(player);
204
+ player.setMuted(this.muted);
205
+ player.setVolume(this.volume);
206
+ player.setPlaybackRate(this.playbackRate);
207
+ player.setSource(this.sourceDescription);
208
+
209
+ if (!this.paused) {
210
+ player.play();
211
+ }
212
+
213
+ seekTo(this.seekTime);
214
+ }
215
+ }, 1);
216
+ }
217
+
218
+ @Override
219
+ public void onHostResume() {
220
+ if (BuildConfig.LOG_VIEW_EVENTS) {
221
+ Log.d(TAG, "onHostResume");
222
+ }
223
+ if (playerView != null) {
224
+ playerView.onResume();
225
+ }
226
+ }
227
+
228
+ @Override
229
+ public void onHostPause() {
230
+ if (BuildConfig.LOG_VIEW_EVENTS) {
231
+ Log.d(TAG, "onHostPause");
232
+ }
233
+ if (playerView != null) {
234
+ playerView.onPause();
235
+ }
236
+ }
237
+
238
+ @Override
239
+ public void onHostDestroy() {
240
+ if (BuildConfig.LOG_VIEW_EVENTS) {
241
+ Log.d(TAG, "onHostDestroy");
242
+ }
243
+ stopPlayback();
244
+ if (playerView != null) {
245
+ playerView.onDestroy();
246
+ }
247
+ }
248
+
249
+ public void cleanUpResources() {
250
+ if (BuildConfig.LOG_VIEW_EVENTS) {
251
+ Log.d(TAG, "cleanUpResources");
252
+ }
253
+ stopPlayback();
254
+ }
255
+
256
+ private void stopPlayback() {
257
+ releasePlayer();
258
+ }
259
+
260
+ private void releasePlayer() {
261
+ if (player != null) {
262
+ eventEmitter.removeListeners(player);
263
+ player.stop();
264
+ player = null;
265
+ }
266
+ reactContext.removeLifecycleEventListener(this);
267
+ }
268
+
269
+ public void setSource(@Nullable final SourceDescription sourceDescription) {
270
+ this.sourceDescription = sourceDescription;
271
+ if (player != null && sourceDescription != null) {
272
+ player.setSource(sourceDescription);
273
+ }
274
+ }
275
+
276
+ public void setPaused(boolean paused) {
277
+ this.paused = paused;
278
+ if (player != null) {
279
+ final boolean playerIsPaused = player.isPaused();
280
+ if (!paused && playerIsPaused) {
281
+ player.play();
282
+ } else if (paused && !playerIsPaused) {
283
+ player.pause();
284
+ }
285
+ }
286
+ }
287
+
288
+ public void setMuted(boolean muted) {
289
+ this.muted = muted;
290
+ if (player != null) {
291
+ player.setMuted(muted);
292
+ }
293
+ }
294
+
295
+ public void setVolume(double volume) {
296
+ this.volume = volume;
297
+ if (player != null) {
298
+ player.setVolume(volume);
299
+ }
300
+ }
301
+
302
+ public void setPlaybackRate(double playbackRate) {
303
+ this.playbackRate = playbackRate;
304
+ if (player != null) {
305
+ player.setPlaybackRate(playbackRate);
306
+ }
307
+ }
308
+
309
+ public void seekTo(double seekTime) {
310
+ this.seekTime = seekTime;
311
+ if (player != null) {
312
+ player.setCurrentTime(1e-03 * seekTime);
313
+ this.seekTime = TIME_UNSET;
314
+ }
315
+ }
316
+
317
+ @Nullable
318
+ public TextTrack getSelectedTextTrack() {
319
+ if (player != null) {
320
+ final TextTrackList tracks = player.getTextTracks();
321
+ for (int i = 0; i < tracks.length(); i++) {
322
+ final TextTrack track = tracks.getItem(i);
323
+ if (track.getMode() == TextTrackMode.SHOWING) {
324
+ return track;
325
+ }
326
+ }
327
+ }
328
+ return null;
329
+ }
330
+
331
+ public void setSelectedTextTrack(int uid) {
332
+ if (player != null) {
333
+ for (final TextTrack track: player.getTextTracks()) {
334
+ if (track.getUid() == uid) {
335
+ track.setMode(TextTrackMode.SHOWING);
336
+ } else {
337
+ track.setMode(TextTrackMode.HIDDEN);
338
+ }
339
+ }
340
+ }
341
+ }
342
+
343
+ @Nullable
344
+ public MediaTrack<AudioQuality> getSelectedAudioTrack() {
345
+ if (player != null) {
346
+ final MediaTrackList<AudioQuality> tracks = player.getAudioTracks();
347
+ for (int i = 0; i < tracks.length(); i++) {
348
+ final MediaTrack<AudioQuality> track = tracks.getItem(i);
349
+ if (track.isEnabled()) {
350
+ return track;
351
+ }
352
+ }
353
+ }
354
+ return null;
355
+ }
356
+
357
+ public void setSelectedAudioTrack(int uid) {
358
+ if (player != null) {
359
+ for (final MediaTrack<AudioQuality> track: player.getAudioTracks()) {
360
+ track.setEnabled(track.getUid() == uid);
361
+ }
362
+ }
363
+ }
364
+
365
+ @Nullable
366
+ public MediaTrack<VideoQuality> getSelectedVideoTrack() {
367
+ if (player != null) {
368
+ final MediaTrackList<VideoQuality> tracks = player.getVideoTracks();
369
+ for (int i = 0; i < tracks.length(); i++) {
370
+ final MediaTrack<VideoQuality> track = tracks.getItem(i);
371
+ if (track.isEnabled()) {
372
+ return track;
373
+ }
374
+ }
375
+ }
376
+ return null;
377
+ }
378
+
379
+ public void setSelectedVideoTrack(int uid) {
380
+ if (player != null) {
381
+ for (final MediaTrack<VideoQuality> track: player.getVideoTracks()) {
382
+ track.setEnabled(track.getUid() == uid);
383
+ }
384
+ }
385
+ }
386
+
387
+ @SuppressLint("ObsoleteSdkInt")
388
+ public void setFullscreen(boolean fullscreen) {
389
+ if (fullscreen == this.fullscreen) {
390
+ return; // Avoid generating events when nothing is changing
391
+ }
392
+ this.fullscreen = fullscreen;
393
+
394
+ Activity activity = reactContext.getCurrentActivity();
395
+ if (activity == null) {
396
+ return;
397
+ }
398
+ Window window = activity.getWindow();
399
+ View decorView = window.getDecorView();
400
+ int uiOptions;
401
+ if (fullscreen) {
402
+ if (Build.VERSION.SDK_INT >= 19) { // 4.4+
403
+ uiOptions = SYSTEM_UI_FLAG_HIDE_NAVIGATION
404
+ | SYSTEM_UI_FLAG_IMMERSIVE_STICKY
405
+ | SYSTEM_UI_FLAG_FULLSCREEN;
406
+ } else {
407
+ uiOptions = SYSTEM_UI_FLAG_HIDE_NAVIGATION
408
+ | SYSTEM_UI_FLAG_FULLSCREEN;
409
+ }
410
+ eventEmitter.onFullscreenWillPresent();
411
+ decorView.setSystemUiVisibility(uiOptions);
412
+ eventEmitter.onFullscreenDidPresent();
413
+ } else {
414
+ uiOptions = View.SYSTEM_UI_FLAG_VISIBLE;
415
+ eventEmitter.onFullscreenWillDismiss();
416
+ decorView.setSystemUiVisibility(uiOptions);
417
+ eventEmitter.onFullscreenDidDismiss();
418
+ }
419
+ }
420
+ }
@@ -0,0 +1,114 @@
1
+ package com.theoplayer;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import androidx.annotation.Nullable;
5
+
6
+ import com.facebook.react.bridge.ReadableMap;
7
+ import com.facebook.react.common.MapBuilder;
8
+ import com.facebook.react.uimanager.ThemedReactContext;
9
+ import com.facebook.react.uimanager.ViewGroupManager;
10
+ import com.facebook.react.uimanager.annotations.ReactProp;
11
+
12
+ import java.util.Map;
13
+
14
+ public class ReactTHEOplayerViewManager extends ViewGroupManager<ReactTHEOplayerView> {
15
+ public static final String REACT_CLASS = "THEOplayerRCTView";
16
+
17
+ private static final String PROP_CONFIG = "config";
18
+ private static final String PROP_SRC = "src";
19
+ private static final String PROP_SEEK = "seek";
20
+ private static final String PROP_PAUSED = "paused";
21
+ private static final String PROP_MUTED = "muted";
22
+ private static final String PROP_VOLUME = "volume";
23
+ private static final String PROP_PLAYBACKRATE = "playbackRate";
24
+ private static final String PROP_FULLSCREEN = "fullscreen";
25
+ private static final String PROP_SELECTED_TEXTTRACK = "selectedTextTrack";
26
+ private static final String PROP_SELECTED_AUDIOTRACK = "selectedAudioTrack";
27
+ private static final String PROP_SELECTED_VIDEOTRACK = "selectedVideoTrack";
28
+
29
+ @Override
30
+ @NonNull
31
+ public String getName() {
32
+ return REACT_CLASS;
33
+ }
34
+
35
+ @NonNull
36
+ @Override
37
+ protected ReactTHEOplayerView createViewInstance(@NonNull ThemedReactContext reactContext) {
38
+ return new ReactTHEOplayerView(reactContext);
39
+ }
40
+
41
+ @Override
42
+ public void onDropViewInstance(ReactTHEOplayerView view) {
43
+ view.cleanUpResources();
44
+ }
45
+
46
+ @ReactProp(name = PROP_CONFIG)
47
+ public void setConfig(final ReactTHEOplayerView videoView, @Nullable ReadableMap config) {
48
+ videoView.initialize(config);
49
+ }
50
+
51
+ @ReactProp(name = PROP_SRC)
52
+ public void setSource(final ReactTHEOplayerView videoView, @Nullable ReadableMap src) {
53
+ videoView.setSource(new SourceHelper().parseSourceFromJS(src));
54
+ }
55
+
56
+ @ReactProp(name = PROP_SEEK)
57
+ public void setSeek(final ReactTHEOplayerView videoView, final double seek) {
58
+ videoView.seekTo(seek);
59
+ }
60
+
61
+ @ReactProp(name = PROP_PAUSED, defaultBoolean = false)
62
+ public void setPaused(final ReactTHEOplayerView videoView, final boolean paused) {
63
+ videoView.setPaused(paused);
64
+ }
65
+
66
+ @ReactProp(name = PROP_MUTED, defaultBoolean = false)
67
+ public void setMuted(final ReactTHEOplayerView videoView, final boolean muted) {
68
+ videoView.setMuted(muted);
69
+ }
70
+
71
+ @ReactProp(name = PROP_VOLUME, defaultDouble = 1.0)
72
+ public void setVolume(final ReactTHEOplayerView videoView, final double volume) {
73
+ videoView.setVolume(volume);
74
+ }
75
+
76
+ @ReactProp(name = PROP_PLAYBACKRATE, defaultDouble = 1.0)
77
+ public void setPlaybackRate(final ReactTHEOplayerView videoView, final double playbackRate) {
78
+ videoView.setPlaybackRate(playbackRate);
79
+ }
80
+
81
+ @ReactProp(name = PROP_FULLSCREEN, defaultBoolean = false)
82
+ public void setFullscreen(final ReactTHEOplayerView videoView, final boolean fullscreen) {
83
+ videoView.setFullscreen(fullscreen);
84
+ }
85
+
86
+ @ReactProp(name = PROP_SELECTED_TEXTTRACK, defaultInt = -1)
87
+ public void setSelectedTextTrack(final ReactTHEOplayerView videoView, final int uid) {
88
+ videoView.setSelectedTextTrack(uid);
89
+ }
90
+
91
+ @ReactProp(name = PROP_SELECTED_AUDIOTRACK, defaultInt = -1)
92
+ public void setSelectedAudioTrack(final ReactTHEOplayerView videoView, final int uid) {
93
+ if (uid != -1) {
94
+ videoView.setSelectedAudioTrack(uid);
95
+ }
96
+ }
97
+
98
+ @ReactProp(name = PROP_SELECTED_VIDEOTRACK, defaultInt = -1)
99
+ public void setSelectedVideoTrack(final ReactTHEOplayerView videoView, final int uid) {
100
+ if (uid != -1) {
101
+ videoView.setSelectedVideoTrack(uid);
102
+ }
103
+ }
104
+
105
+ @Override
106
+ public @Nullable
107
+ Map<String, Object> getExportedCustomDirectEventTypeConstants() {
108
+ MapBuilder.Builder<String, Object> builder = MapBuilder.builder();
109
+ for (String event : VideoEventEmitter.Events) {
110
+ builder.put(event, MapBuilder.of("registrationName", event));
111
+ }
112
+ return builder.build();
113
+ }
114
+ }