@javascriptcommon/react-native-track-player 1.2.23 → 4.1.5

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 (507) hide show
  1. package/LICENSE +201 -21
  2. package/README.md +8 -0
  3. package/android/build.gradle +80 -63
  4. package/android/proguard-rules.txt +0 -3
  5. package/android/src/main/AndroidManifest.xml +10 -11
  6. package/android/src/main/java/com/doublesymmetry/trackplayer/HeadlessJsMediaService.kt +199 -0
  7. package/android/src/main/java/com/doublesymmetry/trackplayer/TrackPlayer.kt +33 -0
  8. package/android/src/main/java/com/{guichaguri → doublesymmetry}/trackplayer/extensions/AudioPlayerStateExt.kt +3 -3
  9. package/android/src/main/java/com/doublesymmetry/trackplayer/extensions/EnumExtensions.kt +5 -0
  10. package/android/src/main/java/com/doublesymmetry/trackplayer/extensions/NumberExt.kt +13 -0
  11. package/android/src/main/java/com/{guichaguri → doublesymmetry}/trackplayer/model/MetadataAdapter.kt +20 -17
  12. package/android/src/main/java/com/doublesymmetry/trackplayer/model/NowPlayingMetadata.kt +16 -0
  13. package/android/src/main/java/com/{guichaguri/trackplayer/kotlinaudio/models → doublesymmetry/trackplayer/model}/PlaybackMetadata.kt +31 -28
  14. package/android/src/main/java/com/{guichaguri → doublesymmetry}/trackplayer/model/State.kt +1 -1
  15. package/android/src/main/java/com/doublesymmetry/trackplayer/model/Track.kt +67 -0
  16. package/android/src/main/java/com/doublesymmetry/trackplayer/model/TrackAudioItem.kt +18 -0
  17. package/android/src/main/java/com/doublesymmetry/trackplayer/model/TrackMetadata.kt +38 -0
  18. package/android/src/main/java/com/{guichaguri → doublesymmetry}/trackplayer/module/MusicEvents.kt +10 -9
  19. package/android/src/main/java/com/doublesymmetry/trackplayer/module/MusicModule.kt +778 -0
  20. package/android/src/main/java/com/doublesymmetry/trackplayer/service/MusicService.kt +1286 -0
  21. package/android/src/main/java/com/doublesymmetry/trackplayer/utils/AppForegroundTracker.kt +35 -0
  22. package/android/src/main/java/com/{guichaguri/trackplayer/service → doublesymmetry/trackplayer/utils}/BundleUtils.kt +50 -20
  23. package/android/src/main/java/com/doublesymmetry/trackplayer/utils/CoilBitmapLoader.kt +65 -0
  24. package/android/src/main/java/com/doublesymmetry/trackplayer/utils/MediaItemBuilder.kt +41 -0
  25. package/android/src/main/java/com/doublesymmetry/trackplayer/utils/RejectionException.kt +11 -0
  26. package/android/src/main/java/com/doublesymmetry/trackplayer/video/TrackPlayerVideoView.kt +42 -0
  27. package/android/src/main/java/com/doublesymmetry/trackplayer/video/TrackPlayerVideoViewManager.kt +18 -0
  28. package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/event/EventHolder.kt +7 -7
  29. package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/event/PlayerEventHolder.kt +22 -9
  30. package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/models/AudioContentType.kt +1 -1
  31. package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/AudioItem.kt +118 -0
  32. package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/models/AudioItemTransitionReason.kt +3 -3
  33. package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/models/AudioPlayerState.kt +2 -2
  34. package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/models/BufferConfig.kt +1 -1
  35. package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/models/CacheConfig.kt +1 -1
  36. package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/models/Capability.kt +1 -1
  37. package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/CustomButton.kt +19 -0
  38. package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/models/FocusChangeData.kt +1 -1
  39. package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/models/MediaSessionCallback.kt +1 -1
  40. package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/models/PlayWhenReadyChangeData.kt +1 -3
  41. package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/models/PlaybackEndedReason.kt +1 -1
  42. package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/models/PlaybackError.kt +1 -1
  43. package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/models/PlayerConfig.kt +8 -5
  44. package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/PlayerOptions.kt +40 -0
  45. package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/models/PositionChangedReason.kt +1 -1
  46. package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/RepeatMode.kt +16 -0
  47. package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/WakeMode.kt +7 -0
  48. package/android/src/main/java/com/lovegaoshi/kotlinaudio/player/AudioPlayer.kt +756 -0
  49. package/android/src/main/java/com/lovegaoshi/kotlinaudio/player/ForwardingPlayer.java +1124 -0
  50. package/android/src/main/java/com/{guichaguri/trackplayer/kotlinaudio/players → lovegaoshi/kotlinaudio/player}/QueuedAudioPlayer.kt +68 -58
  51. package/android/src/main/java/com/lovegaoshi/kotlinaudio/player/components/APMRenderersFactory.kt +33 -0
  52. package/android/src/main/java/com/lovegaoshi/kotlinaudio/player/components/Buffer.kt +34 -0
  53. package/android/src/main/java/com/lovegaoshi/kotlinaudio/player/components/Cache.kt +27 -0
  54. package/android/src/main/java/com/lovegaoshi/kotlinaudio/player/components/FocusManager.kt +59 -0
  55. package/android/src/main/java/com/lovegaoshi/kotlinaudio/player/components/MediaFactory.kt +130 -0
  56. package/android/src/main/java/com/lovegaoshi/kotlinaudio/processors/TeeListener.kt +171 -0
  57. package/android/src/main/java/com/lovegaoshi/kotlinaudio/service/MusicService.kt +127 -0
  58. package/android/src/main/java/com/lovegaoshi/kotlinaudio/utils/FFT.java +99 -0
  59. package/android/src/main/java/com/lovegaoshi/kotlinaudio/utils/Utils.kt +113 -0
  60. package/android/src/main/res/drawable/baseline_repeat_24.xml +5 -0
  61. package/android/src/main/res/drawable/baseline_repeat_one_24.xml +5 -0
  62. package/android/src/main/res/drawable/forward.xml +5 -0
  63. package/android/src/main/res/drawable/heart_24px.xml +5 -0
  64. package/android/src/main/res/drawable/hearte_24px.xml +5 -0
  65. package/android/src/main/res/drawable/ifl_24px.xml +5 -0
  66. package/android/src/main/res/drawable/rewind.xml +5 -0
  67. package/android/src/main/res/drawable/shuffle_24px.xml +5 -0
  68. package/android/src/main/res/values/strings.xml +3 -4
  69. package/android/src/main/res/xml/automotive_app_desc.xml +3 -0
  70. package/ios/Example/SwiftAudio/Assets.xcassets/22AMI.imageset/22AMillion.jpg +0 -0
  71. package/ios/Example/SwiftAudio/Assets.xcassets/22AMI.imageset/Contents.json +21 -0
  72. package/ios/Example/SwiftAudio/Assets.xcassets/AccentColor.colorset/Contents.json +11 -0
  73. package/ios/Example/SwiftAudio/Assets.xcassets/AppIcon.appiconset/Contents.json +58 -0
  74. package/ios/Example/SwiftAudio/Assets.xcassets/Contents.json +6 -0
  75. package/ios/Example/SwiftAudio/Assets.xcassets/cover.imageset/Contents.json +21 -0
  76. package/ios/Example/SwiftAudio/Assets.xcassets/cover.imageset/cover.jpg +0 -0
  77. package/ios/Example/SwiftAudio/AudioController.swift +46 -0
  78. package/ios/Example/SwiftAudio/Extensions.swift +22 -0
  79. package/ios/Example/SwiftAudio/PlayerView.swift +172 -0
  80. package/ios/Example/SwiftAudio/PlayerViewModel.swift +120 -0
  81. package/ios/Example/SwiftAudio/Preview Content/Preview Assets.xcassets/Contents.json +6 -0
  82. package/ios/Example/SwiftAudio/QueueView.swift +65 -0
  83. package/ios/{TrackPlayer.xcodeproj/xcuserdata/marco.xcuserdatad/xcschemes/xcschememanagement.plist → Example/SwiftAudio/SwiftAudio.entitlements} +6 -8
  84. package/ios/Example/SwiftAudio/SwiftAudioApp.swift +17 -0
  85. package/ios/Example/SwiftAudio.xcodeproj/project.pbxproj +412 -0
  86. package/ios/{TrackPlayer.xcodeproj → Example/SwiftAudio.xcodeproj}/project.xcworkspace/contents.xcworkspacedata +1 -1
  87. package/ios/RNTrackPlayer/Models/Capabilities.swift +39 -4
  88. package/ios/RNTrackPlayer/Models/MediaURL.swift +12 -6
  89. package/ios/RNTrackPlayer/Models/MetadataAdapter.swift +147 -0
  90. package/ios/RNTrackPlayer/Models/PitchAlgorithms.swift +13 -0
  91. package/ios/RNTrackPlayer/Models/SessionCategories.swift +106 -0
  92. package/ios/RNTrackPlayer/Models/State.swift +26 -0
  93. package/ios/RNTrackPlayer/Models/Track.swift +74 -54
  94. package/ios/RNTrackPlayer/RNTrackPlayer.swift +867 -406
  95. package/ios/RNTrackPlayer/Support/RNTrackPlayer-Bridging-Header.h +1 -0
  96. package/ios/RNTrackPlayer/TrackPlayer.h +14 -0
  97. package/ios/RNTrackPlayer/TrackPlayer.mm +249 -0
  98. package/ios/RNTrackPlayer/Utils/EventType.swift +45 -0
  99. package/ios/RNTrackPlayer/Utils/Metadata.swift +60 -0
  100. package/ios/RNTrackPlayer/Video/RNTrackPlayerVideoView.swift +83 -0
  101. package/ios/RNTrackPlayer/Video/RNTrackPlayerVideoViewManager.m +5 -0
  102. package/ios/RNTrackPlayer/Video/RNTrackPlayerVideoViewManager.swift +17 -0
  103. package/ios/SwiftAudioEx/Package.swift +20 -0
  104. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/AVPlayerWrapper/AVPlayerWrapper.swift +531 -0
  105. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/AVPlayerWrapper/AVPlayerWrapperDelegate.swift +27 -0
  106. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/AVPlayerWrapper/AVPlayerWrapperProtocol.swift +69 -0
  107. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/AVPlayerWrapper/AVPlayerWrapperState.swift +43 -0
  108. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/AudioItem.swift +158 -0
  109. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/AudioPlayer.swift +459 -0
  110. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/AudioPlayerError.swift +26 -0
  111. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/AudioSessionController/AudioSession.swift +33 -0
  112. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/AudioSessionController/AudioSessionController.swift +135 -0
  113. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/AudioTap.swift +96 -0
  114. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/Event.swift +155 -0
  115. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/NowPlayingInfoController/MediaItemProperty.swift +95 -0
  116. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/NowPlayingInfoController/NowPlayingInfoCenter.swift +17 -0
  117. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/NowPlayingInfoController/NowPlayingInfoController.swift +73 -0
  118. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/NowPlayingInfoController/NowPlayingInfoControllerProtocol.swift +26 -0
  119. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/NowPlayingInfoController/NowPlayingInfoKeyValue.swift +14 -0
  120. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/NowPlayingInfoController/NowPlayingInfoProperty.swift +234 -0
  121. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/Observer/AVPlayerItemNotificationObserver.swift +102 -0
  122. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/Observer/AVPlayerItemObserver.swift +136 -0
  123. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/Observer/AVPlayerObserver.swift +120 -0
  124. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/Observer/AVPlayerTimeObserver.swift +112 -0
  125. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/QueueManager.swift +356 -0
  126. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/QueuedAudioPlayer.swift +236 -0
  127. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/RemoteCommandController/RemoteCommand.swift +170 -0
  128. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/RemoteCommandController/RemoteCommandController.swift +206 -0
  129. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/RepeatMode.swift +15 -0
  130. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/TimeEventFrequency.swift +26 -0
  131. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/Utils/DispatchQueueType.swift +18 -0
  132. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/WaveformAudioTap.swift +159 -0
  133. package/lib/specs/NativeTrackPlayer.d.ts +134 -0
  134. package/lib/specs/NativeTrackPlayer.js +4 -0
  135. package/lib/src/TrackPlayerModule.web.d.ts +2 -0
  136. package/lib/src/TrackPlayerModule.web.js +2 -0
  137. package/lib/src/VideoView.d.ts +16 -0
  138. package/lib/src/VideoView.js +25 -0
  139. package/lib/src/constants/AndroidAudioContentType.d.ts +35 -0
  140. package/lib/src/constants/AndroidAudioContentType.js +36 -0
  141. package/lib/src/constants/AndroidAutoContentStyle.d.ts +10 -0
  142. package/lib/src/constants/AndroidAutoContentStyle.js +11 -0
  143. package/lib/src/constants/AppKilledPlaybackBehavior.d.ts +17 -0
  144. package/lib/src/constants/AppKilledPlaybackBehavior.js +18 -0
  145. package/lib/src/constants/Capability.d.ts +17 -0
  146. package/lib/src/constants/Capability.js +19 -0
  147. package/lib/src/constants/Event.d.ts +172 -0
  148. package/lib/src/constants/Event.js +173 -0
  149. package/lib/src/constants/IOSCategory.d.ts +36 -0
  150. package/lib/src/constants/IOSCategory.js +37 -0
  151. package/lib/src/constants/IOSCategoryMode.d.ts +47 -0
  152. package/lib/src/constants/IOSCategoryMode.js +48 -0
  153. package/lib/src/constants/IOSCategoryOptions.d.ts +44 -0
  154. package/lib/src/constants/IOSCategoryOptions.js +45 -0
  155. package/lib/src/constants/MediaItemPlayable.d.ts +4 -0
  156. package/lib/src/constants/MediaItemPlayable.js +5 -0
  157. package/lib/src/constants/PitchAlgorithm.d.ts +14 -0
  158. package/lib/src/constants/PitchAlgorithm.js +16 -0
  159. package/lib/src/constants/RatingType.d.ts +8 -0
  160. package/lib/src/constants/RatingType.js +10 -0
  161. package/lib/src/constants/RepeatMode.d.ts +8 -0
  162. package/lib/src/constants/RepeatMode.js +10 -0
  163. package/lib/src/constants/State.d.ts +34 -0
  164. package/lib/src/constants/State.js +35 -0
  165. package/lib/src/constants/TrackType.d.ts +6 -0
  166. package/lib/src/constants/TrackType.js +7 -0
  167. package/lib/src/constants/index.d.ts +14 -0
  168. package/lib/src/constants/index.js +14 -0
  169. package/lib/src/hooks/index.d.ts +6 -0
  170. package/lib/src/hooks/index.js +6 -0
  171. package/lib/src/hooks/useActiveTrack.d.ts +2 -0
  172. package/lib/src/hooks/useActiveTrack.js +28 -0
  173. package/lib/src/hooks/useAppIsInBackground.d.ts +1 -0
  174. package/lib/src/hooks/useAppIsInBackground.js +16 -0
  175. package/lib/src/hooks/useIsPlaying.d.ts +35 -0
  176. package/lib/src/hooks/useIsPlaying.js +50 -0
  177. package/lib/src/hooks/usePlayWhenReady.d.ts +1 -0
  178. package/lib/src/hooks/usePlayWhenReady.js +27 -0
  179. package/lib/src/hooks/usePlaybackState.d.ts +10 -0
  180. package/lib/src/hooks/usePlaybackState.js +35 -0
  181. package/lib/src/hooks/useProgress.d.ts +7 -0
  182. package/lib/src/hooks/useProgress.js +55 -0
  183. package/lib/src/hooks/useTrackPlayerEvents.d.ts +8 -0
  184. package/lib/src/hooks/useTrackPlayerEvents.js +30 -0
  185. package/lib/src/index.d.ts +6 -0
  186. package/lib/src/index.js +6 -0
  187. package/lib/src/interfaces/AndroidAutoBrowseTree.d.ts +5 -0
  188. package/lib/src/interfaces/AndroidAutoBrowseTree.js +1 -0
  189. package/lib/src/interfaces/AndroidOptions.d.ts +41 -0
  190. package/lib/src/interfaces/AndroidOptions.js +1 -0
  191. package/lib/src/interfaces/CustomButtons.d.ts +5 -0
  192. package/lib/src/interfaces/CustomButtons.js +1 -0
  193. package/lib/src/interfaces/FeedbackOptions.d.ts +6 -0
  194. package/lib/src/interfaces/FeedbackOptions.js +1 -0
  195. package/lib/src/interfaces/MediaItem.d.ts +18 -0
  196. package/lib/src/interfaces/MediaItem.js +1 -0
  197. package/lib/src/interfaces/MetadataOptions.d.ts +3 -0
  198. package/lib/src/interfaces/MetadataOptions.js +1 -0
  199. package/lib/src/interfaces/NowPlayingMetadata.d.ts +4 -0
  200. package/lib/src/interfaces/NowPlayingMetadata.js +1 -0
  201. package/lib/src/interfaces/PlaybackState.d.ts +8 -0
  202. package/lib/src/interfaces/PlaybackState.js +1 -0
  203. package/lib/src/interfaces/PlayerOptions.d.ts +132 -0
  204. package/lib/src/interfaces/PlayerOptions.js +1 -0
  205. package/lib/src/interfaces/Progress.d.ts +15 -0
  206. package/lib/src/interfaces/Progress.js +1 -0
  207. package/lib/src/interfaces/ResourceObject.d.ts +1 -0
  208. package/lib/src/interfaces/ResourceObject.js +1 -0
  209. package/lib/src/interfaces/ServiceHandler.d.ts +1 -0
  210. package/lib/src/interfaces/ServiceHandler.js +1 -0
  211. package/lib/src/interfaces/Track.d.ts +21 -0
  212. package/lib/src/interfaces/Track.js +1 -0
  213. package/lib/src/interfaces/TrackMetadataBase.d.ts +28 -0
  214. package/lib/src/interfaces/TrackMetadataBase.js +1 -0
  215. package/lib/src/interfaces/UpdateOptions.d.ts +52 -0
  216. package/lib/src/interfaces/UpdateOptions.js +1 -0
  217. package/lib/src/interfaces/events/AudioMetadataReceivedEvent.d.ts +33 -0
  218. package/lib/src/interfaces/events/AudioMetadataReceivedEvent.js +1 -0
  219. package/lib/src/interfaces/events/ControllerConnectedEvent.d.ts +8 -0
  220. package/lib/src/interfaces/events/ControllerConnectedEvent.js +1 -0
  221. package/lib/src/interfaces/events/EventPayloadByEvent.d.ts +77 -0
  222. package/lib/src/interfaces/events/EventPayloadByEvent.js +1 -0
  223. package/lib/src/interfaces/events/FFTUpdateEvent.d.ts +7 -0
  224. package/lib/src/interfaces/events/FFTUpdateEvent.js +1 -0
  225. package/lib/src/interfaces/events/PlaybackActiveTrackChangedEvent.d.ts +24 -0
  226. package/lib/src/interfaces/events/PlaybackActiveTrackChangedEvent.js +1 -0
  227. package/lib/src/interfaces/events/PlaybackAnimatedVolumeChangedEvent.d.ts +4 -0
  228. package/lib/src/interfaces/events/PlaybackAnimatedVolumeChangedEvent.js +1 -0
  229. package/lib/src/interfaces/events/PlaybackErrorEvent.d.ts +6 -0
  230. package/lib/src/interfaces/events/PlaybackErrorEvent.js +1 -0
  231. package/lib/src/interfaces/events/PlaybackMetadataReceivedEvent.d.ts +16 -0
  232. package/lib/src/interfaces/events/PlaybackMetadataReceivedEvent.js +1 -0
  233. package/lib/src/interfaces/events/PlaybackPlayWhenReadyChangedEvent.d.ts +4 -0
  234. package/lib/src/interfaces/events/PlaybackPlayWhenReadyChangedEvent.js +1 -0
  235. package/lib/src/interfaces/events/PlaybackProgressUpdatedEvent.d.ts +4 -0
  236. package/lib/src/interfaces/events/PlaybackProgressUpdatedEvent.js +1 -0
  237. package/lib/src/interfaces/events/PlaybackQueueEndedEvent.d.ts +9 -0
  238. package/lib/src/interfaces/events/PlaybackQueueEndedEvent.js +1 -0
  239. package/lib/src/interfaces/events/PlaybackResumeEvent.d.ts +3 -0
  240. package/lib/src/interfaces/events/PlaybackResumeEvent.js +1 -0
  241. package/lib/src/interfaces/events/PlaybackTrackChangedEvent.d.ts +11 -0
  242. package/lib/src/interfaces/events/PlaybackTrackChangedEvent.js +1 -0
  243. package/lib/src/interfaces/events/PlayerErrorEvent.d.ts +6 -0
  244. package/lib/src/interfaces/events/PlayerErrorEvent.js +1 -0
  245. package/lib/src/interfaces/events/RemoteBrowseEvent.d.ts +4 -0
  246. package/lib/src/interfaces/events/RemoteBrowseEvent.js +1 -0
  247. package/lib/src/interfaces/events/RemoteCustomActionEvent.d.ts +7 -0
  248. package/lib/src/interfaces/events/RemoteCustomActionEvent.js +1 -0
  249. package/lib/src/interfaces/events/RemoteDuckEvent.d.ts +13 -0
  250. package/lib/src/interfaces/events/RemoteDuckEvent.js +1 -0
  251. package/lib/src/interfaces/events/RemoteJumpBackwardEvent.d.ts +7 -0
  252. package/lib/src/interfaces/events/RemoteJumpBackwardEvent.js +1 -0
  253. package/lib/src/interfaces/events/RemoteJumpForwardEvent.d.ts +7 -0
  254. package/lib/src/interfaces/events/RemoteJumpForwardEvent.js +1 -0
  255. package/lib/src/interfaces/events/RemotePlayIdEvent.d.ts +4 -0
  256. package/lib/src/interfaces/events/RemotePlayIdEvent.js +1 -0
  257. package/lib/src/interfaces/events/RemotePlaySearchEvent.d.ts +9 -0
  258. package/lib/src/interfaces/events/RemotePlaySearchEvent.js +1 -0
  259. package/lib/src/interfaces/events/RemoteSearchEvent.d.ts +3 -0
  260. package/lib/src/interfaces/events/RemoteSearchEvent.js +1 -0
  261. package/lib/src/interfaces/events/RemoteSeekEvent.d.ts +4 -0
  262. package/lib/src/interfaces/events/RemoteSeekEvent.js +1 -0
  263. package/lib/src/interfaces/events/RemoteSetRatingEvent.d.ts +4 -0
  264. package/lib/src/interfaces/events/RemoteSetRatingEvent.js +1 -0
  265. package/lib/src/interfaces/events/RemoteSkipEvent.d.ts +3 -0
  266. package/lib/src/interfaces/events/RemoteSkipEvent.js +1 -0
  267. package/lib/src/interfaces/events/index.d.ts +20 -0
  268. package/lib/src/interfaces/events/index.js +20 -0
  269. package/lib/src/interfaces/index.d.ts +15 -0
  270. package/lib/src/interfaces/index.js +15 -0
  271. package/lib/src/resolveAssetSource.d.ts +2 -0
  272. package/lib/src/resolveAssetSource.js +3 -0
  273. package/lib/src/resolveAssetSource.web.d.ts +2 -0
  274. package/lib/src/resolveAssetSource.web.js +8 -0
  275. package/lib/src/trackPlayer.d.ts +371 -0
  276. package/lib/src/trackPlayer.js +627 -0
  277. package/lib/web/TrackPlayer/Player.d.ts +40 -0
  278. package/lib/web/TrackPlayer/Player.js +188 -0
  279. package/lib/web/TrackPlayer/PlaylistPlayer.d.ts +31 -0
  280. package/lib/web/TrackPlayer/PlaylistPlayer.js +181 -0
  281. package/lib/web/TrackPlayer/RepeatMode.d.ts +5 -0
  282. package/lib/web/TrackPlayer/RepeatMode.js +6 -0
  283. package/lib/web/TrackPlayer/SetupNotCalledError.d.ts +3 -0
  284. package/lib/web/TrackPlayer/SetupNotCalledError.js +5 -0
  285. package/lib/web/TrackPlayer/index.d.ts +3 -0
  286. package/lib/web/TrackPlayer/index.js +3 -0
  287. package/lib/web/TrackPlayerModule.d.ts +63 -0
  288. package/lib/web/TrackPlayerModule.js +153 -0
  289. package/lib/web/index.d.ts +3 -0
  290. package/lib/web/index.js +3 -0
  291. package/package.json +85 -6
  292. package/react-native-track-player.podspec +13 -13
  293. package/specs/NativeTrackPlayer.ts +153 -0
  294. package/src/TrackPlayerModule.web.ts +2 -0
  295. package/src/VideoView.tsx +51 -0
  296. package/src/constants/AndroidAudioContentType.ts +35 -0
  297. package/src/constants/AndroidAutoContentStyle.ts +10 -0
  298. package/src/constants/AppKilledPlaybackBehavior.ts +19 -0
  299. package/src/constants/Capability.ts +19 -0
  300. package/src/constants/Event.ts +173 -0
  301. package/src/constants/IOSCategory.ts +36 -0
  302. package/src/constants/IOSCategoryMode.ts +47 -0
  303. package/src/constants/IOSCategoryOptions.ts +44 -0
  304. package/src/constants/MediaItemPlayable.ts +4 -0
  305. package/src/constants/PitchAlgorithm.ts +16 -0
  306. package/src/constants/RatingType.ts +10 -0
  307. package/src/constants/RepeatMode.ts +10 -0
  308. package/src/constants/State.ts +34 -0
  309. package/src/constants/TrackType.ts +6 -0
  310. package/src/constants/index.ts +14 -0
  311. package/src/hooks/index.ts +6 -0
  312. package/src/hooks/useActiveTrack.ts +36 -0
  313. package/src/hooks/useAppIsInBackground.ts +20 -0
  314. package/src/hooks/useIsPlaying.ts +56 -0
  315. package/src/hooks/usePlayWhenReady.ts +37 -0
  316. package/src/hooks/usePlaybackState.ts +45 -0
  317. package/src/hooks/useProgress.ts +64 -0
  318. package/src/hooks/useTrackPlayerEvents.ts +48 -0
  319. package/src/index.ts +8 -0
  320. package/src/interfaces/AndroidAutoBrowseTree.ts +6 -0
  321. package/src/interfaces/AndroidOptions.ts +48 -0
  322. package/src/interfaces/CustomButtons.ts +6 -0
  323. package/src/interfaces/FeedbackOptions.ts +7 -0
  324. package/src/interfaces/MediaItem.ts +19 -0
  325. package/src/interfaces/MetadataOptions.ts +4 -0
  326. package/src/interfaces/NowPlayingMetadata.ts +5 -0
  327. package/src/interfaces/PlaybackState.ts +11 -0
  328. package/src/interfaces/PlayerOptions.ts +138 -0
  329. package/src/interfaces/Progress.ts +15 -0
  330. package/src/interfaces/ResourceObject.ts +1 -0
  331. package/src/interfaces/ServiceHandler.ts +1 -0
  332. package/src/interfaces/Track.ts +23 -0
  333. package/src/interfaces/TrackMetadataBase.ts +29 -0
  334. package/src/interfaces/UpdateOptions.ts +59 -0
  335. package/src/interfaces/events/AudioMetadataReceivedEvent.ts +37 -0
  336. package/src/interfaces/events/ControllerConnectedEvent.ts +9 -0
  337. package/src/interfaces/events/EventPayloadByEvent.ts +80 -0
  338. package/src/interfaces/events/FFTUpdateEvent.ts +9 -0
  339. package/src/interfaces/events/PlaybackActiveTrackChangedEvent.ts +29 -0
  340. package/src/interfaces/events/PlaybackAnimatedVolumeChangedEvent.ts +4 -0
  341. package/src/interfaces/events/PlaybackErrorEvent.ts +6 -0
  342. package/src/interfaces/events/PlaybackMetadataReceivedEvent.ts +16 -0
  343. package/src/interfaces/events/PlaybackPlayWhenReadyChangedEvent.ts +4 -0
  344. package/src/interfaces/events/PlaybackProgressUpdatedEvent.ts +5 -0
  345. package/src/interfaces/events/PlaybackQueueEndedEvent.ts +9 -0
  346. package/src/interfaces/events/PlaybackResumeEvent.ts +5 -0
  347. package/src/interfaces/events/PlaybackTrackChangedEvent.ts +11 -0
  348. package/src/interfaces/events/PlayerErrorEvent.ts +6 -0
  349. package/src/interfaces/events/RemoteBrowseEvent.ts +4 -0
  350. package/src/interfaces/events/RemoteCustomActionEvent.ts +7 -0
  351. package/src/interfaces/events/RemoteDuckEvent.ts +13 -0
  352. package/src/interfaces/events/RemoteJumpBackwardEvent.ts +7 -0
  353. package/src/interfaces/events/RemoteJumpForwardEvent.ts +7 -0
  354. package/src/interfaces/events/RemotePlayIdEvent.ts +4 -0
  355. package/src/interfaces/events/RemotePlaySearchEvent.ts +21 -0
  356. package/src/interfaces/events/RemoteSearchEvent.ts +3 -0
  357. package/src/interfaces/events/RemoteSeekEvent.ts +4 -0
  358. package/src/interfaces/events/RemoteSetRatingEvent.ts +5 -0
  359. package/src/interfaces/events/RemoteSkipEvent.ts +3 -0
  360. package/src/interfaces/events/index.ts +20 -0
  361. package/src/interfaces/index.ts +15 -0
  362. package/src/resolveAssetSource.ts +3 -0
  363. package/src/resolveAssetSource.web.ts +10 -0
  364. package/src/trackPlayer.ts +806 -0
  365. package/web/TrackPlayer/Player.ts +201 -0
  366. package/web/TrackPlayer/PlaylistPlayer.ts +215 -0
  367. package/web/TrackPlayer/RepeatMode.ts +6 -0
  368. package/web/TrackPlayer/SetupNotCalledError.ts +5 -0
  369. package/web/TrackPlayer/index.ts +3 -0
  370. package/web/TrackPlayerModule.ts +181 -0
  371. package/web/index.ts +4 -0
  372. package/CHANGELOG.md +0 -75
  373. package/android/react-native-music-control.iml +0 -139
  374. package/android/react-native-track-player.iml +0 -151
  375. package/android/src/main/ic_home-playstore.png +0 -0
  376. package/android/src/main/ic_repeat-playstore.png +0 -0
  377. package/android/src/main/ic_repeat_50-playstore.png +0 -0
  378. package/android/src/main/ic_shuffle-playstore.png +0 -0
  379. package/android/src/main/ic_shuffle_50-playstore.png +0 -0
  380. package/android/src/main/ic_shuffle_sm-playstore.png +0 -0
  381. package/android/src/main/ic_stop-playstore.png +0 -0
  382. package/android/src/main/ic_test-playstore.png +0 -0
  383. package/android/src/main/java/com/guichaguri/trackplayer/HeadlessJsMediaService.java +0 -225
  384. package/android/src/main/java/com/guichaguri/trackplayer/TrackPlayer.kt +0 -25
  385. package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/event/NotificationEventHolder.kt +0 -20
  386. package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/models/AAMediaSessionCallback.kt +0 -10
  387. package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/models/AudioItem.kt +0 -66
  388. package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/models/NotificationConfig.kt +0 -43
  389. package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/models/NotificationMetadata.kt +0 -8
  390. package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/models/NotificationState.kt +0 -8
  391. package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/models/PlayerOptions.kt +0 -9
  392. package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/models/QueuedPlayerOptions.kt +0 -49
  393. package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/notification/NotificationManager.kt +0 -678
  394. package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/players/AudioPlayer.kt +0 -10
  395. package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/players/BaseAudioPlayer.kt +0 -864
  396. package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/players/components/MediaSourceExt.kt +0 -35
  397. package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/players/components/PlayerCache.kt +0 -26
  398. package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/utils/Utils.kt +0 -12
  399. package/android/src/main/java/com/guichaguri/trackplayer/model/Track.kt +0 -120
  400. package/android/src/main/java/com/guichaguri/trackplayer/model/TrackAudioItem.kt +0 -19
  401. package/android/src/main/java/com/guichaguri/trackplayer/model/TrackType.kt +0 -11
  402. package/android/src/main/java/com/guichaguri/trackplayer/module/AutoConnectionDetector.kt +0 -151
  403. package/android/src/main/java/com/guichaguri/trackplayer/module/MusicModule.kt +0 -1177
  404. package/android/src/main/java/com/guichaguri/trackplayer/service/MusicBinder.kt +0 -31
  405. package/android/src/main/java/com/guichaguri/trackplayer/service/MusicManager.kt +0 -347
  406. package/android/src/main/java/com/guichaguri/trackplayer/service/MusicService.kt +0 -1254
  407. package/android/src/main/java/com/guichaguri/trackplayer/service/Utils.kt +0 -228
  408. package/android/src/main/java/com/guichaguri/trackplayer/service/metadata/ButtonEvents.kt +0 -141
  409. package/android/src/main/java/com/guichaguri/trackplayer/service/metadata/MetadataManager.kt +0 -396
  410. package/android/src/main/res/drawable-hdpi/ic_forward.png +0 -0
  411. package/android/src/main/res/drawable-hdpi/ic_home.png +0 -0
  412. package/android/src/main/res/drawable-hdpi/ic_next.png +0 -0
  413. package/android/src/main/res/drawable-hdpi/ic_pause.png +0 -0
  414. package/android/src/main/res/drawable-hdpi/ic_play.png +0 -0
  415. package/android/src/main/res/drawable-hdpi/ic_previous.png +0 -0
  416. package/android/src/main/res/drawable-hdpi/ic_rewind.png +0 -0
  417. package/android/src/main/res/drawable-hdpi/ic_stop.png +0 -0
  418. package/android/src/main/res/drawable-mdpi/ic_forward.png +0 -0
  419. package/android/src/main/res/drawable-mdpi/ic_home.png +0 -0
  420. package/android/src/main/res/drawable-mdpi/ic_next.png +0 -0
  421. package/android/src/main/res/drawable-mdpi/ic_pause.png +0 -0
  422. package/android/src/main/res/drawable-mdpi/ic_play.png +0 -0
  423. package/android/src/main/res/drawable-mdpi/ic_previous.png +0 -0
  424. package/android/src/main/res/drawable-mdpi/ic_rewind.png +0 -0
  425. package/android/src/main/res/drawable-mdpi/ic_stop.png +0 -0
  426. package/android/src/main/res/drawable-xhdpi/ic_forward.png +0 -0
  427. package/android/src/main/res/drawable-xhdpi/ic_home.png +0 -0
  428. package/android/src/main/res/drawable-xhdpi/ic_next.png +0 -0
  429. package/android/src/main/res/drawable-xhdpi/ic_pause.png +0 -0
  430. package/android/src/main/res/drawable-xhdpi/ic_play.png +0 -0
  431. package/android/src/main/res/drawable-xhdpi/ic_previous.png +0 -0
  432. package/android/src/main/res/drawable-xhdpi/ic_rewind.png +0 -0
  433. package/android/src/main/res/drawable-xhdpi/ic_stop.png +0 -0
  434. package/android/src/main/res/drawable-xxhdpi/ic_forward.png +0 -0
  435. package/android/src/main/res/drawable-xxhdpi/ic_home.png +0 -0
  436. package/android/src/main/res/drawable-xxhdpi/ic_next.png +0 -0
  437. package/android/src/main/res/drawable-xxhdpi/ic_pause.png +0 -0
  438. package/android/src/main/res/drawable-xxhdpi/ic_play.png +0 -0
  439. package/android/src/main/res/drawable-xxhdpi/ic_previous.png +0 -0
  440. package/android/src/main/res/drawable-xxhdpi/ic_rewind.png +0 -0
  441. package/android/src/main/res/drawable-xxhdpi/ic_stop.png +0 -0
  442. package/android/src/main/res/drawable-xxxhdpi/ic_forward.png +0 -0
  443. package/android/src/main/res/drawable-xxxhdpi/ic_home.png +0 -0
  444. package/android/src/main/res/drawable-xxxhdpi/ic_next.png +0 -0
  445. package/android/src/main/res/drawable-xxxhdpi/ic_pause.png +0 -0
  446. package/android/src/main/res/drawable-xxxhdpi/ic_play.png +0 -0
  447. package/android/src/main/res/drawable-xxxhdpi/ic_previous.png +0 -0
  448. package/android/src/main/res/drawable-xxxhdpi/ic_rewind.png +0 -0
  449. package/android/src/main/res/drawable-xxxhdpi/ic_stop.png +0 -0
  450. package/android/src/main/res/mipmap-hdpi/ic_arrow_down_circle_foreground.png +0 -0
  451. package/android/src/main/res/mipmap-hdpi/ic_clock_now_foreground.png +0 -0
  452. package/android/src/main/res/mipmap-hdpi/ic_close_foreground.png +0 -0
  453. package/android/src/main/res/mipmap-hdpi/ic_heart_foreground.png +0 -0
  454. package/android/src/main/res/mipmap-hdpi/ic_heart_outlined_foreground.png +0 -0
  455. package/android/src/main/res/mipmap-hdpi/ic_repeat_off_foreground.png +0 -0
  456. package/android/src/main/res/mipmap-hdpi/ic_repeat_on_foreground.png +0 -0
  457. package/android/src/main/res/mipmap-hdpi/ic_shuffle_off_foreground.png +0 -0
  458. package/android/src/main/res/mipmap-hdpi/ic_shuffle_on_foreground.png +0 -0
  459. package/android/src/main/res/mipmap-mdpi/ic_arrow_down_circle_foreground.png +0 -0
  460. package/android/src/main/res/mipmap-mdpi/ic_clock_now_foreground.png +0 -0
  461. package/android/src/main/res/mipmap-mdpi/ic_close_foreground.png +0 -0
  462. package/android/src/main/res/mipmap-mdpi/ic_heart_foreground.png +0 -0
  463. package/android/src/main/res/mipmap-mdpi/ic_heart_outlined_foreground.png +0 -0
  464. package/android/src/main/res/mipmap-mdpi/ic_repeat_off_foreground.png +0 -0
  465. package/android/src/main/res/mipmap-mdpi/ic_repeat_on_foreground.png +0 -0
  466. package/android/src/main/res/mipmap-mdpi/ic_shuffle_off_foreground.png +0 -0
  467. package/android/src/main/res/mipmap-mdpi/ic_shuffle_on_foreground.png +0 -0
  468. package/android/src/main/res/mipmap-xhdpi/ic_arrow_down_circle_foreground.png +0 -0
  469. package/android/src/main/res/mipmap-xhdpi/ic_clock_now_foreground.png +0 -0
  470. package/android/src/main/res/mipmap-xhdpi/ic_close_foreground.png +0 -0
  471. package/android/src/main/res/mipmap-xhdpi/ic_heart_foreground.png +0 -0
  472. package/android/src/main/res/mipmap-xhdpi/ic_heart_outlined_foreground.png +0 -0
  473. package/android/src/main/res/mipmap-xhdpi/ic_repeat_off_foreground.png +0 -0
  474. package/android/src/main/res/mipmap-xhdpi/ic_repeat_on_foreground.png +0 -0
  475. package/android/src/main/res/mipmap-xhdpi/ic_shuffle_off_foreground.png +0 -0
  476. package/android/src/main/res/mipmap-xhdpi/ic_shuffle_on_foreground.png +0 -0
  477. package/android/src/main/res/mipmap-xxhdpi/ic_arrow_down_circle_foreground.png +0 -0
  478. package/android/src/main/res/mipmap-xxhdpi/ic_clock_now_foreground.png +0 -0
  479. package/android/src/main/res/mipmap-xxhdpi/ic_close_foreground.png +0 -0
  480. package/android/src/main/res/mipmap-xxhdpi/ic_heart_foreground.png +0 -0
  481. package/android/src/main/res/mipmap-xxhdpi/ic_heart_outlined_foreground.png +0 -0
  482. package/android/src/main/res/mipmap-xxhdpi/ic_repeat_off_foreground.png +0 -0
  483. package/android/src/main/res/mipmap-xxhdpi/ic_repeat_on_foreground.png +0 -0
  484. package/android/src/main/res/mipmap-xxhdpi/ic_shuffle_off_foreground.png +0 -0
  485. package/android/src/main/res/mipmap-xxhdpi/ic_shuffle_on_foreground.png +0 -0
  486. package/android/src/main/res/mipmap-xxxhdpi/ic_arrow_down_circle_foreground.png +0 -0
  487. package/android/src/main/res/mipmap-xxxhdpi/ic_clock_now_foreground.png +0 -0
  488. package/android/src/main/res/mipmap-xxxhdpi/ic_close_foreground.png +0 -0
  489. package/android/src/main/res/mipmap-xxxhdpi/ic_heart_foreground.png +0 -0
  490. package/android/src/main/res/mipmap-xxxhdpi/ic_heart_outlined_foreground.png +0 -0
  491. package/android/src/main/res/mipmap-xxxhdpi/ic_repeat_off_foreground.png +0 -0
  492. package/android/src/main/res/mipmap-xxxhdpi/ic_repeat_on_foreground.png +0 -0
  493. package/android/src/main/res/mipmap-xxxhdpi/ic_shuffle_off_foreground.png +0 -0
  494. package/android/src/main/res/mipmap-xxxhdpi/ic_shuffle_on_foreground.png +0 -0
  495. package/android/src/main/res/raw/silent_5_seconds.mp3 +0 -0
  496. package/android/src/main/res/strings.xml +0 -6
  497. package/index.d.ts +0 -235
  498. package/index.js +0 -4
  499. package/ios/RNTrackPlayer/RNTrackPlayerBridge.h +0 -12
  500. package/ios/RNTrackPlayer/RNTrackPlayerBridge.m +0 -29
  501. package/ios/TrackPlayer.xcodeproj/project.pbxproj +0 -495
  502. package/ios/TrackPlayer.xcodeproj/project.xcworkspace/xcuserdata/marco.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  503. package/lib/ProgressComponent.js +0 -70
  504. package/lib/eventTypes.js +0 -28
  505. package/lib/hooks.js +0 -160
  506. package/lib/index.js +0 -178
  507. /package/ios/{TrackPlayer.xcodeproj → Example/SwiftAudio.xcodeproj}/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -0
package/LICENSE CHANGED
@@ -1,21 +1,201 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2016 Tanguy Antoine
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,8 @@
1
+ [![Android compile check](https://github.com/lovegaoshi/react-native-track-player/actions/workflows/compile-check.yml/badge.svg)](https://github.com/lovegaoshi/react-native-track-player/actions/workflows/compile-check.yml)
2
+
3
+
4
+ Please note this is a personal fork of [RNTP](https://github.com/doublesymmetry/react-native-track-player) for [APM](https://github.com/lovegaoshi/azusa-player-mobile)'s development. Its forked out of upstream because RNTP unfortunately was on a development hiatus and the community has been quiet for a very long time, while the entire react native community [1](https://github.com/evergrace-co/react-native-audio-pro),[2](https://docs.expo.dev/versions/latest/sdk/audio/) does NOT have anything better for audio playback. Many of the features APM uses, such as crossfade and Android Auto capabilities, were NOT merged upstream, unlikely to be merged in the foreseeable future, and won't be seen elsewhere either.
5
+
6
+ Functionalities used by APM [passes the play store review](https://play.google.com/store/apps/details?id=com.noxplay.noxplayer&pcampaignid=pcampaignidMKT-Other-global-all-co-prtnr-py-PartBadge-Mar2515-1).
7
+
8
+ This fork and APM proudly remains open-source and APM is published under GPLv3. As this fork is specifically developed for APM, contributions are welcome but changes modifying any APM features will NOT be accepted. For feature usages it's encouraged to look at the example app and APM. For library usages it's recommend to FORK yourself and modify any APM specific features and resources as needed.
@@ -1,91 +1,108 @@
1
+ import com.android.Version
2
+
1
3
  buildscript {
4
+ ext.getExtOrDefault = {name ->
5
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['TrackPlayer_' + name]
6
+ }
7
+
2
8
  repositories {
3
- mavenLocal()
4
- mavenCentral()
5
9
  google()
10
+ mavenCentral()
6
11
  }
7
12
  dependencies {
8
- classpath 'com.android.tools.build:gradle:7.4.2'
13
+ classpath 'com.android.tools.build:gradle:8.8.2'
9
14
  classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.10"
10
15
  }
11
16
  }
12
17
 
13
18
  apply plugin: 'com.android.library'
14
- apply plugin: 'org.jetbrains.kotlin.android'
19
+ apply plugin: 'kotlin-android'
15
20
 
16
- def safeExtGet(prop, fallback) {
17
- rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
21
+ if (!rootProject.ext.has("native")) {
22
+ apply plugin: 'com.facebook.react'
23
+ }
24
+
25
+ def getExtOrIntegerDefault(name, defaultInt) {
26
+ try {
27
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['RNTP_' + name]).toInteger()
28
+ } catch (ignored) {
29
+ return defaultInt
30
+ }
18
31
  }
19
32
 
20
33
  android {
21
- compileSdkVersion safeExtGet('compileSdkVersion', 28)
22
- buildToolsVersion safeExtGet('buildToolsVersion', '28.0.3')
34
+ compileSdkVersion getExtOrIntegerDefault('compileSdkVersion', 35)
23
35
 
24
- compileOptions {
25
- targetCompatibility JavaVersion.VERSION_1_8
26
- sourceCompatibility JavaVersion.VERSION_1_8
36
+ def agpVersion = Version.ANDROID_GRADLE_PLUGIN_VERSION
37
+ if (agpVersion.tokenize('.')[0].toInteger() >= 7) {
38
+ namespace "com.doublesymmetry.trackplayer"
27
39
  }
28
-
29
- def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
30
40
  defaultConfig {
31
- minSdkVersion safeExtGet('minSdkVersion', 16)
32
- targetSdkVersion safeExtGet('targetSdkVersion', 28)
33
- versionCode 1
34
- versionName "1.0"
35
- }
36
- }
41
+ minSdkVersion getExtOrIntegerDefault('minSdkVersion', 23) // RN's minimum version
42
+ targetSdkVersion getExtOrIntegerDefault('targetSdkVersion', 34)
37
43
 
38
- dependencies {
39
44
 
40
- // All support libs must use the same version
41
- implementation 'androidx.work:work-runtime:2.7.1'
42
- implementation "androidx.localbroadcastmanager:localbroadcastmanager:1.1.0"
43
- implementation "com.github.bumptech.glide:glide:4.13.2"
45
+ consumerProguardFiles 'proguard-rules.txt'
46
+ }
44
47
 
45
- // implementation 'com.github.lovegaoshi:KotlinAudio:v2.0.0-rc7-podverse-13'
48
+ compileOptions {
49
+ sourceCompatibility JavaVersion.VERSION_1_8
50
+ targetCompatibility JavaVersion.VERSION_1_8
51
+ }
52
+ if (rootProject.ext.has("native")) {
53
+ kotlinOptions {
54
+ // HACK: does RN auto sets to 17? or am i crazy?
55
+ jvmTarget = "1.8"
56
+ }
57
+ }
58
+ }
46
59
 
60
+ repositories {
61
+ mavenLocal()
62
+ maven {
63
+ // As RN is not updated in jcenter anymore, we'll have to grab it from npm
64
+ // Make sure you have installed the react-native npm package before compiling
65
+ url '../node_modules/react-native/android'
66
+ }
47
67
 
48
- implementation "com.facebook.react:react-native:+"
68
+ mavenCentral()
69
+ google()
70
+ }
49
71
 
72
+ dependencies {
73
+ //noinspection GradleDynamicVersion
74
+ if (rootProject.ext.has("native")) {
75
+ implementation "com.facebook.react:react-android:+"
76
+ } else {
77
+ implementation "com.facebook.react:react-native:+"
78
+ }
50
79
  // Make sure we're using androidx
51
- implementation "androidx.core:core-ktx:1.7.0"
80
+ implementation "androidx.core:core-ktx:1.16.0"
52
81
  implementation "androidx.localbroadcastmanager:localbroadcastmanager:1.1.0"
53
- implementation "androidx.lifecycle:lifecycle-process:2.6.1"
54
- implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.3"
55
- implementation 'androidx.media:media:1.6.0'
56
-
57
-
58
-
59
-
60
- implementation "androidx.car.app:app:1.4.0"
61
-
62
-
63
- implementation 'io.coil-kt:coil:1.4.0'
64
- implementation 'androidx.media:media:1.6.0'
65
- api 'com.google.android.exoplayer:exoplayer:2.18.1'
66
- api 'com.google.android.exoplayer:extension-mediasession:2.18.1'
82
+ implementation "androidx.lifecycle:lifecycle-process:2.9.2"
83
+ implementation 'androidx.media:media:1.7.0'
84
+
85
+ implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.9.2")
86
+ implementation("androidx.activity:activity-compose:1.10.1")
87
+ implementation("androidx.compose.ui:ui:1.8.3")
88
+ implementation("androidx.compose.ui:ui-graphics:1.8.3")
89
+
90
+ implementation("androidx.media3:media3-exoplayer:1.8.0")
91
+ implementation("androidx.media3:media3-session:1.8.0")
92
+ implementation("androidx.media3:media3-ui:1.8.0")
93
+ implementation("androidx.media3:media3-exoplayer-hls:1.8.0")
94
+ implementation("androidx.media3:media3-exoplayer-dash:1.8.0")
95
+ implementation("androidx.media3:media3-exoplayer-smoothstreaming:1.8.0")
96
+ implementation("androidx.media3:media3-common:1.8.0")
97
+ implementation("org.jellyfin.media3:media3-ffmpeg-decoder:1.8.0+1")
98
+
99
+ implementation "com.google.guava:guava:33.4.8-android"
100
+ implementation "org.jetbrains.kotlinx:kotlinx-coroutines-guava:1.10.2"
101
+ implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2"
102
+
103
+ implementation 'io.coil-kt:coil:2.7.0'
67
104
  api 'com.jakewharton.timber:timber:5.0.1'
68
105
 
69
- implementation 'androidx.test:rules:1.4.0'
70
-
71
- // Asynchronous Testing
72
- androidTestImplementation('org.awaitility:awaitility:4.2.0') {
73
- transitive = false
74
- }
75
- androidTestImplementation('org.awaitility:awaitility-kotlin:4.2.0') {
76
- transitive = false
77
- }
78
-
79
- // (Required) Writing and executing Unit Tests on the JUnit Platform
80
- androidTestImplementation("androidx.test:runner:1.4.0")
81
- androidTestImplementation("org.junit.jupiter:junit-jupiter-api:5.8.2")
82
- testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.2")
83
-
84
- // (Optional) If you need "Parameterized Tests"
85
- testImplementation("org.junit.jupiter:junit-jupiter-params:5.8.2")
86
-
87
- // The instrumentation test companion libraries
88
- androidTestImplementation("de.mannodermaus.junit5:android-test-core:1.3.0")
89
- androidTestRuntimeOnly("de.mannodermaus.junit5:android-test-runner:1.3.0")
90
-
106
+ implementation 'androidx.test:rules:1.7.0'
107
+ implementation 'jp.wasabeef.transformers:coil:1.0.6'
91
108
  }
@@ -1,3 +0,0 @@
1
-
2
- # Ignore "not found" errors for libraries
3
- -dontwarn com.google.android.exoplayer2.**
@@ -1,28 +1,27 @@
1
1
  <?xml version="1.0" encoding="utf-8"?>
2
2
  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3
- package="com.guichaguri.trackplayer">
3
+ package="com.doublesymmetry.trackplayer">
4
4
 
5
5
  <uses-permission android:name="android.permission.WAKE_LOCK" />
6
6
  <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
7
- <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
8
-
7
+ <uses-permission
8
+ android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
9
+
9
10
  <application>
10
11
 
11
12
  <!-- The main service, handles playback, playlists and media buttons -->
12
- <service android:name="com.guichaguri.trackplayer.service.MusicService" android:enabled="true" android:exported="true" android:foregroundServiceType="mediaPlayback">
13
+ <service
14
+ android:name="com.doublesymmetry.trackplayer.service.MusicService"
15
+ android:enabled="true"
16
+ android:exported="true"
17
+ android:foregroundServiceType="mediaPlayback">
13
18
  <intent-filter>
14
19
  <action android:name="android.intent.action.MEDIA_BUTTON" />
20
+ <action android:name="androidx.media3.session.MediaLibraryService" />
15
21
  <action android:name="android.media.browse.MediaBrowserService" />
16
22
  </intent-filter>
17
23
  </service>
18
24
 
19
- <!-- A receiver that will receive media buttons. Required on pre-lollipop devices -->
20
- <receiver android:name="androidx.media.session.MediaButtonReceiver" android:exported="true">
21
- <intent-filter>
22
- <action android:name="android.intent.action.MEDIA_BUTTON" />
23
- </intent-filter>
24
- </receiver>
25
-
26
25
  </application>
27
26
 
28
27
  </manifest>
@@ -0,0 +1,199 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ package com.doublesymmetry.trackplayer
9
+
10
+ import android.annotation.SuppressLint
11
+ import android.content.BroadcastReceiver
12
+ import android.content.Context
13
+ import android.content.Intent
14
+ import android.os.IBinder
15
+ import android.os.PowerManager
16
+ import android.os.PowerManager.WakeLock
17
+ import androidx.media3.session.MediaLibraryService
18
+ import com.facebook.react.ReactApplication
19
+ import com.facebook.react.ReactHost
20
+ import com.facebook.react.ReactInstanceEventListener
21
+ import com.facebook.react.ReactNativeHost
22
+ import com.facebook.react.bridge.ReactContext
23
+ import com.facebook.react.bridge.UiThreadUtil
24
+ import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags
25
+ import com.facebook.react.jstasks.HeadlessJsTaskConfig
26
+ import com.facebook.react.jstasks.HeadlessJsTaskContext.Companion.getInstance
27
+ import com.facebook.react.jstasks.HeadlessJsTaskEventListener
28
+ import java.util.concurrent.CopyOnWriteArraySet
29
+
30
+ /**
31
+ * Base class for running JS without a UI. Generally, you only need to override [getTaskConfig],
32
+ * which is called for every [onStartCommand]. The result, if not `null`, is used to run a JS task.
33
+ *
34
+ * If you need more fine-grained control over how tasks are run, you can override [onStartCommand]
35
+ * and call [startTask] depending on your custom logic.
36
+ *
37
+ * If you're starting a `HeadlessJsTaskService` from a `BroadcastReceiver` (e.g. handling push
38
+ * notifications), make sure to call [acquireWakeLockNow] before returning from
39
+ * [BroadcastReceiver.onReceive], to make sure the device doesn't go to sleep before the service is
40
+ * started.
41
+ */
42
+ public abstract class HeadlessJsMediaService : MediaLibraryService(), HeadlessJsTaskEventListener {
43
+ val activeTasks: MutableSet<Int> = CopyOnWriteArraySet()
44
+ private var initialized = false
45
+
46
+ override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
47
+ super.onStartCommand(intent, flags, startId)
48
+ val taskConfig = getTaskConfig(intent)
49
+ return if (!initialized && taskConfig != null) {
50
+ initialized = true
51
+ startTask(taskConfig)
52
+ START_REDELIVER_INTENT
53
+ } else {
54
+ START_NOT_STICKY
55
+ }
56
+ }
57
+
58
+ /**
59
+ * Called from [.onStartCommand] to create a [HeadlessJsTaskConfig] for this intent.
60
+ *
61
+ * @return a [HeadlessJsTaskConfig] to be used with [startTask], or `null` to ignore this command.
62
+ */
63
+ protected open fun getTaskConfig(intent: Intent?): HeadlessJsTaskConfig? = null
64
+
65
+ override fun onBind(intent: Intent?): IBinder? {
66
+ return super.onBind(intent)
67
+ }
68
+
69
+ override fun onCreate() {
70
+ super.onCreate()
71
+ }
72
+
73
+ /**
74
+ * Start a task. This method handles starting a new React instance if required.
75
+ *
76
+ * Has to be called on the UI thread.
77
+ *
78
+ * @param taskConfig describes what task to start and the parameters to pass to it
79
+ */
80
+ protected fun startTask(taskConfig: HeadlessJsTaskConfig) {
81
+ UiThreadUtil.assertOnUiThread()
82
+ // acquireWakeLockNow(this)
83
+
84
+ val context = reactContext
85
+ if (context == null) {
86
+ createReactContextAndScheduleTask(taskConfig)
87
+ } else {
88
+ invokeStartTask(context, taskConfig)
89
+ }
90
+ }
91
+
92
+ private fun invokeStartTask(reactContext: ReactContext, taskConfig: HeadlessJsTaskConfig) {
93
+ val headlessJsTaskContext = getInstance(reactContext)
94
+ headlessJsTaskContext.addTaskEventListener(this)
95
+ UiThreadUtil.runOnUiThread {
96
+ val taskId = headlessJsTaskContext.startTask(taskConfig)
97
+ activeTasks.add(taskId)
98
+ }
99
+ }
100
+
101
+ override fun onDestroy() {
102
+ super.onDestroy()
103
+
104
+ reactContext?.let { context ->
105
+ val headlessJsTaskContext = getInstance(context)
106
+ headlessJsTaskContext.removeTaskEventListener(this)
107
+ }
108
+ wakeLock?.release()
109
+ }
110
+
111
+ override fun onHeadlessJsTaskStart(taskId: Int): Unit = Unit
112
+
113
+ override fun onHeadlessJsTaskFinish(taskId: Int) {
114
+ activeTasks.remove(taskId)
115
+ if (activeTasks.isEmpty()) {
116
+ stopSelf()
117
+ }
118
+ }
119
+
120
+ /**
121
+ * Get the [com.facebook.react.ReactNativeHost] used by this app. By default, assumes [getApplication] is an instance
122
+ * of [com.facebook.react.ReactApplication] and calls [com.facebook.react.ReactApplication.reactNativeHost].
123
+ *
124
+ * Override this method if your application class does not implement `ReactApplication` or you
125
+ * simply have a different mechanism for storing a `ReactNativeHost`, e.g. as a static field
126
+ * somewhere.
127
+ */
128
+ protected val reactNativeHost: ReactNativeHost
129
+ get() = (application as ReactApplication).reactNativeHost
130
+
131
+ /**
132
+ * Get the [com.facebook.react.ReactHost] used by this app. By default, assumes [.getApplication] is an instance of
133
+ * [ReactApplication] and calls [ReactApplication.getReactHost]. This method assumes it is called
134
+ * in new architecture and returns null if not.
135
+ */
136
+ protected val reactHost: ReactHost?
137
+ get() = (application as ReactApplication).reactHost
138
+
139
+ protected val reactContext: ReactContext?
140
+ @SuppressLint("VisibleForTests")
141
+ get() {
142
+ if (ReactNativeFeatureFlags.enableBridgelessArchitecture()) {
143
+ val reactHost =
144
+ checkNotNull(reactHost) { "ReactHost is not initialized in New Architecture" }
145
+ return reactHost.currentReactContext
146
+ } else {
147
+ val reactInstanceManager = reactNativeHost.reactInstanceManager
148
+ return reactInstanceManager.currentReactContext
149
+ }
150
+ }
151
+
152
+ private fun createReactContextAndScheduleTask(taskConfig: HeadlessJsTaskConfig) {
153
+ if (ReactNativeFeatureFlags.enableBridgelessArchitecture()) {
154
+ val reactHost = checkNotNull(reactHost)
155
+ reactHost.addReactInstanceEventListener(
156
+ object : ReactInstanceEventListener {
157
+ override fun onReactContextInitialized(context: ReactContext) {
158
+ invokeStartTask(context, taskConfig)
159
+ reactHost.removeReactInstanceEventListener(this)
160
+ }
161
+ })
162
+ reactHost.start()
163
+ } else {
164
+ val reactInstanceManager = reactNativeHost.reactInstanceManager
165
+ reactInstanceManager.addReactInstanceEventListener(
166
+ object : ReactInstanceEventListener {
167
+ override fun onReactContextInitialized(context: ReactContext) {
168
+ invokeStartTask(context, taskConfig)
169
+ reactInstanceManager.removeReactInstanceEventListener(this)
170
+ }
171
+ })
172
+ reactInstanceManager.createReactContextInBackground()
173
+ }
174
+ }
175
+
176
+ public companion object {
177
+ var wakeLock: WakeLock? = null
178
+
179
+ /**
180
+ * Acquire a wake lock to ensure the device doesn't go to sleep while processing background
181
+ * tasks.
182
+ */
183
+ @JvmStatic
184
+ @SuppressLint("WakelockTimeout")
185
+ public fun acquireWakeLockNow(context: Context) {
186
+ if (wakeLock == null || wakeLock?.isHeld == false) {
187
+ val powerManager = checkNotNull(context.getSystemService(POWER_SERVICE) as PowerManager)
188
+ wakeLock =
189
+ powerManager
190
+ .newWakeLock(
191
+ PowerManager.PARTIAL_WAKE_LOCK, HeadlessJsMediaService::class.java.canonicalName)
192
+ .also { lock ->
193
+ lock.setReferenceCounted(false)
194
+ lock.acquire()
195
+ }
196
+ }
197
+ }
198
+ }
199
+ }