react-native-mp3-player 1.0.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 (328) hide show
  1. package/LICENSE +205 -0
  2. package/README.md +88 -0
  3. package/android/build.gradle +114 -0
  4. package/android/proguard-rules.txt +0 -0
  5. package/android/src/main/AndroidManifest.xml +27 -0
  6. package/android/src/main/java/com/doublesymmetry/trackplayer/HeadlessJsMediaService.kt +199 -0
  7. package/android/src/main/java/com/doublesymmetry/trackplayer/TrackPlayer.kt +30 -0
  8. package/android/src/main/java/com/doublesymmetry/trackplayer/extensions/AudioPlayerStateExt.kt +19 -0
  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/doublesymmetry/trackplayer/model/MetadataAdapter.kt +227 -0
  12. package/android/src/main/java/com/doublesymmetry/trackplayer/model/NowPlayingMetadata.kt +16 -0
  13. package/android/src/main/java/com/doublesymmetry/trackplayer/model/PlaybackMetadata.kt +203 -0
  14. package/android/src/main/java/com/doublesymmetry/trackplayer/model/State.kt +13 -0
  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/doublesymmetry/trackplayer/module/MusicEvents.kt +65 -0
  19. package/android/src/main/java/com/doublesymmetry/trackplayer/module/MusicModule.kt +775 -0
  20. package/android/src/main/java/com/doublesymmetry/trackplayer/service/MusicService.kt +1251 -0
  21. package/android/src/main/java/com/doublesymmetry/trackplayer/utils/AppForegroundTracker.kt +35 -0
  22. package/android/src/main/java/com/doublesymmetry/trackplayer/utils/BundleUtils.kt +147 -0
  23. package/android/src/main/java/com/doublesymmetry/trackplayer/utils/CoilBitmapLoader.kt +64 -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/lovegaoshi/kotlinaudio/event/EventHolder.kt +30 -0
  27. package/android/src/main/java/com/lovegaoshi/kotlinaudio/event/PlayerEventHolder.kt +124 -0
  28. package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/AudioContentType.kt +10 -0
  29. package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/AudioItem.kt +133 -0
  30. package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/AudioItemTransitionReason.kt +33 -0
  31. package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/AudioPlayerState.kt +30 -0
  32. package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/BufferConfig.kt +8 -0
  33. package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/CacheConfig.kt +17 -0
  34. package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/Capability.kt +19 -0
  35. package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/CustomButton.kt +19 -0
  36. package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/FocusChangeData.kt +3 -0
  37. package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/MediaSessionCallback.kt +17 -0
  38. package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/PlayWhenReadyChangeData.kt +3 -0
  39. package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/PlaybackEndedReason.kt +5 -0
  40. package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/PlaybackError.kt +6 -0
  41. package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/PlayerConfig.kt +36 -0
  42. package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/PlayerOptions.kt +39 -0
  43. package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/PositionChangedReason.kt +39 -0
  44. package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/RepeatMode.kt +16 -0
  45. package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/WakeMode.kt +7 -0
  46. package/android/src/main/java/com/lovegaoshi/kotlinaudio/player/AudioPlayer.kt +689 -0
  47. package/android/src/main/java/com/lovegaoshi/kotlinaudio/player/ForwardingPlayer.java +1124 -0
  48. package/android/src/main/java/com/lovegaoshi/kotlinaudio/player/QueuedAudioPlayer.kt +295 -0
  49. package/android/src/main/java/com/lovegaoshi/kotlinaudio/player/components/Buffer.kt +34 -0
  50. package/android/src/main/java/com/lovegaoshi/kotlinaudio/player/components/Cache.kt +47 -0
  51. package/android/src/main/java/com/lovegaoshi/kotlinaudio/player/components/FocusManager.kt +59 -0
  52. package/android/src/main/java/com/lovegaoshi/kotlinaudio/player/components/MediaFactory.kt +165 -0
  53. package/android/src/main/java/com/lovegaoshi/kotlinaudio/service/MusicService.kt +127 -0
  54. package/android/src/main/java/com/lovegaoshi/kotlinaudio/utils/Utils.kt +113 -0
  55. package/android/src/main/res/drawable/baseline_repeat_24.xml +5 -0
  56. package/android/src/main/res/drawable/baseline_repeat_one_24.xml +5 -0
  57. package/android/src/main/res/drawable/forward.xml +5 -0
  58. package/android/src/main/res/drawable/heart_24px.xml +5 -0
  59. package/android/src/main/res/drawable/hearte_24px.xml +5 -0
  60. package/android/src/main/res/drawable/ifl_24px.xml +5 -0
  61. package/android/src/main/res/drawable/rewind.xml +5 -0
  62. package/android/src/main/res/drawable/shuffle_24px.xml +5 -0
  63. package/android/src/main/res/values/strings.xml +5 -0
  64. package/android/src/main/res/xml/automotive_app_desc.xml +3 -0
  65. package/ios/Example/SwiftAudio/Assets.xcassets/22AMI.imageset/22AMillion.jpg +0 -0
  66. package/ios/Example/SwiftAudio/Assets.xcassets/22AMI.imageset/Contents.json +21 -0
  67. package/ios/Example/SwiftAudio/Assets.xcassets/AccentColor.colorset/Contents.json +11 -0
  68. package/ios/Example/SwiftAudio/Assets.xcassets/AppIcon.appiconset/Contents.json +58 -0
  69. package/ios/Example/SwiftAudio/Assets.xcassets/Contents.json +6 -0
  70. package/ios/Example/SwiftAudio/Assets.xcassets/cover.imageset/Contents.json +21 -0
  71. package/ios/Example/SwiftAudio/Assets.xcassets/cover.imageset/cover.jpg +0 -0
  72. package/ios/Example/SwiftAudio/AudioController.swift +46 -0
  73. package/ios/Example/SwiftAudio/Extensions.swift +22 -0
  74. package/ios/Example/SwiftAudio/PlayerView.swift +172 -0
  75. package/ios/Example/SwiftAudio/PlayerViewModel.swift +120 -0
  76. package/ios/Example/SwiftAudio/Preview Content/Preview Assets.xcassets/Contents.json +6 -0
  77. package/ios/Example/SwiftAudio/QueueView.swift +65 -0
  78. package/ios/Example/SwiftAudio/SwiftAudio.entitlements +12 -0
  79. package/ios/Example/SwiftAudio/SwiftAudioApp.swift +17 -0
  80. package/ios/Example/SwiftAudio.xcodeproj/project.pbxproj +412 -0
  81. package/ios/Example/SwiftAudio.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  82. package/ios/Example/SwiftAudio.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  83. package/ios/RNTrackPlayer/Models/Capabilities.swift +52 -0
  84. package/ios/RNTrackPlayer/Models/MediaURL.swift +38 -0
  85. package/ios/RNTrackPlayer/Models/MetadataAdapter.swift +147 -0
  86. package/ios/RNTrackPlayer/Models/PitchAlgorithms.swift +13 -0
  87. package/ios/RNTrackPlayer/Models/SessionCategories.swift +106 -0
  88. package/ios/RNTrackPlayer/Models/State.swift +26 -0
  89. package/ios/RNTrackPlayer/Models/Track.swift +140 -0
  90. package/ios/RNTrackPlayer/RNTrackPlayer.swift +941 -0
  91. package/ios/RNTrackPlayer/Support/RNTrackPlayer-Bridging-Header.h +7 -0
  92. package/ios/RNTrackPlayer/TrackPlayer.h +14 -0
  93. package/ios/RNTrackPlayer/TrackPlayer.mm +246 -0
  94. package/ios/RNTrackPlayer/Utils/EventType.swift +44 -0
  95. package/ios/RNTrackPlayer/Utils/Metadata.swift +60 -0
  96. package/ios/SwiftAudioEx/Package.swift +20 -0
  97. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/AVPlayerWrapper/AVPlayerWrapper.swift +521 -0
  98. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/AVPlayerWrapper/AVPlayerWrapperDelegate.swift +27 -0
  99. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/AVPlayerWrapper/AVPlayerWrapperProtocol.swift +69 -0
  100. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/AVPlayerWrapper/AVPlayerWrapperState.swift +43 -0
  101. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/AudioItem.swift +158 -0
  102. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/AudioPlayer.swift +459 -0
  103. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/AudioPlayerError.swift +26 -0
  104. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/AudioSessionController/AudioSession.swift +33 -0
  105. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/AudioSessionController/AudioSessionController.swift +135 -0
  106. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/AudioTap.swift +99 -0
  107. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/Event.swift +155 -0
  108. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/NowPlayingInfoController/MediaItemProperty.swift +95 -0
  109. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/NowPlayingInfoController/NowPlayingInfoCenter.swift +17 -0
  110. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/NowPlayingInfoController/NowPlayingInfoController.swift +73 -0
  111. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/NowPlayingInfoController/NowPlayingInfoControllerProtocol.swift +26 -0
  112. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/NowPlayingInfoController/NowPlayingInfoKeyValue.swift +14 -0
  113. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/NowPlayingInfoController/NowPlayingInfoProperty.swift +234 -0
  114. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/Observer/AVPlayerItemNotificationObserver.swift +102 -0
  115. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/Observer/AVPlayerItemObserver.swift +136 -0
  116. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/Observer/AVPlayerObserver.swift +120 -0
  117. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/Observer/AVPlayerTimeObserver.swift +112 -0
  118. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/QueueManager.swift +356 -0
  119. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/QueuedAudioPlayer.swift +236 -0
  120. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/RemoteCommandController/RemoteCommand.swift +170 -0
  121. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/RemoteCommandController/RemoteCommandController.swift +206 -0
  122. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/RepeatMode.swift +15 -0
  123. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/TimeEventFrequency.swift +26 -0
  124. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/Utils/DispatchQueueType.swift +18 -0
  125. package/ios/SwiftAudioEx/Sources/SwiftAudioEx/WaveformAudioTap.swift +159 -0
  126. package/lib/specs/NativeTrackPlayer.d.ts +129 -0
  127. package/lib/specs/NativeTrackPlayer.js +4 -0
  128. package/lib/src/constants/AndroidAudioContentType.d.ts +35 -0
  129. package/lib/src/constants/AndroidAudioContentType.js +36 -0
  130. package/lib/src/constants/AndroidAutoContentStyle.d.ts +10 -0
  131. package/lib/src/constants/AndroidAutoContentStyle.js +11 -0
  132. package/lib/src/constants/AppKilledPlaybackBehavior.d.ts +17 -0
  133. package/lib/src/constants/AppKilledPlaybackBehavior.js +18 -0
  134. package/lib/src/constants/Capability.d.ts +17 -0
  135. package/lib/src/constants/Capability.js +19 -0
  136. package/lib/src/constants/Event.d.ts +163 -0
  137. package/lib/src/constants/Event.js +164 -0
  138. package/lib/src/constants/IOSCategory.d.ts +36 -0
  139. package/lib/src/constants/IOSCategory.js +37 -0
  140. package/lib/src/constants/IOSCategoryMode.d.ts +47 -0
  141. package/lib/src/constants/IOSCategoryMode.js +48 -0
  142. package/lib/src/constants/IOSCategoryOptions.d.ts +44 -0
  143. package/lib/src/constants/IOSCategoryOptions.js +45 -0
  144. package/lib/src/constants/MediaItemPlayable.d.ts +4 -0
  145. package/lib/src/constants/MediaItemPlayable.js +5 -0
  146. package/lib/src/constants/PitchAlgorithm.d.ts +14 -0
  147. package/lib/src/constants/PitchAlgorithm.js +16 -0
  148. package/lib/src/constants/RatingType.d.ts +8 -0
  149. package/lib/src/constants/RatingType.js +10 -0
  150. package/lib/src/constants/RepeatMode.d.ts +8 -0
  151. package/lib/src/constants/RepeatMode.js +10 -0
  152. package/lib/src/constants/State.d.ts +34 -0
  153. package/lib/src/constants/State.js +35 -0
  154. package/lib/src/constants/TrackType.d.ts +6 -0
  155. package/lib/src/constants/TrackType.js +7 -0
  156. package/lib/src/constants/index.d.ts +14 -0
  157. package/lib/src/constants/index.js +14 -0
  158. package/lib/src/hooks/index.d.ts +6 -0
  159. package/lib/src/hooks/index.js +6 -0
  160. package/lib/src/hooks/useActiveTrack.d.ts +2 -0
  161. package/lib/src/hooks/useActiveTrack.js +28 -0
  162. package/lib/src/hooks/useAppIsInBackground.d.ts +1 -0
  163. package/lib/src/hooks/useAppIsInBackground.js +16 -0
  164. package/lib/src/hooks/useIsPlaying.d.ts +35 -0
  165. package/lib/src/hooks/useIsPlaying.js +50 -0
  166. package/lib/src/hooks/usePlayWhenReady.d.ts +1 -0
  167. package/lib/src/hooks/usePlayWhenReady.js +27 -0
  168. package/lib/src/hooks/usePlaybackState.d.ts +10 -0
  169. package/lib/src/hooks/usePlaybackState.js +35 -0
  170. package/lib/src/hooks/useProgress.d.ts +7 -0
  171. package/lib/src/hooks/useProgress.js +55 -0
  172. package/lib/src/hooks/useTrackPlayerEvents.d.ts +8 -0
  173. package/lib/src/hooks/useTrackPlayerEvents.js +30 -0
  174. package/lib/src/index.d.ts +5 -0
  175. package/lib/src/index.js +5 -0
  176. package/lib/src/interfaces/AndroidAutoBrowseTree.d.ts +5 -0
  177. package/lib/src/interfaces/AndroidAutoBrowseTree.js +1 -0
  178. package/lib/src/interfaces/AndroidOptions.d.ts +41 -0
  179. package/lib/src/interfaces/AndroidOptions.js +1 -0
  180. package/lib/src/interfaces/CustomButtons.d.ts +5 -0
  181. package/lib/src/interfaces/CustomButtons.js +1 -0
  182. package/lib/src/interfaces/FeedbackOptions.d.ts +6 -0
  183. package/lib/src/interfaces/FeedbackOptions.js +1 -0
  184. package/lib/src/interfaces/MediaItem.d.ts +18 -0
  185. package/lib/src/interfaces/MediaItem.js +1 -0
  186. package/lib/src/interfaces/MetadataOptions.d.ts +3 -0
  187. package/lib/src/interfaces/MetadataOptions.js +1 -0
  188. package/lib/src/interfaces/NowPlayingMetadata.d.ts +4 -0
  189. package/lib/src/interfaces/NowPlayingMetadata.js +1 -0
  190. package/lib/src/interfaces/PlaybackState.d.ts +8 -0
  191. package/lib/src/interfaces/PlaybackState.js +1 -0
  192. package/lib/src/interfaces/PlayerOptions.d.ts +127 -0
  193. package/lib/src/interfaces/PlayerOptions.js +1 -0
  194. package/lib/src/interfaces/Progress.d.ts +15 -0
  195. package/lib/src/interfaces/Progress.js +1 -0
  196. package/lib/src/interfaces/ResourceObject.d.ts +1 -0
  197. package/lib/src/interfaces/ResourceObject.js +1 -0
  198. package/lib/src/interfaces/ServiceHandler.d.ts +1 -0
  199. package/lib/src/interfaces/ServiceHandler.js +1 -0
  200. package/lib/src/interfaces/Track.d.ts +21 -0
  201. package/lib/src/interfaces/Track.js +1 -0
  202. package/lib/src/interfaces/TrackMetadataBase.d.ts +28 -0
  203. package/lib/src/interfaces/TrackMetadataBase.js +1 -0
  204. package/lib/src/interfaces/UpdateOptions.d.ts +52 -0
  205. package/lib/src/interfaces/UpdateOptions.js +1 -0
  206. package/lib/src/interfaces/events/AudioMetadataReceivedEvent.d.ts +33 -0
  207. package/lib/src/interfaces/events/AudioMetadataReceivedEvent.js +1 -0
  208. package/lib/src/interfaces/events/ControllerConnectedEvent.d.ts +8 -0
  209. package/lib/src/interfaces/events/ControllerConnectedEvent.js +1 -0
  210. package/lib/src/interfaces/events/EventPayloadByEvent.d.ts +73 -0
  211. package/lib/src/interfaces/events/EventPayloadByEvent.js +1 -0
  212. package/lib/src/interfaces/events/PlaybackActiveTrackChangedEvent.d.ts +24 -0
  213. package/lib/src/interfaces/events/PlaybackActiveTrackChangedEvent.js +1 -0
  214. package/lib/src/interfaces/events/PlaybackAnimatedVolumeChangedEvent.d.ts +4 -0
  215. package/lib/src/interfaces/events/PlaybackAnimatedVolumeChangedEvent.js +1 -0
  216. package/lib/src/interfaces/events/PlaybackErrorEvent.d.ts +6 -0
  217. package/lib/src/interfaces/events/PlaybackErrorEvent.js +1 -0
  218. package/lib/src/interfaces/events/PlaybackMetadataReceivedEvent.d.ts +16 -0
  219. package/lib/src/interfaces/events/PlaybackMetadataReceivedEvent.js +1 -0
  220. package/lib/src/interfaces/events/PlaybackPlayWhenReadyChangedEvent.d.ts +4 -0
  221. package/lib/src/interfaces/events/PlaybackPlayWhenReadyChangedEvent.js +1 -0
  222. package/lib/src/interfaces/events/PlaybackProgressUpdatedEvent.d.ts +4 -0
  223. package/lib/src/interfaces/events/PlaybackProgressUpdatedEvent.js +1 -0
  224. package/lib/src/interfaces/events/PlaybackQueueEndedEvent.d.ts +9 -0
  225. package/lib/src/interfaces/events/PlaybackQueueEndedEvent.js +1 -0
  226. package/lib/src/interfaces/events/PlaybackResumeEvent.d.ts +3 -0
  227. package/lib/src/interfaces/events/PlaybackResumeEvent.js +1 -0
  228. package/lib/src/interfaces/events/PlaybackTrackChangedEvent.d.ts +11 -0
  229. package/lib/src/interfaces/events/PlaybackTrackChangedEvent.js +1 -0
  230. package/lib/src/interfaces/events/PlayerErrorEvent.d.ts +6 -0
  231. package/lib/src/interfaces/events/PlayerErrorEvent.js +1 -0
  232. package/lib/src/interfaces/events/RemoteBrowseEvent.d.ts +4 -0
  233. package/lib/src/interfaces/events/RemoteBrowseEvent.js +1 -0
  234. package/lib/src/interfaces/events/RemoteCustomActionEvent.d.ts +7 -0
  235. package/lib/src/interfaces/events/RemoteCustomActionEvent.js +1 -0
  236. package/lib/src/interfaces/events/RemoteDuckEvent.d.ts +13 -0
  237. package/lib/src/interfaces/events/RemoteDuckEvent.js +1 -0
  238. package/lib/src/interfaces/events/RemoteJumpBackwardEvent.d.ts +8 -0
  239. package/lib/src/interfaces/events/RemoteJumpBackwardEvent.js +1 -0
  240. package/lib/src/interfaces/events/RemoteJumpForwardEvent.d.ts +8 -0
  241. package/lib/src/interfaces/events/RemoteJumpForwardEvent.js +1 -0
  242. package/lib/src/interfaces/events/RemotePlayIdEvent.d.ts +4 -0
  243. package/lib/src/interfaces/events/RemotePlayIdEvent.js +1 -0
  244. package/lib/src/interfaces/events/RemotePlaySearchEvent.d.ts +9 -0
  245. package/lib/src/interfaces/events/RemotePlaySearchEvent.js +1 -0
  246. package/lib/src/interfaces/events/RemoteSeekEvent.d.ts +4 -0
  247. package/lib/src/interfaces/events/RemoteSeekEvent.js +1 -0
  248. package/lib/src/interfaces/events/RemoteSetRatingEvent.d.ts +4 -0
  249. package/lib/src/interfaces/events/RemoteSetRatingEvent.js +1 -0
  250. package/lib/src/interfaces/events/RemoteSkipEvent.d.ts +3 -0
  251. package/lib/src/interfaces/events/RemoteSkipEvent.js +1 -0
  252. package/lib/src/interfaces/events/index.d.ts +18 -0
  253. package/lib/src/interfaces/events/index.js +18 -0
  254. package/lib/src/interfaces/index.d.ts +15 -0
  255. package/lib/src/interfaces/index.js +15 -0
  256. package/lib/src/resolveAssetSource.d.ts +2 -0
  257. package/lib/src/resolveAssetSource.js +3 -0
  258. package/lib/src/trackPlayer.d.ts +347 -0
  259. package/lib/src/trackPlayer.js +592 -0
  260. package/package.json +94 -0
  261. package/react-native-mp3-player.podspec +22 -0
  262. package/specs/NativeTrackPlayer.ts +148 -0
  263. package/src/constants/AndroidAudioContentType.ts +35 -0
  264. package/src/constants/AndroidAutoContentStyle.ts +10 -0
  265. package/src/constants/AppKilledPlaybackBehavior.ts +19 -0
  266. package/src/constants/Capability.ts +19 -0
  267. package/src/constants/Event.ts +164 -0
  268. package/src/constants/IOSCategory.ts +36 -0
  269. package/src/constants/IOSCategoryMode.ts +47 -0
  270. package/src/constants/IOSCategoryOptions.ts +44 -0
  271. package/src/constants/MediaItemPlayable.ts +4 -0
  272. package/src/constants/PitchAlgorithm.ts +16 -0
  273. package/src/constants/RatingType.ts +10 -0
  274. package/src/constants/RepeatMode.ts +10 -0
  275. package/src/constants/State.ts +34 -0
  276. package/src/constants/TrackType.ts +6 -0
  277. package/src/constants/index.ts +14 -0
  278. package/src/hooks/index.ts +6 -0
  279. package/src/hooks/useActiveTrack.ts +36 -0
  280. package/src/hooks/useAppIsInBackground.ts +20 -0
  281. package/src/hooks/useIsPlaying.ts +56 -0
  282. package/src/hooks/usePlayWhenReady.ts +37 -0
  283. package/src/hooks/usePlaybackState.ts +45 -0
  284. package/src/hooks/useProgress.ts +64 -0
  285. package/src/hooks/useTrackPlayerEvents.ts +48 -0
  286. package/src/index.ts +7 -0
  287. package/src/interfaces/AndroidAutoBrowseTree.ts +6 -0
  288. package/src/interfaces/AndroidOptions.ts +48 -0
  289. package/src/interfaces/CustomButtons.ts +6 -0
  290. package/src/interfaces/FeedbackOptions.ts +7 -0
  291. package/src/interfaces/MediaItem.ts +19 -0
  292. package/src/interfaces/MetadataOptions.ts +4 -0
  293. package/src/interfaces/NowPlayingMetadata.ts +5 -0
  294. package/src/interfaces/PlaybackState.ts +11 -0
  295. package/src/interfaces/PlayerOptions.ts +133 -0
  296. package/src/interfaces/Progress.ts +15 -0
  297. package/src/interfaces/ResourceObject.ts +1 -0
  298. package/src/interfaces/ServiceHandler.ts +1 -0
  299. package/src/interfaces/Track.ts +23 -0
  300. package/src/interfaces/TrackMetadataBase.ts +29 -0
  301. package/src/interfaces/UpdateOptions.ts +59 -0
  302. package/src/interfaces/events/AudioMetadataReceivedEvent.ts +37 -0
  303. package/src/interfaces/events/ControllerConnectedEvent.ts +9 -0
  304. package/src/interfaces/events/EventPayloadByEvent.ts +76 -0
  305. package/src/interfaces/events/PlaybackActiveTrackChangedEvent.ts +29 -0
  306. package/src/interfaces/events/PlaybackAnimatedVolumeChangedEvent.ts +4 -0
  307. package/src/interfaces/events/PlaybackErrorEvent.ts +6 -0
  308. package/src/interfaces/events/PlaybackMetadataReceivedEvent.ts +16 -0
  309. package/src/interfaces/events/PlaybackPlayWhenReadyChangedEvent.ts +4 -0
  310. package/src/interfaces/events/PlaybackProgressUpdatedEvent.ts +5 -0
  311. package/src/interfaces/events/PlaybackQueueEndedEvent.ts +9 -0
  312. package/src/interfaces/events/PlaybackResumeEvent.ts +5 -0
  313. package/src/interfaces/events/PlaybackTrackChangedEvent.ts +11 -0
  314. package/src/interfaces/events/PlayerErrorEvent.ts +6 -0
  315. package/src/interfaces/events/RemoteBrowseEvent.ts +4 -0
  316. package/src/interfaces/events/RemoteCustomActionEvent.ts +7 -0
  317. package/src/interfaces/events/RemoteDuckEvent.ts +13 -0
  318. package/src/interfaces/events/RemoteJumpBackwardEvent.ts +8 -0
  319. package/src/interfaces/events/RemoteJumpForwardEvent.ts +8 -0
  320. package/src/interfaces/events/RemotePlayIdEvent.ts +4 -0
  321. package/src/interfaces/events/RemotePlaySearchEvent.ts +21 -0
  322. package/src/interfaces/events/RemoteSeekEvent.ts +4 -0
  323. package/src/interfaces/events/RemoteSetRatingEvent.ts +5 -0
  324. package/src/interfaces/events/RemoteSkipEvent.ts +3 -0
  325. package/src/interfaces/events/index.ts +18 -0
  326. package/src/interfaces/index.ts +15 -0
  327. package/src/resolveAssetSource.ts +3 -0
  328. package/src/trackPlayer.ts +768 -0
@@ -0,0 +1,592 @@
1
+ import { AppRegistry, NativeEventEmitter, Platform, Animated, } from 'react-native';
2
+ import TrackPlayer from '../specs/NativeTrackPlayer';
3
+ import resolveAssetSource from './resolveAssetSource';
4
+ const isAndroid = Platform.OS === 'android';
5
+ const emitter = new NativeEventEmitter(TrackPlayer);
6
+ const animatedVolume = new Animated.Value(1);
7
+ animatedVolume.addListener((state) => TrackPlayer.setVolume(state.value));
8
+ // MARK: - Helpers
9
+ function resolveImportedAssetOrPath(pathOrAsset) {
10
+ return pathOrAsset === undefined
11
+ ? undefined
12
+ : typeof pathOrAsset === 'string'
13
+ ? pathOrAsset
14
+ : resolveImportedAsset(pathOrAsset);
15
+ }
16
+ function resolveImportedAsset(id) {
17
+ return id
18
+ ? (resolveAssetSource(id) ?? undefined)
19
+ : undefined;
20
+ }
21
+ // MARK: - General API
22
+ /**
23
+ * Initializes the player with the specified options.
24
+ *
25
+ * Note that on Android this method must only be called while the app is in the
26
+ * foreground, otherwise it will throw an error with code
27
+ * `'android_cannot_setup_player_in_background'`. In this case you can wait for
28
+ * the app to be in the foreground and try again.
29
+ *
30
+ * @param options The options to initialize the player with.
31
+ * @see https://rntp.dev/docs/api/functions/lifecycle
32
+ */
33
+ export async function setupPlayer(options = {}, background = false) {
34
+ if (options != null && typeof options !== 'object') {
35
+ throw new Error('react-native-mp3-player: setupPlayer() options must be a plain object or undefined');
36
+ }
37
+ return TrackPlayer.setupPlayer(options ?? {}, background);
38
+ }
39
+ /**
40
+ * Register the playback service. The service will run as long as the player runs.
41
+ */
42
+ export function registerPlaybackService(factory) {
43
+ if (isAndroid) {
44
+ // Registers the headless task
45
+ AppRegistry.registerHeadlessTask('TrackPlayer', factory);
46
+ }
47
+ else if (Platform.OS === 'web') {
48
+ factory()();
49
+ }
50
+ else {
51
+ // Initializes and runs the service in the next tick
52
+ setImmediate(factory());
53
+ }
54
+ }
55
+ export function addEventListener(event, listener) {
56
+ return emitter.addListener(event, listener);
57
+ }
58
+ export async function add(tracks, insertBeforeIndex = -1) {
59
+ const resolvedTracks = (Array.isArray(tracks) ? tracks : [tracks]).map((track) => ({
60
+ ...track,
61
+ url: resolveImportedAssetOrPath(track.url),
62
+ artwork: resolveImportedAssetOrPath(track.artwork),
63
+ }));
64
+ return resolvedTracks.length < 1
65
+ ? undefined
66
+ : TrackPlayer.add(resolvedTracks, insertBeforeIndex);
67
+ }
68
+ /**
69
+ * Replaces the current track or loads the track as the first in the queue.
70
+ *
71
+ * @param track The track to load.
72
+ */
73
+ export async function load(track) {
74
+ if (!track || typeof track !== 'object') {
75
+ throw new Error('react-native-mp3-player: load() requires a track object');
76
+ }
77
+ if (track.url == null && track.id == null) {
78
+ throw new Error('react-native-mp3-player: load() track must have "url" or "id"');
79
+ }
80
+ return TrackPlayer.load(track);
81
+ }
82
+ /**
83
+ * Move a track within the queue.
84
+ *
85
+ * @param fromIndex The index of the track to be moved.
86
+ * @param toIndex The index to move the track to. If the index is larger than
87
+ * the size of the queue, then the track is moved to the end of the queue.
88
+ */
89
+ export async function move(fromIndex, toIndex) {
90
+ return TrackPlayer.move(fromIndex, toIndex);
91
+ }
92
+ export async function remove(indexOrIndexes) {
93
+ return TrackPlayer.remove(Array.isArray(indexOrIndexes) ? indexOrIndexes : [indexOrIndexes]);
94
+ }
95
+ /**
96
+ * Clears any upcoming tracks from the queue.
97
+ */
98
+ export async function removeUpcomingTracks() {
99
+ return TrackPlayer.removeUpcomingTracks();
100
+ }
101
+ /**
102
+ * Skips to a track in the queue.
103
+ *
104
+ * @param index The index of the track to skip to.
105
+ * @param initialPosition (Optional) The initial position to seek to in seconds.
106
+ */
107
+ export async function skip(index, initialPosition = -1) {
108
+ return TrackPlayer.skip(index, initialPosition);
109
+ }
110
+ /**
111
+ * Skips to the next track in the queue.
112
+ *
113
+ * @param initialPosition (Optional) The initial position to seek to in seconds.
114
+ */
115
+ export async function skipToNext(initialPosition = -1) {
116
+ return TrackPlayer.skipToNext(initialPosition);
117
+ }
118
+ /**
119
+ * Skips to the previous track in the queue.
120
+ *
121
+ * @param initialPosition (Optional) The initial position to seek to in seconds.
122
+ */
123
+ export async function skipToPrevious(initialPosition = -1) {
124
+ return TrackPlayer.skipToPrevious(initialPosition);
125
+ }
126
+ // MARK: - Control Center / Notifications API
127
+ /**
128
+ * Updates the configuration for the components.
129
+ *
130
+ * @param options The options to update.
131
+ * @see https://rntp.dev/docs/api/functions/player#updateoptionsoptions
132
+ */
133
+ export async function updateOptions({ alwaysPauseOnInterruption, ...options } = {}) {
134
+ return TrackPlayer.updateOptions({
135
+ ...options,
136
+ android: {
137
+ // Handle deprecated alwaysPauseOnInterruption option:
138
+ alwaysPauseOnInterruption: options.android?.alwaysPauseOnInterruption ?? alwaysPauseOnInterruption,
139
+ ...options.android,
140
+ },
141
+ icon: resolveImportedAsset(options.icon),
142
+ playIcon: resolveImportedAsset(options.playIcon),
143
+ pauseIcon: resolveImportedAsset(options.pauseIcon),
144
+ stopIcon: resolveImportedAsset(options.stopIcon),
145
+ previousIcon: resolveImportedAsset(options.previousIcon),
146
+ nextIcon: resolveImportedAsset(options.nextIcon),
147
+ // rewindIcon: resolveImportedAsset(options.rewindIcon),
148
+ // forwardIcon: resolveImportedAsset(options.forwardIcon),
149
+ });
150
+ }
151
+ /**
152
+ * Updates the metadata of a track in the queue. If the current track is updated,
153
+ * the notification and the Now Playing Center will be updated accordingly.
154
+ *
155
+ * @param trackIndex The index of the track whose metadata will be updated.
156
+ * @param metadata The metadata to update.
157
+ */
158
+ export async function updateMetadataForTrack(trackIndex, metadata) {
159
+ return TrackPlayer.updateMetadataForTrack(trackIndex, {
160
+ ...metadata,
161
+ artwork: resolveImportedAssetOrPath(metadata.artwork),
162
+ });
163
+ }
164
+ /**
165
+ * Updates the metadata content of the notification (Android) and the Now Playing Center (iOS)
166
+ * without affecting the data stored for the current track.
167
+ */
168
+ export function updateNowPlayingMetadata(metadata) {
169
+ return TrackPlayer.updateNowPlayingMetadata({
170
+ ...metadata,
171
+ artwork: resolveImportedAssetOrPath(metadata.artwork),
172
+ });
173
+ }
174
+ // MARK: - Player API
175
+ /**
176
+ * Resets the player stopping the current track and clearing the queue.
177
+ */
178
+ export async function reset() {
179
+ return TrackPlayer.reset();
180
+ }
181
+ /**
182
+ * Plays or resumes the current track.
183
+ */
184
+ export async function play() {
185
+ return TrackPlayer.play();
186
+ }
187
+ /**
188
+ * Pauses the current track.
189
+ */
190
+ export async function pause() {
191
+ return TrackPlayer.pause();
192
+ }
193
+ /**
194
+ * Stops the current track.
195
+ */
196
+ export async function stop() {
197
+ return TrackPlayer.stop();
198
+ }
199
+ /**
200
+ * Sets whether the player will play automatically when it is ready to do so.
201
+ * This is the equivalent of calling `TrackPlayer.play()` when `playWhenReady = true`
202
+ * or `TrackPlayer.pause()` when `playWhenReady = false`.
203
+ */
204
+ export async function setPlayWhenReady(playWhenReady) {
205
+ return TrackPlayer.setPlayWhenReady(playWhenReady);
206
+ }
207
+ /**
208
+ * Gets whether the player will play automatically when it is ready to do so.
209
+ */
210
+ export async function getPlayWhenReady() {
211
+ return TrackPlayer.getPlayWhenReady();
212
+ }
213
+ /**
214
+ * Seeks to a specified time position in the current track.
215
+ *
216
+ * @param position The position to seek to in seconds.
217
+ */
218
+ export async function seekTo(position) {
219
+ return TrackPlayer.seekTo(position);
220
+ }
221
+ /**
222
+ * Seeks by a relative time offset in the current track.
223
+ *
224
+ * @param offset The time offset to seek by in seconds.
225
+ */
226
+ export async function seekBy(offset) {
227
+ return TrackPlayer.seekBy(offset);
228
+ }
229
+ /**
230
+ * Sets the volume of the player.
231
+ *
232
+ * @param volume The volume as a number between 0 and 1.
233
+ */
234
+ export async function setVolume(level) {
235
+ return TrackPlayer.setVolume(level);
236
+ }
237
+ /**
238
+ * Sets the volume of the player with a simple linear scaling.
239
+ * In Android this is achieved via a native thread call.
240
+ * In other platforms this is achieved via RN's Animated.Value.
241
+ *
242
+ * @param volume The volume as a number between 0 and 1.
243
+ * @param duration The duration of the animation in milliseconds. defualt is 0 ms, which just functions as TP.setVolume.
244
+ * @param init The initial value of the volume. This may be useful eg to be 0 for a fade in event.
245
+ * @param interval The interval of the animation in milliseconds. default is 20 ms.
246
+ * @param msg (Android) The message to be emitted after volume is fully changed, via Event.PlaybackAnimatedVolumeChanged.
247
+ * @param callback (other platforms) The callback to be called after volume is fully changed.
248
+ */
249
+ export const setAnimatedVolume = async ({ volume, duration = 0, init = -1, interval = 20, msg = '', callback = () => undefined, }) => {
250
+ if (duration === 0) {
251
+ TrackPlayer.setVolume(volume);
252
+ return callback();
253
+ }
254
+ if (init !== -1) {
255
+ TrackPlayer.setVolume(init);
256
+ }
257
+ if (isAndroid) {
258
+ return TrackPlayer.setAnimatedVolume(volume, duration, interval, msg);
259
+ }
260
+ else {
261
+ /*
262
+ TODO: Animated.value change relies on React rendering so Android
263
+ headlessJS will not work with it. however does iOS and windows work in the background?
264
+ if not this code block is needed
265
+ if (AppState.currentState !== 'active') {
266
+ // need to figure out a way to run Animated.timing in background. probably needs our own module
267
+ duration = 0;
268
+ }
269
+ */
270
+ volume = Math.min(volume, 1);
271
+ if (duration === 0) {
272
+ animatedVolume.setValue(volume);
273
+ callback();
274
+ return;
275
+ }
276
+ animatedVolume.stopAnimation();
277
+ Animated.timing(animatedVolume, {
278
+ toValue: volume,
279
+ useNativeDriver: true,
280
+ duration,
281
+ }).start(() => callback());
282
+ }
283
+ };
284
+ /**
285
+ * performs fading out to pause playback.
286
+ * @param duration duration of the fade progress in ms
287
+ * @param interval interval of the fade progress in ms
288
+ */
289
+ export const fadeOutPause = async (duration = 500, interval = 20) => {
290
+ if (isAndroid) {
291
+ TrackPlayer.fadeOutPause(duration, interval);
292
+ }
293
+ else {
294
+ setAnimatedVolume({
295
+ duration,
296
+ interval,
297
+ volume: 0,
298
+ callback: () => pause(),
299
+ });
300
+ }
301
+ };
302
+ /**
303
+ * performs fading into playing the next track.
304
+ * @param duration duration of the fade progress in ms
305
+ * @param interval interval of the fade progress in ms
306
+ * @param toVolume volume to fade into
307
+ */
308
+ export const fadeOutNext = async (duration = 500, interval = 20, toVolume = 1) => {
309
+ if (isAndroid) {
310
+ TrackPlayer.fadeOutNext(duration, interval, toVolume);
311
+ }
312
+ else {
313
+ setAnimatedVolume({
314
+ duration,
315
+ interval,
316
+ volume: 0,
317
+ callback: async () => {
318
+ await skipToNext();
319
+ setAnimatedVolume({
320
+ duration,
321
+ interval,
322
+ volume: toVolume,
323
+ });
324
+ },
325
+ });
326
+ }
327
+ };
328
+ /**
329
+ * performs fading into playing the previous track.
330
+ * @param duration duration of the fade progress in ms
331
+ * @param interval interval of the fade progress in ms
332
+ * @param toVolume volume to fade into
333
+ */
334
+ export const fadeOutPrevious = async (duration = 500, interval = 20, toVolume = 1) => {
335
+ if (isAndroid) {
336
+ TrackPlayer.fadeOutPrevious(duration, interval, toVolume);
337
+ }
338
+ else {
339
+ setAnimatedVolume({
340
+ duration,
341
+ interval,
342
+ volume: 0,
343
+ callback: async () => {
344
+ await skipToPrevious();
345
+ setAnimatedVolume({
346
+ duration,
347
+ interval,
348
+ volume: toVolume,
349
+ });
350
+ },
351
+ });
352
+ }
353
+ };
354
+ /**
355
+ * performs fading into skipping to a track.
356
+ * @param index the index of the track to skip to
357
+ * @param duration duration of the fade progress in ms
358
+ * @param interval interval of the fade progress in ms
359
+ * @param toVolume volume to fade into
360
+ */
361
+ export const fadeOutJump = async (index, duration = 500, interval = 20, toVolume = 1) => {
362
+ if (isAndroid) {
363
+ TrackPlayer.fadeOutJump(index, duration, interval, toVolume);
364
+ }
365
+ else {
366
+ setAnimatedVolume({
367
+ duration,
368
+ interval,
369
+ volume: 0,
370
+ callback: async () => {
371
+ await skip(index);
372
+ setAnimatedVolume({
373
+ duration,
374
+ interval,
375
+ volume: toVolume,
376
+ });
377
+ },
378
+ });
379
+ }
380
+ };
381
+ /**
382
+ * Sets the playback rate.
383
+ *
384
+ * @param rate The playback rate to change to, where 0.5 would be half speed,
385
+ * 1 would be regular speed, 2 would be double speed etc.
386
+ */
387
+ export async function setRate(rate) {
388
+ return TrackPlayer.setRate(rate);
389
+ }
390
+ /**
391
+ * Sets the playback pitch. android only
392
+ *
393
+ * @param pitch The pitch.
394
+ */
395
+ export async function setPitch(pitch) {
396
+ return isAndroid ? TrackPlayer.setPitch(pitch) : void 0;
397
+ }
398
+ /**
399
+ * Sets the queue.
400
+ *
401
+ * @param tracks The tracks to set as the queue.
402
+ * @see https://rntp.dev/docs/api/constants/repeat-mode
403
+ */
404
+ export async function setQueue(tracks) {
405
+ return TrackPlayer.setQueue(tracks);
406
+ }
407
+ /**
408
+ * Sets the queue repeat mode.
409
+ *
410
+ * @param repeatMode The repeat mode to set.
411
+ * @see https://rntp.dev/docs/api/constants/repeat-mode
412
+ */
413
+ export async function setRepeatMode(mode) {
414
+ return TrackPlayer.setRepeatMode(mode);
415
+ }
416
+ // MARK: - Getters
417
+ /**
418
+ * Gets the volume of the player as a number between 0 and 1.
419
+ */
420
+ export async function getVolume() {
421
+ return TrackPlayer.getVolume();
422
+ }
423
+ /**
424
+ * Gets the playback rate where 0.5 would be half speed, 1 would be
425
+ * regular speed and 2 would be double speed etc.
426
+ */
427
+ export async function getRate() {
428
+ return TrackPlayer.getRate();
429
+ }
430
+ /**
431
+ * Gets the pitch of the track.
432
+ */
433
+ export async function getPitch() {
434
+ return isAndroid ? TrackPlayer.getPitch() : 1;
435
+ }
436
+ /**
437
+ * Gets a track object from the queue.
438
+ *
439
+ * @param index The index of the track.
440
+ * @returns The track object or undefined if there isn't a track object at that
441
+ * index.
442
+ */
443
+ export async function getTrack(index) {
444
+ // @ts-expect-error codegen issues
445
+ return TrackPlayer.getTrack(index);
446
+ }
447
+ /**
448
+ * Gets the whole queue.
449
+ */
450
+ export async function getQueue() {
451
+ // @ts-expect-error codegen issues
452
+ return TrackPlayer.getQueue();
453
+ }
454
+ /**
455
+ * Gets the index of the active track in the queue or undefined if there is no
456
+ * current track.
457
+ */
458
+ export async function getActiveTrackIndex() {
459
+ return (await TrackPlayer.getActiveTrackIndex()) ?? undefined;
460
+ }
461
+ /**
462
+ * Gets the active track or undefined if there is no current track.
463
+ */
464
+ export async function getActiveTrack() {
465
+ // @ts-expect-error codegen issues
466
+ return (await TrackPlayer.getActiveTrack()) ?? undefined;
467
+ }
468
+ /**
469
+ * Gets information on the progress of the currently active track, including its
470
+ * current playback position in seconds, buffered position in seconds and
471
+ * duration in seconds.
472
+ */
473
+ export async function getProgress() {
474
+ // @ts-expect-error codegen issues
475
+ return TrackPlayer.getProgress();
476
+ }
477
+ /**
478
+ * Gets the playback state of the player.
479
+ *
480
+ * @see https://rntp.dev/docs/api/constants/state
481
+ */
482
+ export async function getPlaybackState() {
483
+ // @ts-expect-error codegen issues
484
+ return TrackPlayer.getPlaybackState();
485
+ }
486
+ /**
487
+ * Gets the queue repeat mode.
488
+ *
489
+ * @see https://rntp.dev/docs/api/constants/repeat-mode
490
+ */
491
+ export async function getRepeatMode() {
492
+ return TrackPlayer.getRepeatMode();
493
+ }
494
+ /**
495
+ * Retries the current item when the playback state is `State.Error`.
496
+ */
497
+ export async function retry() {
498
+ return TrackPlayer.retry();
499
+ }
500
+ /**
501
+ * Sets the content hierarchy of Android Auto (Android only). The hierarchy structure is a dict with
502
+ * the mediaId as keys, and a list of MediaItem as values. To use, you must at least specify the root directory, where
503
+ * the key is "/". If the root directory contains BROWSABLE MediaItems, they will be shown as tabs. Do note Google requires
504
+ * AA to have a max of 4 tabs. You may then set the mediaId keys of the browsable MediaItems to be a list of other MediaItems.
505
+ *
506
+ * @param browseTree the content hierarchy dict.
507
+ * @returns a serialized copy of the browseTree set by native. For debug purposes.
508
+ */
509
+ export async function setBrowseTree(browseTree) {
510
+ if (!isAndroid)
511
+ return new Promise(() => '');
512
+ return TrackPlayer.setBrowseTree(browseTree);
513
+ }
514
+ /**
515
+ * this method enables android auto playback progress tracking; see
516
+ * https://developer.android.com/training/cars/media#browse-progress-bar
517
+ * android only.
518
+ * @param mediaID the mediaID.
519
+ * @returns
520
+ */
521
+ export async function setPlaybackState(mediaID) {
522
+ if (!isAndroid)
523
+ return;
524
+ TrackPlayer.setPlaybackState(mediaID);
525
+ }
526
+ /**
527
+ * Sets the content style of Android Auto (Android only).
528
+ * there are list style and grid style. see https://developer.android.com/training/cars/media#apply_content_style .
529
+ * the styles are applicable to browsable nodes and playable nodes. setting the args to true will yield the list style.
530
+ * false = the grid style.
531
+ */
532
+ export function setBrowseTreeStyle(browsableStyle, playableStyle) {
533
+ if (!isAndroid)
534
+ return null;
535
+ TrackPlayer.setBrowseTreeStyle(browsableStyle, playableStyle);
536
+ return null;
537
+ }
538
+ /**
539
+ * acquires the wake lock of MusicService (android only.)
540
+ */
541
+ export async function acquireWakeLock() {
542
+ if (!isAndroid)
543
+ return;
544
+ TrackPlayer.acquireWakeLock();
545
+ }
546
+ /**
547
+ * acquires the wake lock of MusicService (android only.)
548
+ */
549
+ export async function abandonWakeLock() {
550
+ if (!isAndroid)
551
+ return;
552
+ TrackPlayer.abandonWakeLock();
553
+ }
554
+ /**
555
+ * prepare to crossfade (android only.) the crossfade alternate
556
+ * player will be automatically primed to the current player's index,
557
+ * then by previous = true or not, skip to previous or next. player
558
+ * will be prepared. its advised to call this well before actually performing
559
+ * crossfade so the resource can be prepared.
560
+ */
561
+ export async function crossFadePrepare(previous = false, seekTo = 0) {
562
+ if (!isAndroid)
563
+ return;
564
+ TrackPlayer.crossFadePrepare(previous, seekTo);
565
+ }
566
+ /**
567
+ * perform crossfade (android only).
568
+ *
569
+ * fadeDuration and fadeInterval are both in ms.
570
+ *
571
+ * fadeToVolume is a float from 0-1.
572
+ *
573
+ * waitUntil is in ms.
574
+ */
575
+ export async function crossFade(fadeDuration = 2000, fadeInterval = 20, fadeToVolume = 1, waitUntil = 0) {
576
+ if (!isAndroid)
577
+ return;
578
+ TrackPlayer.switchExoPlayer(fadeDuration, fadeInterval, fadeToVolume, waitUntil);
579
+ }
580
+ /**
581
+ * get the last connected package. non android will return undefined.
582
+ *
583
+ * android without a connected package (either system.UI, android auto, or media controller) yet
584
+ * will return ''; else will be one of the three.
585
+ *
586
+ * I intend to use this to determine if app crashed from android auto.
587
+ */
588
+ export async function getLastConnectedPackage() {
589
+ if (!isAndroid)
590
+ return;
591
+ return TrackPlayer.getLastConnectedPackage();
592
+ }
package/package.json ADDED
@@ -0,0 +1,94 @@
1
+ {
2
+ "name": "react-native-mp3-player",
3
+ "version": "1.0.0",
4
+ "description": "React Native audio player with reliable iOS background playback. Media controls, queue, hooks. Built for stability and long-running playback.",
5
+ "main": "lib/src/index.js",
6
+ "types": "lib/src/index.d.ts",
7
+ "react-native": "src/index",
8
+ "source": "src/index",
9
+ "scripts": {
10
+ "build": "rimraf lib && tsc",
11
+ "dev": "tsc --watch",
12
+ "format": "prettier --write src",
13
+ "types": "tsc --noEmit true",
14
+ "prepare": "npm run build",
15
+ "example": "npm run start --prefix example",
16
+ "pods": "cd example/ios && pod install",
17
+ "bootstrap": "npm install --prefix example && npm install && npm run pods",
18
+ "ci:format": "prettier --check src"
19
+ },
20
+ "files": [
21
+ "src",
22
+ "lib/**/*",
23
+ "ios/**/*",
24
+ "android/src/**/*",
25
+ "android/build.gradle",
26
+ "android/build.gradle.kts",
27
+ "android/proguard-rules.txt",
28
+ "react-native-mp3-player.podspec",
29
+ "specs"
30
+ ],
31
+ "contributors": [
32
+ {
33
+ "name": "David Chavez",
34
+ "email": "david@dcvz.io",
35
+ "url": "http://dcvz.io"
36
+ },
37
+ {
38
+ "name": "Guilherme Chaguri",
39
+ "email": "guichaguri@gmail.com",
40
+ "url": "http://guichaguri.com"
41
+ },
42
+ {
43
+ "name": "Dustin Bahr",
44
+ "email": "dustin@curiousmedia.com"
45
+ }
46
+ ],
47
+ "license": "Apache-2.0",
48
+ "repository": {
49
+ "type": "git",
50
+ "url": "https://github.com/alkarartech/react-native-mp3-player.git"
51
+ },
52
+ "bugs": {
53
+ "url": "https://github.com/alkarartech/react-native-mp3-player/issues"
54
+ },
55
+ "homepage": "https://github.com/alkarartech/react-native-mp3-player#readme",
56
+ "keywords": [
57
+ "react",
58
+ "react-native",
59
+ "audio-player",
60
+ "mp3",
61
+ "music",
62
+ "background-audio",
63
+ "media-controls",
64
+ "hooks"
65
+ ],
66
+ "codegenConfig": {
67
+ "name": "NativeTrackPlayerSpec",
68
+ "type": "modules",
69
+ "jsSrcsDir": "specs",
70
+ "android": {
71
+ "javaPackageName": "com.doublesymmetry.trackplayer"
72
+ },
73
+ "ios": {
74
+ "modulesProvider": {
75
+ "TrackPlayer": "NativeTrackPlayer"
76
+ }
77
+ }
78
+ },
79
+ "peerDependencies": {
80
+ "react": "*",
81
+ "react-native": "*"
82
+ },
83
+ "devDependencies": {
84
+ "@react-native-community/cli": "20.0.0",
85
+ "@react-native/babel-preset": "0.81.1",
86
+ "@types/react": "^19.1.0",
87
+ "del-cli": "^5.1.0",
88
+ "prettier": "^3.0.3",
89
+ "react": "19.1.0",
90
+ "react-native": "0.81.1",
91
+ "rimraf": "^5.0.0",
92
+ "typescript": "^5.8.3"
93
+ }
94
+ }
@@ -0,0 +1,22 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = "react-native-track-player"
7
+ s.version = package["version"]
8
+ s.summary = package["description"]
9
+ s.license = package["license"]
10
+
11
+ s.author = "David Chavez"
12
+ s.homepage = package["repository"]["url"]
13
+ s.platform = :ios, "11.0"
14
+
15
+ s.source = { :git => package["repository"]["url"], :tag => "v#{s.version}" }
16
+ s.source_files = "ios/**/*.{h,m,mm,swift}"
17
+ s.exclude_files = [ 'ios/Example', 'ios/SwiftAudioEx/Package.swift' ]
18
+
19
+ s.swift_version = "4.2"
20
+
21
+ install_modules_dependencies(s)
22
+ end