@javascriptcommon/react-native-track-player 1.2.23 → 4.1.4
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.
- package/LICENSE +201 -21
- package/README.md +8 -0
- package/android/build.gradle +80 -63
- package/android/proguard-rules.txt +0 -3
- package/android/src/main/AndroidManifest.xml +10 -11
- package/android/src/main/java/com/doublesymmetry/trackplayer/HeadlessJsMediaService.kt +199 -0
- package/android/src/main/java/com/doublesymmetry/trackplayer/TrackPlayer.kt +33 -0
- package/android/src/main/java/com/{guichaguri → doublesymmetry}/trackplayer/extensions/AudioPlayerStateExt.kt +3 -3
- package/android/src/main/java/com/doublesymmetry/trackplayer/extensions/EnumExtensions.kt +5 -0
- package/android/src/main/java/com/doublesymmetry/trackplayer/extensions/NumberExt.kt +13 -0
- package/android/src/main/java/com/{guichaguri → doublesymmetry}/trackplayer/model/MetadataAdapter.kt +20 -17
- package/android/src/main/java/com/doublesymmetry/trackplayer/model/NowPlayingMetadata.kt +16 -0
- package/android/src/main/java/com/{guichaguri/trackplayer/kotlinaudio/models → doublesymmetry/trackplayer/model}/PlaybackMetadata.kt +31 -28
- package/android/src/main/java/com/{guichaguri → doublesymmetry}/trackplayer/model/State.kt +1 -1
- package/android/src/main/java/com/doublesymmetry/trackplayer/model/Track.kt +67 -0
- package/android/src/main/java/com/doublesymmetry/trackplayer/model/TrackAudioItem.kt +18 -0
- package/android/src/main/java/com/doublesymmetry/trackplayer/model/TrackMetadata.kt +38 -0
- package/android/src/main/java/com/{guichaguri → doublesymmetry}/trackplayer/module/MusicEvents.kt +10 -9
- package/android/src/main/java/com/doublesymmetry/trackplayer/module/MusicModule.kt +778 -0
- package/android/src/main/java/com/doublesymmetry/trackplayer/service/MusicService.kt +1286 -0
- package/android/src/main/java/com/doublesymmetry/trackplayer/utils/AppForegroundTracker.kt +35 -0
- package/android/src/main/java/com/{guichaguri/trackplayer/service → doublesymmetry/trackplayer/utils}/BundleUtils.kt +50 -20
- package/android/src/main/java/com/doublesymmetry/trackplayer/utils/CoilBitmapLoader.kt +65 -0
- package/android/src/main/java/com/doublesymmetry/trackplayer/utils/MediaItemBuilder.kt +41 -0
- package/android/src/main/java/com/doublesymmetry/trackplayer/utils/RejectionException.kt +11 -0
- package/android/src/main/java/com/doublesymmetry/trackplayer/video/TrackPlayerVideoView.kt +42 -0
- package/android/src/main/java/com/doublesymmetry/trackplayer/video/TrackPlayerVideoViewManager.kt +18 -0
- package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/event/EventHolder.kt +7 -7
- package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/event/PlayerEventHolder.kt +22 -9
- package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/models/AudioContentType.kt +1 -1
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/AudioItem.kt +118 -0
- package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/models/AudioItemTransitionReason.kt +3 -3
- package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/models/AudioPlayerState.kt +2 -2
- package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/models/BufferConfig.kt +1 -1
- package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/models/CacheConfig.kt +1 -1
- package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/models/Capability.kt +1 -1
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/CustomButton.kt +19 -0
- package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/models/FocusChangeData.kt +1 -1
- package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/models/MediaSessionCallback.kt +1 -1
- package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/models/PlayWhenReadyChangeData.kt +1 -3
- package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/models/PlaybackEndedReason.kt +1 -1
- package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/models/PlaybackError.kt +1 -1
- package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/models/PlayerConfig.kt +8 -5
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/PlayerOptions.kt +40 -0
- package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/models/PositionChangedReason.kt +1 -1
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/RepeatMode.kt +16 -0
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/WakeMode.kt +7 -0
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/player/AudioPlayer.kt +756 -0
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/player/ForwardingPlayer.java +1124 -0
- package/android/src/main/java/com/{guichaguri/trackplayer/kotlinaudio/players → lovegaoshi/kotlinaudio/player}/QueuedAudioPlayer.kt +68 -58
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/player/components/APMRenderersFactory.kt +33 -0
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/player/components/Buffer.kt +34 -0
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/player/components/Cache.kt +27 -0
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/player/components/FocusManager.kt +59 -0
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/player/components/MediaFactory.kt +130 -0
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/processors/TeeListener.kt +171 -0
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/service/MusicService.kt +127 -0
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/utils/FFT.java +99 -0
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/utils/Utils.kt +113 -0
- package/android/src/main/res/drawable/baseline_repeat_24.xml +5 -0
- package/android/src/main/res/drawable/baseline_repeat_one_24.xml +5 -0
- package/android/src/main/res/drawable/forward.xml +5 -0
- package/android/src/main/res/drawable/heart_24px.xml +5 -0
- package/android/src/main/res/drawable/hearte_24px.xml +5 -0
- package/android/src/main/res/drawable/ifl_24px.xml +5 -0
- package/android/src/main/res/drawable/rewind.xml +5 -0
- package/android/src/main/res/drawable/shuffle_24px.xml +5 -0
- package/android/src/main/res/values/strings.xml +3 -4
- package/android/src/main/res/xml/automotive_app_desc.xml +3 -0
- package/ios/Example/SwiftAudio/Assets.xcassets/22AMI.imageset/22AMillion.jpg +0 -0
- package/ios/Example/SwiftAudio/Assets.xcassets/22AMI.imageset/Contents.json +21 -0
- package/ios/Example/SwiftAudio/Assets.xcassets/AccentColor.colorset/Contents.json +11 -0
- package/ios/Example/SwiftAudio/Assets.xcassets/AppIcon.appiconset/Contents.json +58 -0
- package/ios/Example/SwiftAudio/Assets.xcassets/Contents.json +6 -0
- package/ios/Example/SwiftAudio/Assets.xcassets/cover.imageset/Contents.json +21 -0
- package/ios/Example/SwiftAudio/Assets.xcassets/cover.imageset/cover.jpg +0 -0
- package/ios/Example/SwiftAudio/AudioController.swift +46 -0
- package/ios/Example/SwiftAudio/Extensions.swift +22 -0
- package/ios/Example/SwiftAudio/PlayerView.swift +172 -0
- package/ios/Example/SwiftAudio/PlayerViewModel.swift +120 -0
- package/ios/Example/SwiftAudio/Preview Content/Preview Assets.xcassets/Contents.json +6 -0
- package/ios/Example/SwiftAudio/QueueView.swift +65 -0
- package/ios/{TrackPlayer.xcodeproj/xcuserdata/marco.xcuserdatad/xcschemes/xcschememanagement.plist → Example/SwiftAudio/SwiftAudio.entitlements} +6 -8
- package/ios/Example/SwiftAudio/SwiftAudioApp.swift +17 -0
- package/ios/Example/SwiftAudio.xcodeproj/project.pbxproj +412 -0
- package/ios/{TrackPlayer.xcodeproj → Example/SwiftAudio.xcodeproj}/project.xcworkspace/contents.xcworkspacedata +1 -1
- package/ios/RNTrackPlayer/Models/Capabilities.swift +39 -4
- package/ios/RNTrackPlayer/Models/MediaURL.swift +12 -6
- package/ios/RNTrackPlayer/Models/MetadataAdapter.swift +147 -0
- package/ios/RNTrackPlayer/Models/PitchAlgorithms.swift +13 -0
- package/ios/RNTrackPlayer/Models/SessionCategories.swift +106 -0
- package/ios/RNTrackPlayer/Models/State.swift +26 -0
- package/ios/RNTrackPlayer/Models/Track.swift +74 -54
- package/ios/RNTrackPlayer/RNTrackPlayer.swift +867 -406
- package/ios/RNTrackPlayer/Support/RNTrackPlayer-Bridging-Header.h +1 -0
- package/ios/RNTrackPlayer/TrackPlayer.h +14 -0
- package/ios/RNTrackPlayer/TrackPlayer.mm +249 -0
- package/ios/RNTrackPlayer/Utils/EventType.swift +45 -0
- package/ios/RNTrackPlayer/Utils/Metadata.swift +60 -0
- package/ios/RNTrackPlayer/Video/RNTrackPlayerVideoView.swift +83 -0
- package/ios/RNTrackPlayer/Video/RNTrackPlayerVideoViewManager.m +5 -0
- package/ios/RNTrackPlayer/Video/RNTrackPlayerVideoViewManager.swift +17 -0
- package/ios/SwiftAudioEx/Package.swift +20 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/AVPlayerWrapper/AVPlayerWrapper.swift +531 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/AVPlayerWrapper/AVPlayerWrapperDelegate.swift +27 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/AVPlayerWrapper/AVPlayerWrapperProtocol.swift +69 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/AVPlayerWrapper/AVPlayerWrapperState.swift +43 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/AudioItem.swift +158 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/AudioPlayer.swift +459 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/AudioPlayerError.swift +26 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/AudioSessionController/AudioSession.swift +33 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/AudioSessionController/AudioSessionController.swift +135 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/AudioTap.swift +96 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/Event.swift +155 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/NowPlayingInfoController/MediaItemProperty.swift +95 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/NowPlayingInfoController/NowPlayingInfoCenter.swift +17 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/NowPlayingInfoController/NowPlayingInfoController.swift +73 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/NowPlayingInfoController/NowPlayingInfoControllerProtocol.swift +26 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/NowPlayingInfoController/NowPlayingInfoKeyValue.swift +14 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/NowPlayingInfoController/NowPlayingInfoProperty.swift +234 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/Observer/AVPlayerItemNotificationObserver.swift +102 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/Observer/AVPlayerItemObserver.swift +136 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/Observer/AVPlayerObserver.swift +120 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/Observer/AVPlayerTimeObserver.swift +112 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/QueueManager.swift +356 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/QueuedAudioPlayer.swift +236 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/RemoteCommandController/RemoteCommand.swift +170 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/RemoteCommandController/RemoteCommandController.swift +206 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/RepeatMode.swift +15 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/TimeEventFrequency.swift +26 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/Utils/DispatchQueueType.swift +18 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/WaveformAudioTap.swift +159 -0
- package/lib/specs/NativeTrackPlayer.d.ts +134 -0
- package/lib/specs/NativeTrackPlayer.js +4 -0
- package/lib/src/TrackPlayerModule.web.d.ts +2 -0
- package/lib/src/TrackPlayerModule.web.js +2 -0
- package/lib/src/VideoView.d.ts +16 -0
- package/lib/src/VideoView.js +25 -0
- package/lib/src/constants/AndroidAudioContentType.d.ts +35 -0
- package/lib/src/constants/AndroidAudioContentType.js +36 -0
- package/lib/src/constants/AndroidAutoContentStyle.d.ts +10 -0
- package/lib/src/constants/AndroidAutoContentStyle.js +11 -0
- package/lib/src/constants/AppKilledPlaybackBehavior.d.ts +17 -0
- package/lib/src/constants/AppKilledPlaybackBehavior.js +18 -0
- package/lib/src/constants/Capability.d.ts +17 -0
- package/lib/src/constants/Capability.js +19 -0
- package/lib/src/constants/Event.d.ts +172 -0
- package/lib/src/constants/Event.js +173 -0
- package/lib/src/constants/IOSCategory.d.ts +36 -0
- package/lib/src/constants/IOSCategory.js +37 -0
- package/lib/src/constants/IOSCategoryMode.d.ts +47 -0
- package/lib/src/constants/IOSCategoryMode.js +48 -0
- package/lib/src/constants/IOSCategoryOptions.d.ts +44 -0
- package/lib/src/constants/IOSCategoryOptions.js +45 -0
- package/lib/src/constants/MediaItemPlayable.d.ts +4 -0
- package/lib/src/constants/MediaItemPlayable.js +5 -0
- package/lib/src/constants/PitchAlgorithm.d.ts +14 -0
- package/lib/src/constants/PitchAlgorithm.js +16 -0
- package/lib/src/constants/RatingType.d.ts +8 -0
- package/lib/src/constants/RatingType.js +10 -0
- package/lib/src/constants/RepeatMode.d.ts +8 -0
- package/lib/src/constants/RepeatMode.js +10 -0
- package/lib/src/constants/State.d.ts +34 -0
- package/lib/src/constants/State.js +35 -0
- package/lib/src/constants/TrackType.d.ts +6 -0
- package/lib/src/constants/TrackType.js +7 -0
- package/lib/src/constants/index.d.ts +14 -0
- package/lib/src/constants/index.js +14 -0
- package/lib/src/hooks/index.d.ts +6 -0
- package/lib/src/hooks/index.js +6 -0
- package/lib/src/hooks/useActiveTrack.d.ts +2 -0
- package/lib/src/hooks/useActiveTrack.js +28 -0
- package/lib/src/hooks/useAppIsInBackground.d.ts +1 -0
- package/lib/src/hooks/useAppIsInBackground.js +16 -0
- package/lib/src/hooks/useIsPlaying.d.ts +35 -0
- package/lib/src/hooks/useIsPlaying.js +50 -0
- package/lib/src/hooks/usePlayWhenReady.d.ts +1 -0
- package/lib/src/hooks/usePlayWhenReady.js +27 -0
- package/lib/src/hooks/usePlaybackState.d.ts +10 -0
- package/lib/src/hooks/usePlaybackState.js +35 -0
- package/lib/src/hooks/useProgress.d.ts +7 -0
- package/lib/src/hooks/useProgress.js +55 -0
- package/lib/src/hooks/useTrackPlayerEvents.d.ts +8 -0
- package/lib/src/hooks/useTrackPlayerEvents.js +30 -0
- package/lib/src/index.d.ts +6 -0
- package/lib/src/index.js +6 -0
- package/lib/src/interfaces/AndroidAutoBrowseTree.d.ts +5 -0
- package/lib/src/interfaces/AndroidAutoBrowseTree.js +1 -0
- package/lib/src/interfaces/AndroidOptions.d.ts +41 -0
- package/lib/src/interfaces/AndroidOptions.js +1 -0
- package/lib/src/interfaces/CustomButtons.d.ts +5 -0
- package/lib/src/interfaces/CustomButtons.js +1 -0
- package/lib/src/interfaces/FeedbackOptions.d.ts +6 -0
- package/lib/src/interfaces/FeedbackOptions.js +1 -0
- package/lib/src/interfaces/MediaItem.d.ts +18 -0
- package/lib/src/interfaces/MediaItem.js +1 -0
- package/lib/src/interfaces/MetadataOptions.d.ts +3 -0
- package/lib/src/interfaces/MetadataOptions.js +1 -0
- package/lib/src/interfaces/NowPlayingMetadata.d.ts +4 -0
- package/lib/src/interfaces/NowPlayingMetadata.js +1 -0
- package/lib/src/interfaces/PlaybackState.d.ts +8 -0
- package/lib/src/interfaces/PlaybackState.js +1 -0
- package/lib/src/interfaces/PlayerOptions.d.ts +132 -0
- package/lib/src/interfaces/PlayerOptions.js +1 -0
- package/lib/src/interfaces/Progress.d.ts +15 -0
- package/lib/src/interfaces/Progress.js +1 -0
- package/lib/src/interfaces/ResourceObject.d.ts +1 -0
- package/lib/src/interfaces/ResourceObject.js +1 -0
- package/lib/src/interfaces/ServiceHandler.d.ts +1 -0
- package/lib/src/interfaces/ServiceHandler.js +1 -0
- package/lib/src/interfaces/Track.d.ts +21 -0
- package/lib/src/interfaces/Track.js +1 -0
- package/lib/src/interfaces/TrackMetadataBase.d.ts +28 -0
- package/lib/src/interfaces/TrackMetadataBase.js +1 -0
- package/lib/src/interfaces/UpdateOptions.d.ts +52 -0
- package/lib/src/interfaces/UpdateOptions.js +1 -0
- package/lib/src/interfaces/events/AudioMetadataReceivedEvent.d.ts +33 -0
- package/lib/src/interfaces/events/AudioMetadataReceivedEvent.js +1 -0
- package/lib/src/interfaces/events/ControllerConnectedEvent.d.ts +8 -0
- package/lib/src/interfaces/events/ControllerConnectedEvent.js +1 -0
- package/lib/src/interfaces/events/EventPayloadByEvent.d.ts +77 -0
- package/lib/src/interfaces/events/EventPayloadByEvent.js +1 -0
- package/lib/src/interfaces/events/FFTUpdateEvent.d.ts +7 -0
- package/lib/src/interfaces/events/FFTUpdateEvent.js +1 -0
- package/lib/src/interfaces/events/PlaybackActiveTrackChangedEvent.d.ts +24 -0
- package/lib/src/interfaces/events/PlaybackActiveTrackChangedEvent.js +1 -0
- package/lib/src/interfaces/events/PlaybackAnimatedVolumeChangedEvent.d.ts +4 -0
- package/lib/src/interfaces/events/PlaybackAnimatedVolumeChangedEvent.js +1 -0
- package/lib/src/interfaces/events/PlaybackErrorEvent.d.ts +6 -0
- package/lib/src/interfaces/events/PlaybackErrorEvent.js +1 -0
- package/lib/src/interfaces/events/PlaybackMetadataReceivedEvent.d.ts +16 -0
- package/lib/src/interfaces/events/PlaybackMetadataReceivedEvent.js +1 -0
- package/lib/src/interfaces/events/PlaybackPlayWhenReadyChangedEvent.d.ts +4 -0
- package/lib/src/interfaces/events/PlaybackPlayWhenReadyChangedEvent.js +1 -0
- package/lib/src/interfaces/events/PlaybackProgressUpdatedEvent.d.ts +4 -0
- package/lib/src/interfaces/events/PlaybackProgressUpdatedEvent.js +1 -0
- package/lib/src/interfaces/events/PlaybackQueueEndedEvent.d.ts +9 -0
- package/lib/src/interfaces/events/PlaybackQueueEndedEvent.js +1 -0
- package/lib/src/interfaces/events/PlaybackResumeEvent.d.ts +3 -0
- package/lib/src/interfaces/events/PlaybackResumeEvent.js +1 -0
- package/lib/src/interfaces/events/PlaybackTrackChangedEvent.d.ts +11 -0
- package/lib/src/interfaces/events/PlaybackTrackChangedEvent.js +1 -0
- package/lib/src/interfaces/events/PlayerErrorEvent.d.ts +6 -0
- package/lib/src/interfaces/events/PlayerErrorEvent.js +1 -0
- package/lib/src/interfaces/events/RemoteBrowseEvent.d.ts +4 -0
- package/lib/src/interfaces/events/RemoteBrowseEvent.js +1 -0
- package/lib/src/interfaces/events/RemoteCustomActionEvent.d.ts +7 -0
- package/lib/src/interfaces/events/RemoteCustomActionEvent.js +1 -0
- package/lib/src/interfaces/events/RemoteDuckEvent.d.ts +13 -0
- package/lib/src/interfaces/events/RemoteDuckEvent.js +1 -0
- package/lib/src/interfaces/events/RemoteJumpBackwardEvent.d.ts +7 -0
- package/lib/src/interfaces/events/RemoteJumpBackwardEvent.js +1 -0
- package/lib/src/interfaces/events/RemoteJumpForwardEvent.d.ts +7 -0
- package/lib/src/interfaces/events/RemoteJumpForwardEvent.js +1 -0
- package/lib/src/interfaces/events/RemotePlayIdEvent.d.ts +4 -0
- package/lib/src/interfaces/events/RemotePlayIdEvent.js +1 -0
- package/lib/src/interfaces/events/RemotePlaySearchEvent.d.ts +9 -0
- package/lib/src/interfaces/events/RemotePlaySearchEvent.js +1 -0
- package/lib/src/interfaces/events/RemoteSearchEvent.d.ts +3 -0
- package/lib/src/interfaces/events/RemoteSearchEvent.js +1 -0
- package/lib/src/interfaces/events/RemoteSeekEvent.d.ts +4 -0
- package/lib/src/interfaces/events/RemoteSeekEvent.js +1 -0
- package/lib/src/interfaces/events/RemoteSetRatingEvent.d.ts +4 -0
- package/lib/src/interfaces/events/RemoteSetRatingEvent.js +1 -0
- package/lib/src/interfaces/events/RemoteSkipEvent.d.ts +3 -0
- package/lib/src/interfaces/events/RemoteSkipEvent.js +1 -0
- package/lib/src/interfaces/events/index.d.ts +20 -0
- package/lib/src/interfaces/events/index.js +20 -0
- package/lib/src/interfaces/index.d.ts +15 -0
- package/lib/src/interfaces/index.js +15 -0
- package/lib/src/resolveAssetSource.d.ts +2 -0
- package/lib/src/resolveAssetSource.js +3 -0
- package/lib/src/resolveAssetSource.web.d.ts +2 -0
- package/lib/src/resolveAssetSource.web.js +8 -0
- package/lib/src/trackPlayer.d.ts +371 -0
- package/lib/src/trackPlayer.js +627 -0
- package/lib/web/TrackPlayer/Player.d.ts +40 -0
- package/lib/web/TrackPlayer/Player.js +188 -0
- package/lib/web/TrackPlayer/PlaylistPlayer.d.ts +31 -0
- package/lib/web/TrackPlayer/PlaylistPlayer.js +181 -0
- package/lib/web/TrackPlayer/RepeatMode.d.ts +5 -0
- package/lib/web/TrackPlayer/RepeatMode.js +6 -0
- package/lib/web/TrackPlayer/SetupNotCalledError.d.ts +3 -0
- package/lib/web/TrackPlayer/SetupNotCalledError.js +5 -0
- package/lib/web/TrackPlayer/index.d.ts +3 -0
- package/lib/web/TrackPlayer/index.js +3 -0
- package/lib/web/TrackPlayerModule.d.ts +63 -0
- package/lib/web/TrackPlayerModule.js +153 -0
- package/lib/web/index.d.ts +3 -0
- package/lib/web/index.js +3 -0
- package/package.json +85 -6
- package/react-native-track-player.podspec +13 -13
- package/specs/NativeTrackPlayer.ts +153 -0
- package/src/TrackPlayerModule.web.ts +2 -0
- package/src/VideoView.tsx +51 -0
- package/src/constants/AndroidAudioContentType.ts +35 -0
- package/src/constants/AndroidAutoContentStyle.ts +10 -0
- package/src/constants/AppKilledPlaybackBehavior.ts +19 -0
- package/src/constants/Capability.ts +19 -0
- package/src/constants/Event.ts +173 -0
- package/src/constants/IOSCategory.ts +36 -0
- package/src/constants/IOSCategoryMode.ts +47 -0
- package/src/constants/IOSCategoryOptions.ts +44 -0
- package/src/constants/MediaItemPlayable.ts +4 -0
- package/src/constants/PitchAlgorithm.ts +16 -0
- package/src/constants/RatingType.ts +10 -0
- package/src/constants/RepeatMode.ts +10 -0
- package/src/constants/State.ts +34 -0
- package/src/constants/TrackType.ts +6 -0
- package/src/constants/index.ts +14 -0
- package/src/hooks/index.ts +6 -0
- package/src/hooks/useActiveTrack.ts +36 -0
- package/src/hooks/useAppIsInBackground.ts +20 -0
- package/src/hooks/useIsPlaying.ts +56 -0
- package/src/hooks/usePlayWhenReady.ts +37 -0
- package/src/hooks/usePlaybackState.ts +45 -0
- package/src/hooks/useProgress.ts +64 -0
- package/src/hooks/useTrackPlayerEvents.ts +48 -0
- package/src/index.ts +8 -0
- package/src/interfaces/AndroidAutoBrowseTree.ts +6 -0
- package/src/interfaces/AndroidOptions.ts +48 -0
- package/src/interfaces/CustomButtons.ts +6 -0
- package/src/interfaces/FeedbackOptions.ts +7 -0
- package/src/interfaces/MediaItem.ts +19 -0
- package/src/interfaces/MetadataOptions.ts +4 -0
- package/src/interfaces/NowPlayingMetadata.ts +5 -0
- package/src/interfaces/PlaybackState.ts +11 -0
- package/src/interfaces/PlayerOptions.ts +138 -0
- package/src/interfaces/Progress.ts +15 -0
- package/src/interfaces/ResourceObject.ts +1 -0
- package/src/interfaces/ServiceHandler.ts +1 -0
- package/src/interfaces/Track.ts +23 -0
- package/src/interfaces/TrackMetadataBase.ts +29 -0
- package/src/interfaces/UpdateOptions.ts +59 -0
- package/src/interfaces/events/AudioMetadataReceivedEvent.ts +37 -0
- package/src/interfaces/events/ControllerConnectedEvent.ts +9 -0
- package/src/interfaces/events/EventPayloadByEvent.ts +80 -0
- package/src/interfaces/events/FFTUpdateEvent.ts +9 -0
- package/src/interfaces/events/PlaybackActiveTrackChangedEvent.ts +29 -0
- package/src/interfaces/events/PlaybackAnimatedVolumeChangedEvent.ts +4 -0
- package/src/interfaces/events/PlaybackErrorEvent.ts +6 -0
- package/src/interfaces/events/PlaybackMetadataReceivedEvent.ts +16 -0
- package/src/interfaces/events/PlaybackPlayWhenReadyChangedEvent.ts +4 -0
- package/src/interfaces/events/PlaybackProgressUpdatedEvent.ts +5 -0
- package/src/interfaces/events/PlaybackQueueEndedEvent.ts +9 -0
- package/src/interfaces/events/PlaybackResumeEvent.ts +5 -0
- package/src/interfaces/events/PlaybackTrackChangedEvent.ts +11 -0
- package/src/interfaces/events/PlayerErrorEvent.ts +6 -0
- package/src/interfaces/events/RemoteBrowseEvent.ts +4 -0
- package/src/interfaces/events/RemoteCustomActionEvent.ts +7 -0
- package/src/interfaces/events/RemoteDuckEvent.ts +13 -0
- package/src/interfaces/events/RemoteJumpBackwardEvent.ts +7 -0
- package/src/interfaces/events/RemoteJumpForwardEvent.ts +7 -0
- package/src/interfaces/events/RemotePlayIdEvent.ts +4 -0
- package/src/interfaces/events/RemotePlaySearchEvent.ts +21 -0
- package/src/interfaces/events/RemoteSearchEvent.ts +3 -0
- package/src/interfaces/events/RemoteSeekEvent.ts +4 -0
- package/src/interfaces/events/RemoteSetRatingEvent.ts +5 -0
- package/src/interfaces/events/RemoteSkipEvent.ts +3 -0
- package/src/interfaces/events/index.ts +20 -0
- package/src/interfaces/index.ts +15 -0
- package/src/resolveAssetSource.ts +3 -0
- package/src/resolveAssetSource.web.ts +10 -0
- package/src/trackPlayer.ts +806 -0
- package/web/TrackPlayer/Player.ts +201 -0
- package/web/TrackPlayer/PlaylistPlayer.ts +215 -0
- package/web/TrackPlayer/RepeatMode.ts +6 -0
- package/web/TrackPlayer/SetupNotCalledError.ts +5 -0
- package/web/TrackPlayer/index.ts +3 -0
- package/web/TrackPlayerModule.ts +181 -0
- package/web/index.ts +4 -0
- package/CHANGELOG.md +0 -75
- package/android/react-native-music-control.iml +0 -139
- package/android/react-native-track-player.iml +0 -151
- package/android/src/main/ic_home-playstore.png +0 -0
- package/android/src/main/ic_repeat-playstore.png +0 -0
- package/android/src/main/ic_repeat_50-playstore.png +0 -0
- package/android/src/main/ic_shuffle-playstore.png +0 -0
- package/android/src/main/ic_shuffle_50-playstore.png +0 -0
- package/android/src/main/ic_shuffle_sm-playstore.png +0 -0
- package/android/src/main/ic_stop-playstore.png +0 -0
- package/android/src/main/ic_test-playstore.png +0 -0
- package/android/src/main/java/com/guichaguri/trackplayer/HeadlessJsMediaService.java +0 -225
- package/android/src/main/java/com/guichaguri/trackplayer/TrackPlayer.kt +0 -25
- package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/event/NotificationEventHolder.kt +0 -20
- package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/models/AAMediaSessionCallback.kt +0 -10
- package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/models/AudioItem.kt +0 -66
- package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/models/NotificationConfig.kt +0 -43
- package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/models/NotificationMetadata.kt +0 -8
- package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/models/NotificationState.kt +0 -8
- package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/models/PlayerOptions.kt +0 -9
- package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/models/QueuedPlayerOptions.kt +0 -49
- package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/notification/NotificationManager.kt +0 -678
- package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/players/AudioPlayer.kt +0 -10
- package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/players/BaseAudioPlayer.kt +0 -864
- package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/players/components/MediaSourceExt.kt +0 -35
- package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/players/components/PlayerCache.kt +0 -26
- package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/utils/Utils.kt +0 -12
- package/android/src/main/java/com/guichaguri/trackplayer/model/Track.kt +0 -120
- package/android/src/main/java/com/guichaguri/trackplayer/model/TrackAudioItem.kt +0 -19
- package/android/src/main/java/com/guichaguri/trackplayer/model/TrackType.kt +0 -11
- package/android/src/main/java/com/guichaguri/trackplayer/module/AutoConnectionDetector.kt +0 -151
- package/android/src/main/java/com/guichaguri/trackplayer/module/MusicModule.kt +0 -1177
- package/android/src/main/java/com/guichaguri/trackplayer/service/MusicBinder.kt +0 -31
- package/android/src/main/java/com/guichaguri/trackplayer/service/MusicManager.kt +0 -347
- package/android/src/main/java/com/guichaguri/trackplayer/service/MusicService.kt +0 -1254
- package/android/src/main/java/com/guichaguri/trackplayer/service/Utils.kt +0 -228
- package/android/src/main/java/com/guichaguri/trackplayer/service/metadata/ButtonEvents.kt +0 -141
- package/android/src/main/java/com/guichaguri/trackplayer/service/metadata/MetadataManager.kt +0 -396
- package/android/src/main/res/drawable-hdpi/ic_forward.png +0 -0
- package/android/src/main/res/drawable-hdpi/ic_home.png +0 -0
- package/android/src/main/res/drawable-hdpi/ic_next.png +0 -0
- package/android/src/main/res/drawable-hdpi/ic_pause.png +0 -0
- package/android/src/main/res/drawable-hdpi/ic_play.png +0 -0
- package/android/src/main/res/drawable-hdpi/ic_previous.png +0 -0
- package/android/src/main/res/drawable-hdpi/ic_rewind.png +0 -0
- package/android/src/main/res/drawable-hdpi/ic_stop.png +0 -0
- package/android/src/main/res/drawable-mdpi/ic_forward.png +0 -0
- package/android/src/main/res/drawable-mdpi/ic_home.png +0 -0
- package/android/src/main/res/drawable-mdpi/ic_next.png +0 -0
- package/android/src/main/res/drawable-mdpi/ic_pause.png +0 -0
- package/android/src/main/res/drawable-mdpi/ic_play.png +0 -0
- package/android/src/main/res/drawable-mdpi/ic_previous.png +0 -0
- package/android/src/main/res/drawable-mdpi/ic_rewind.png +0 -0
- package/android/src/main/res/drawable-mdpi/ic_stop.png +0 -0
- package/android/src/main/res/drawable-xhdpi/ic_forward.png +0 -0
- package/android/src/main/res/drawable-xhdpi/ic_home.png +0 -0
- package/android/src/main/res/drawable-xhdpi/ic_next.png +0 -0
- package/android/src/main/res/drawable-xhdpi/ic_pause.png +0 -0
- package/android/src/main/res/drawable-xhdpi/ic_play.png +0 -0
- package/android/src/main/res/drawable-xhdpi/ic_previous.png +0 -0
- package/android/src/main/res/drawable-xhdpi/ic_rewind.png +0 -0
- package/android/src/main/res/drawable-xhdpi/ic_stop.png +0 -0
- package/android/src/main/res/drawable-xxhdpi/ic_forward.png +0 -0
- package/android/src/main/res/drawable-xxhdpi/ic_home.png +0 -0
- package/android/src/main/res/drawable-xxhdpi/ic_next.png +0 -0
- package/android/src/main/res/drawable-xxhdpi/ic_pause.png +0 -0
- package/android/src/main/res/drawable-xxhdpi/ic_play.png +0 -0
- package/android/src/main/res/drawable-xxhdpi/ic_previous.png +0 -0
- package/android/src/main/res/drawable-xxhdpi/ic_rewind.png +0 -0
- package/android/src/main/res/drawable-xxhdpi/ic_stop.png +0 -0
- package/android/src/main/res/drawable-xxxhdpi/ic_forward.png +0 -0
- package/android/src/main/res/drawable-xxxhdpi/ic_home.png +0 -0
- package/android/src/main/res/drawable-xxxhdpi/ic_next.png +0 -0
- package/android/src/main/res/drawable-xxxhdpi/ic_pause.png +0 -0
- package/android/src/main/res/drawable-xxxhdpi/ic_play.png +0 -0
- package/android/src/main/res/drawable-xxxhdpi/ic_previous.png +0 -0
- package/android/src/main/res/drawable-xxxhdpi/ic_rewind.png +0 -0
- package/android/src/main/res/drawable-xxxhdpi/ic_stop.png +0 -0
- package/android/src/main/res/mipmap-hdpi/ic_arrow_down_circle_foreground.png +0 -0
- package/android/src/main/res/mipmap-hdpi/ic_clock_now_foreground.png +0 -0
- package/android/src/main/res/mipmap-hdpi/ic_close_foreground.png +0 -0
- package/android/src/main/res/mipmap-hdpi/ic_heart_foreground.png +0 -0
- package/android/src/main/res/mipmap-hdpi/ic_heart_outlined_foreground.png +0 -0
- package/android/src/main/res/mipmap-hdpi/ic_repeat_off_foreground.png +0 -0
- package/android/src/main/res/mipmap-hdpi/ic_repeat_on_foreground.png +0 -0
- package/android/src/main/res/mipmap-hdpi/ic_shuffle_off_foreground.png +0 -0
- package/android/src/main/res/mipmap-hdpi/ic_shuffle_on_foreground.png +0 -0
- package/android/src/main/res/mipmap-mdpi/ic_arrow_down_circle_foreground.png +0 -0
- package/android/src/main/res/mipmap-mdpi/ic_clock_now_foreground.png +0 -0
- package/android/src/main/res/mipmap-mdpi/ic_close_foreground.png +0 -0
- package/android/src/main/res/mipmap-mdpi/ic_heart_foreground.png +0 -0
- package/android/src/main/res/mipmap-mdpi/ic_heart_outlined_foreground.png +0 -0
- package/android/src/main/res/mipmap-mdpi/ic_repeat_off_foreground.png +0 -0
- package/android/src/main/res/mipmap-mdpi/ic_repeat_on_foreground.png +0 -0
- package/android/src/main/res/mipmap-mdpi/ic_shuffle_off_foreground.png +0 -0
- package/android/src/main/res/mipmap-mdpi/ic_shuffle_on_foreground.png +0 -0
- package/android/src/main/res/mipmap-xhdpi/ic_arrow_down_circle_foreground.png +0 -0
- package/android/src/main/res/mipmap-xhdpi/ic_clock_now_foreground.png +0 -0
- package/android/src/main/res/mipmap-xhdpi/ic_close_foreground.png +0 -0
- package/android/src/main/res/mipmap-xhdpi/ic_heart_foreground.png +0 -0
- package/android/src/main/res/mipmap-xhdpi/ic_heart_outlined_foreground.png +0 -0
- package/android/src/main/res/mipmap-xhdpi/ic_repeat_off_foreground.png +0 -0
- package/android/src/main/res/mipmap-xhdpi/ic_repeat_on_foreground.png +0 -0
- package/android/src/main/res/mipmap-xhdpi/ic_shuffle_off_foreground.png +0 -0
- package/android/src/main/res/mipmap-xhdpi/ic_shuffle_on_foreground.png +0 -0
- package/android/src/main/res/mipmap-xxhdpi/ic_arrow_down_circle_foreground.png +0 -0
- package/android/src/main/res/mipmap-xxhdpi/ic_clock_now_foreground.png +0 -0
- package/android/src/main/res/mipmap-xxhdpi/ic_close_foreground.png +0 -0
- package/android/src/main/res/mipmap-xxhdpi/ic_heart_foreground.png +0 -0
- package/android/src/main/res/mipmap-xxhdpi/ic_heart_outlined_foreground.png +0 -0
- package/android/src/main/res/mipmap-xxhdpi/ic_repeat_off_foreground.png +0 -0
- package/android/src/main/res/mipmap-xxhdpi/ic_repeat_on_foreground.png +0 -0
- package/android/src/main/res/mipmap-xxhdpi/ic_shuffle_off_foreground.png +0 -0
- package/android/src/main/res/mipmap-xxhdpi/ic_shuffle_on_foreground.png +0 -0
- package/android/src/main/res/mipmap-xxxhdpi/ic_arrow_down_circle_foreground.png +0 -0
- package/android/src/main/res/mipmap-xxxhdpi/ic_clock_now_foreground.png +0 -0
- package/android/src/main/res/mipmap-xxxhdpi/ic_close_foreground.png +0 -0
- package/android/src/main/res/mipmap-xxxhdpi/ic_heart_foreground.png +0 -0
- package/android/src/main/res/mipmap-xxxhdpi/ic_heart_outlined_foreground.png +0 -0
- package/android/src/main/res/mipmap-xxxhdpi/ic_repeat_off_foreground.png +0 -0
- package/android/src/main/res/mipmap-xxxhdpi/ic_repeat_on_foreground.png +0 -0
- package/android/src/main/res/mipmap-xxxhdpi/ic_shuffle_off_foreground.png +0 -0
- package/android/src/main/res/mipmap-xxxhdpi/ic_shuffle_on_foreground.png +0 -0
- package/android/src/main/res/raw/silent_5_seconds.mp3 +0 -0
- package/android/src/main/res/strings.xml +0 -6
- package/index.d.ts +0 -235
- package/index.js +0 -4
- package/ios/RNTrackPlayer/RNTrackPlayerBridge.h +0 -12
- package/ios/RNTrackPlayer/RNTrackPlayerBridge.m +0 -29
- package/ios/TrackPlayer.xcodeproj/project.pbxproj +0 -495
- package/ios/TrackPlayer.xcodeproj/project.xcworkspace/xcuserdata/marco.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/lib/ProgressComponent.js +0 -70
- package/lib/eventTypes.js +0 -28
- package/lib/hooks.js +0 -160
- package/lib/index.js +0 -178
- /package/ios/{TrackPlayer.xcodeproj → Example/SwiftAudio.xcodeproj}/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -0
|
@@ -0,0 +1,806 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AppRegistry,
|
|
3
|
+
NativeEventEmitter,
|
|
4
|
+
Platform,
|
|
5
|
+
Animated,
|
|
6
|
+
} from 'react-native';
|
|
7
|
+
|
|
8
|
+
import { Event, RepeatMode, State, AndroidAutoContentStyle } from './constants';
|
|
9
|
+
import TrackPlayer from '../specs/NativeTrackPlayer';
|
|
10
|
+
import type {
|
|
11
|
+
AddTrack,
|
|
12
|
+
EventPayloadByEvent,
|
|
13
|
+
NowPlayingMetadata,
|
|
14
|
+
PlaybackState,
|
|
15
|
+
PlayerOptions,
|
|
16
|
+
Progress,
|
|
17
|
+
ServiceHandler,
|
|
18
|
+
Track,
|
|
19
|
+
TrackMetadataBase,
|
|
20
|
+
UpdateOptions,
|
|
21
|
+
AndroidAutoBrowseTree,
|
|
22
|
+
MediaItem,
|
|
23
|
+
} from './interfaces';
|
|
24
|
+
import resolveAssetSource from './resolveAssetSource';
|
|
25
|
+
|
|
26
|
+
const isAndroid = Platform.OS === 'android';
|
|
27
|
+
|
|
28
|
+
const emitter = new NativeEventEmitter(TrackPlayer);
|
|
29
|
+
|
|
30
|
+
const animatedVolume = new Animated.Value(1);
|
|
31
|
+
|
|
32
|
+
animatedVolume.addListener((state) => TrackPlayer.setVolume(state.value));
|
|
33
|
+
|
|
34
|
+
// MARK: - Helpers
|
|
35
|
+
|
|
36
|
+
function resolveImportedAssetOrPath(pathOrAsset: string | number | undefined) {
|
|
37
|
+
return pathOrAsset === undefined
|
|
38
|
+
? undefined
|
|
39
|
+
: typeof pathOrAsset === 'string'
|
|
40
|
+
? pathOrAsset
|
|
41
|
+
: resolveImportedAsset(pathOrAsset);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function resolveImportedAsset(id?: number) {
|
|
45
|
+
return id
|
|
46
|
+
? ((resolveAssetSource(id) as { uri: string } | null) ?? undefined)
|
|
47
|
+
: undefined;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// MARK: - General API
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Initializes the player with the specified options.
|
|
54
|
+
*
|
|
55
|
+
* Note that on Android this method must only be called while the app is in the
|
|
56
|
+
* foreground, otherwise it will throw an error with code
|
|
57
|
+
* `'android_cannot_setup_player_in_background'`. In this case you can wait for
|
|
58
|
+
* the app to be in the foreground and try again.
|
|
59
|
+
*
|
|
60
|
+
* @param options The options to initialize the player with.
|
|
61
|
+
* @see https://rntp.dev/docs/api/functions/lifecycle
|
|
62
|
+
*/
|
|
63
|
+
export async function setupPlayer(
|
|
64
|
+
options: PlayerOptions = {},
|
|
65
|
+
background = false,
|
|
66
|
+
): Promise<void> {
|
|
67
|
+
return TrackPlayer.setupPlayer(options, background);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Register the playback service. The service will run as long as the player runs.
|
|
72
|
+
*/
|
|
73
|
+
export function registerPlaybackService(factory: () => ServiceHandler) {
|
|
74
|
+
if (isAndroid) {
|
|
75
|
+
// Registers the headless task
|
|
76
|
+
AppRegistry.registerHeadlessTask('TrackPlayer', factory);
|
|
77
|
+
} else if (Platform.OS === 'web') {
|
|
78
|
+
factory()();
|
|
79
|
+
} else {
|
|
80
|
+
// Initializes and runs the service in the next tick
|
|
81
|
+
setImmediate(factory());
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function addEventListener<T extends Event>(
|
|
86
|
+
event: T,
|
|
87
|
+
listener: EventPayloadByEvent[T] extends never
|
|
88
|
+
? () => void
|
|
89
|
+
: (event: EventPayloadByEvent[T]) => void,
|
|
90
|
+
) {
|
|
91
|
+
return emitter.addListener(event, listener);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// MARK: - Queue API
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Adds one or more tracks to the queue.
|
|
98
|
+
*
|
|
99
|
+
* @param tracks The tracks to add to the queue.
|
|
100
|
+
* @param insertBeforeIndex (Optional) The index to insert the tracks before.
|
|
101
|
+
* By default the tracks will be added to the end of the queue.
|
|
102
|
+
*/
|
|
103
|
+
export async function add(
|
|
104
|
+
tracks: AddTrack[],
|
|
105
|
+
insertBeforeIndex?: number,
|
|
106
|
+
): Promise<number | void>;
|
|
107
|
+
/**
|
|
108
|
+
* Adds a track to the queue.
|
|
109
|
+
*
|
|
110
|
+
* @param track The track to add to the queue.
|
|
111
|
+
* @param insertBeforeIndex (Optional) The index to insert the track before.
|
|
112
|
+
* By default the track will be added to the end of the queue.
|
|
113
|
+
*/
|
|
114
|
+
export async function add(
|
|
115
|
+
track: AddTrack,
|
|
116
|
+
insertBeforeIndex?: number,
|
|
117
|
+
): Promise<number | void>;
|
|
118
|
+
export async function add(
|
|
119
|
+
tracks: AddTrack | AddTrack[],
|
|
120
|
+
insertBeforeIndex = -1,
|
|
121
|
+
): Promise<number | void> {
|
|
122
|
+
const resolvedTracks = (Array.isArray(tracks) ? tracks : [tracks]).map(
|
|
123
|
+
(track) => ({
|
|
124
|
+
...track,
|
|
125
|
+
url: resolveImportedAssetOrPath(track.url),
|
|
126
|
+
artwork: resolveImportedAssetOrPath(track.artwork),
|
|
127
|
+
}),
|
|
128
|
+
);
|
|
129
|
+
return resolvedTracks.length < 1
|
|
130
|
+
? undefined
|
|
131
|
+
: TrackPlayer.add(resolvedTracks, insertBeforeIndex);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Replaces the current track or loads the track as the first in the queue.
|
|
136
|
+
*
|
|
137
|
+
* @param track The track to load.
|
|
138
|
+
*/
|
|
139
|
+
export async function load(track: Track): Promise<number | void> {
|
|
140
|
+
return TrackPlayer.load(track);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Move a track within the queue.
|
|
145
|
+
*
|
|
146
|
+
* @param fromIndex The index of the track to be moved.
|
|
147
|
+
* @param toIndex The index to move the track to. If the index is larger than
|
|
148
|
+
* the size of the queue, then the track is moved to the end of the queue.
|
|
149
|
+
*/
|
|
150
|
+
export async function move(fromIndex: number, toIndex: number): Promise<void> {
|
|
151
|
+
return TrackPlayer.move(fromIndex, toIndex);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Removes multiple tracks from the queue by their indexes.
|
|
156
|
+
*
|
|
157
|
+
* If the current track is removed, the next track will activated. If the
|
|
158
|
+
* current track was the last track in the queue, the first track will be
|
|
159
|
+
* activated.
|
|
160
|
+
*
|
|
161
|
+
* @param indexes The indexes of the tracks to be removed.
|
|
162
|
+
*/
|
|
163
|
+
export async function remove(indexes: number[]): Promise<void>;
|
|
164
|
+
/**
|
|
165
|
+
* Removes a track from the queue by its index.
|
|
166
|
+
*
|
|
167
|
+
* If the current track is removed, the next track will activated. If the
|
|
168
|
+
* current track was the last track in the queue, the first track will be
|
|
169
|
+
* activated.
|
|
170
|
+
*
|
|
171
|
+
* @param index The index of the track to be removed.
|
|
172
|
+
*/
|
|
173
|
+
export async function remove(index: number): Promise<void>;
|
|
174
|
+
export async function remove(indexOrIndexes: number | number[]): Promise<void> {
|
|
175
|
+
return TrackPlayer.remove(
|
|
176
|
+
Array.isArray(indexOrIndexes) ? indexOrIndexes : [indexOrIndexes],
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Clears any upcoming tracks from the queue.
|
|
182
|
+
*/
|
|
183
|
+
export async function removeUpcomingTracks(): Promise<void> {
|
|
184
|
+
return TrackPlayer.removeUpcomingTracks();
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Skips to a track in the queue.
|
|
189
|
+
*
|
|
190
|
+
* @param index The index of the track to skip to.
|
|
191
|
+
* @param initialPosition (Optional) The initial position to seek to in seconds.
|
|
192
|
+
*/
|
|
193
|
+
export async function skip(index: number, initialPosition = -1): Promise<void> {
|
|
194
|
+
return TrackPlayer.skip(index, initialPosition);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Skips to the next track in the queue.
|
|
199
|
+
*
|
|
200
|
+
* @param initialPosition (Optional) The initial position to seek to in seconds.
|
|
201
|
+
*/
|
|
202
|
+
export async function skipToNext(initialPosition = -1): Promise<void> {
|
|
203
|
+
return TrackPlayer.skipToNext(initialPosition);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Skips to the previous track in the queue.
|
|
208
|
+
*
|
|
209
|
+
* @param initialPosition (Optional) The initial position to seek to in seconds.
|
|
210
|
+
*/
|
|
211
|
+
export async function skipToPrevious(initialPosition = -1): Promise<void> {
|
|
212
|
+
return TrackPlayer.skipToPrevious(initialPosition);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// MARK: - Control Center / Notifications API
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Updates the configuration for the components.
|
|
219
|
+
*
|
|
220
|
+
* @param options The options to update.
|
|
221
|
+
* @see https://rntp.dev/docs/api/functions/player#updateoptionsoptions
|
|
222
|
+
*/
|
|
223
|
+
export async function updateOptions({
|
|
224
|
+
alwaysPauseOnInterruption,
|
|
225
|
+
...options
|
|
226
|
+
}: UpdateOptions = {}): Promise<void> {
|
|
227
|
+
return TrackPlayer.updateOptions({
|
|
228
|
+
...options,
|
|
229
|
+
android: {
|
|
230
|
+
// Handle deprecated alwaysPauseOnInterruption option:
|
|
231
|
+
alwaysPauseOnInterruption:
|
|
232
|
+
options.android?.alwaysPauseOnInterruption ?? alwaysPauseOnInterruption,
|
|
233
|
+
...options.android,
|
|
234
|
+
},
|
|
235
|
+
icon: resolveImportedAsset(options.icon),
|
|
236
|
+
playIcon: resolveImportedAsset(options.playIcon),
|
|
237
|
+
pauseIcon: resolveImportedAsset(options.pauseIcon),
|
|
238
|
+
stopIcon: resolveImportedAsset(options.stopIcon),
|
|
239
|
+
previousIcon: resolveImportedAsset(options.previousIcon),
|
|
240
|
+
nextIcon: resolveImportedAsset(options.nextIcon),
|
|
241
|
+
// rewindIcon: resolveImportedAsset(options.rewindIcon),
|
|
242
|
+
// forwardIcon: resolveImportedAsset(options.forwardIcon),
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Updates the metadata of a track in the queue. If the current track is updated,
|
|
248
|
+
* the notification and the Now Playing Center will be updated accordingly.
|
|
249
|
+
*
|
|
250
|
+
* @param trackIndex The index of the track whose metadata will be updated.
|
|
251
|
+
* @param metadata The metadata to update.
|
|
252
|
+
*/
|
|
253
|
+
export async function updateMetadataForTrack(
|
|
254
|
+
trackIndex: number,
|
|
255
|
+
metadata: TrackMetadataBase,
|
|
256
|
+
): Promise<void> {
|
|
257
|
+
return TrackPlayer.updateMetadataForTrack(trackIndex, {
|
|
258
|
+
...metadata,
|
|
259
|
+
artwork: resolveImportedAssetOrPath(metadata.artwork),
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Updates the metadata content of the notification (Android) and the Now Playing Center (iOS)
|
|
265
|
+
* without affecting the data stored for the current track.
|
|
266
|
+
*/
|
|
267
|
+
export function updateNowPlayingMetadata(
|
|
268
|
+
metadata: NowPlayingMetadata,
|
|
269
|
+
): Promise<void> {
|
|
270
|
+
return TrackPlayer.updateNowPlayingMetadata({
|
|
271
|
+
...metadata,
|
|
272
|
+
artwork: resolveImportedAssetOrPath(metadata.artwork),
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// MARK: - Player API
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Resets the player stopping the current track and clearing the queue.
|
|
280
|
+
*/
|
|
281
|
+
export async function reset(): Promise<void> {
|
|
282
|
+
return TrackPlayer.reset();
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Plays or resumes the current track.
|
|
287
|
+
*/
|
|
288
|
+
export async function play(): Promise<void> {
|
|
289
|
+
return TrackPlayer.play();
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Pauses the current track.
|
|
294
|
+
*/
|
|
295
|
+
export async function pause(): Promise<void> {
|
|
296
|
+
return TrackPlayer.pause();
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Stops the current track.
|
|
301
|
+
*/
|
|
302
|
+
export async function stop(): Promise<void> {
|
|
303
|
+
return TrackPlayer.stop();
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Sets whether the player will play automatically when it is ready to do so.
|
|
308
|
+
* This is the equivalent of calling `TrackPlayer.play()` when `playWhenReady = true`
|
|
309
|
+
* or `TrackPlayer.pause()` when `playWhenReady = false`.
|
|
310
|
+
*/
|
|
311
|
+
export async function setPlayWhenReady(
|
|
312
|
+
playWhenReady: boolean,
|
|
313
|
+
): Promise<boolean> {
|
|
314
|
+
return TrackPlayer.setPlayWhenReady(playWhenReady);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Gets whether the player will play automatically when it is ready to do so.
|
|
319
|
+
*/
|
|
320
|
+
export async function getPlayWhenReady(): Promise<boolean> {
|
|
321
|
+
return TrackPlayer.getPlayWhenReady();
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Seeks to a specified time position in the current track.
|
|
326
|
+
*
|
|
327
|
+
* @param position The position to seek to in seconds.
|
|
328
|
+
*/
|
|
329
|
+
export async function seekTo(position: number): Promise<void> {
|
|
330
|
+
return TrackPlayer.seekTo(position);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Seeks by a relative time offset in the current track.
|
|
335
|
+
*
|
|
336
|
+
* @param offset The time offset to seek by in seconds.
|
|
337
|
+
*/
|
|
338
|
+
export async function seekBy(offset: number): Promise<void> {
|
|
339
|
+
return TrackPlayer.seekBy(offset);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Sets the volume of the player.
|
|
344
|
+
*
|
|
345
|
+
* @param volume The volume as a number between 0 and 1.
|
|
346
|
+
*/
|
|
347
|
+
export async function setVolume(level: number): Promise<void> {
|
|
348
|
+
return TrackPlayer.setVolume(level);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Sets the volume of the player with a simple linear scaling.
|
|
353
|
+
* In Android this is achieved via a native thread call.
|
|
354
|
+
* In other platforms this is achieved via RN's Animated.Value.
|
|
355
|
+
*
|
|
356
|
+
* @param volume The volume as a number between 0 and 1.
|
|
357
|
+
* @param duration The duration of the animation in milliseconds. defualt is 0 ms, which just functions as TP.setVolume.
|
|
358
|
+
* @param init The initial value of the volume. This may be useful eg to be 0 for a fade in event.
|
|
359
|
+
* @param interval The interval of the animation in milliseconds. default is 20 ms.
|
|
360
|
+
* @param msg (Android) The message to be emitted after volume is fully changed, via Event.PlaybackAnimatedVolumeChanged.
|
|
361
|
+
* @param callback (other platforms) The callback to be called after volume is fully changed.
|
|
362
|
+
*/
|
|
363
|
+
export const setAnimatedVolume = async ({
|
|
364
|
+
volume,
|
|
365
|
+
duration = 0,
|
|
366
|
+
init = -1,
|
|
367
|
+
interval = 20,
|
|
368
|
+
msg = '',
|
|
369
|
+
callback = () => undefined,
|
|
370
|
+
}: {
|
|
371
|
+
volume: number;
|
|
372
|
+
duration?: number;
|
|
373
|
+
init?: number;
|
|
374
|
+
interval?: number;
|
|
375
|
+
msg?: string;
|
|
376
|
+
callback?: () => void | Promise<void>;
|
|
377
|
+
}) => {
|
|
378
|
+
if (duration === 0) {
|
|
379
|
+
TrackPlayer.setVolume(volume);
|
|
380
|
+
return callback();
|
|
381
|
+
}
|
|
382
|
+
if (init !== -1) {
|
|
383
|
+
TrackPlayer.setVolume(init);
|
|
384
|
+
}
|
|
385
|
+
if (isAndroid) {
|
|
386
|
+
return TrackPlayer.setAnimatedVolume(volume, duration, interval, msg);
|
|
387
|
+
} else {
|
|
388
|
+
/*
|
|
389
|
+
TODO: Animated.value change relies on React rendering so Android
|
|
390
|
+
headlessJS will not work with it. however does iOS and windows work in the background?
|
|
391
|
+
if not this code block is needed
|
|
392
|
+
if (AppState.currentState !== 'active') {
|
|
393
|
+
// need to figure out a way to run Animated.timing in background. probably needs our own module
|
|
394
|
+
duration = 0;
|
|
395
|
+
}
|
|
396
|
+
*/
|
|
397
|
+
volume = Math.min(volume, 1);
|
|
398
|
+
if (duration === 0) {
|
|
399
|
+
animatedVolume.setValue(volume);
|
|
400
|
+
callback();
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
animatedVolume.stopAnimation();
|
|
404
|
+
Animated.timing(animatedVolume, {
|
|
405
|
+
toValue: volume,
|
|
406
|
+
useNativeDriver: true,
|
|
407
|
+
duration,
|
|
408
|
+
}).start(() => callback());
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* performs fading out to pause playback.
|
|
414
|
+
* @param duration duration of the fade progress in ms
|
|
415
|
+
* @param interval interval of the fade progress in ms
|
|
416
|
+
*/
|
|
417
|
+
export const fadeOutPause = async (duration = 500, interval = 20) => {
|
|
418
|
+
if (isAndroid) {
|
|
419
|
+
TrackPlayer.fadeOutPause(duration, interval);
|
|
420
|
+
} else {
|
|
421
|
+
setAnimatedVolume({
|
|
422
|
+
duration,
|
|
423
|
+
interval,
|
|
424
|
+
volume: 0,
|
|
425
|
+
callback: () => pause(),
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* performs fading into playing the next track.
|
|
432
|
+
* @param duration duration of the fade progress in ms
|
|
433
|
+
* @param interval interval of the fade progress in ms
|
|
434
|
+
* @param toVolume volume to fade into
|
|
435
|
+
*/
|
|
436
|
+
export const fadeOutNext = async (
|
|
437
|
+
duration = 500,
|
|
438
|
+
interval = 20,
|
|
439
|
+
toVolume = 1,
|
|
440
|
+
) => {
|
|
441
|
+
if (isAndroid) {
|
|
442
|
+
TrackPlayer.fadeOutNext(duration, interval, toVolume);
|
|
443
|
+
} else {
|
|
444
|
+
setAnimatedVolume({
|
|
445
|
+
duration,
|
|
446
|
+
interval,
|
|
447
|
+
volume: 0,
|
|
448
|
+
callback: async () => {
|
|
449
|
+
await skipToNext();
|
|
450
|
+
setAnimatedVolume({
|
|
451
|
+
duration,
|
|
452
|
+
interval,
|
|
453
|
+
volume: toVolume,
|
|
454
|
+
});
|
|
455
|
+
},
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* performs fading into playing the previous track.
|
|
462
|
+
* @param duration duration of the fade progress in ms
|
|
463
|
+
* @param interval interval of the fade progress in ms
|
|
464
|
+
* @param toVolume volume to fade into
|
|
465
|
+
*/
|
|
466
|
+
export const fadeOutPrevious = async (
|
|
467
|
+
duration = 500,
|
|
468
|
+
interval = 20,
|
|
469
|
+
toVolume = 1,
|
|
470
|
+
) => {
|
|
471
|
+
if (isAndroid) {
|
|
472
|
+
TrackPlayer.fadeOutPrevious(duration, interval, toVolume);
|
|
473
|
+
} else {
|
|
474
|
+
setAnimatedVolume({
|
|
475
|
+
duration,
|
|
476
|
+
interval,
|
|
477
|
+
volume: 0,
|
|
478
|
+
callback: async () => {
|
|
479
|
+
await skipToPrevious();
|
|
480
|
+
setAnimatedVolume({
|
|
481
|
+
duration,
|
|
482
|
+
interval,
|
|
483
|
+
volume: toVolume,
|
|
484
|
+
});
|
|
485
|
+
},
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* performs fading into skipping to a track.
|
|
492
|
+
* @param index the index of the track to skip to
|
|
493
|
+
* @param duration duration of the fade progress in ms
|
|
494
|
+
* @param interval interval of the fade progress in ms
|
|
495
|
+
* @param toVolume volume to fade into
|
|
496
|
+
*/
|
|
497
|
+
export const fadeOutJump = async (
|
|
498
|
+
index: number,
|
|
499
|
+
duration = 500,
|
|
500
|
+
interval = 20,
|
|
501
|
+
toVolume = 1,
|
|
502
|
+
) => {
|
|
503
|
+
if (isAndroid) {
|
|
504
|
+
TrackPlayer.fadeOutJump(index, duration, interval, toVolume);
|
|
505
|
+
} else {
|
|
506
|
+
setAnimatedVolume({
|
|
507
|
+
duration,
|
|
508
|
+
interval,
|
|
509
|
+
volume: 0,
|
|
510
|
+
callback: async () => {
|
|
511
|
+
await skip(index);
|
|
512
|
+
setAnimatedVolume({
|
|
513
|
+
duration,
|
|
514
|
+
interval,
|
|
515
|
+
volume: toVolume,
|
|
516
|
+
});
|
|
517
|
+
},
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
};
|
|
521
|
+
/**
|
|
522
|
+
* Sets the playback rate.
|
|
523
|
+
*
|
|
524
|
+
* @param rate The playback rate to change to, where 0.5 would be half speed,
|
|
525
|
+
* 1 would be regular speed, 2 would be double speed etc.
|
|
526
|
+
*/
|
|
527
|
+
export async function setRate(rate: number): Promise<void> {
|
|
528
|
+
return TrackPlayer.setRate(rate);
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* Sets the playback pitch. android only
|
|
532
|
+
*
|
|
533
|
+
* @param pitch The pitch.
|
|
534
|
+
*/
|
|
535
|
+
export async function setPitch(pitch: number): Promise<void> {
|
|
536
|
+
return isAndroid ? TrackPlayer.setPitch(pitch) : void 0;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* Sets the queue.
|
|
541
|
+
*
|
|
542
|
+
* @param tracks The tracks to set as the queue.
|
|
543
|
+
* @see https://rntp.dev/docs/api/constants/repeat-mode
|
|
544
|
+
*/
|
|
545
|
+
export async function setQueue(tracks: Track[]): Promise<void> {
|
|
546
|
+
return TrackPlayer.setQueue(tracks);
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* Sets the queue repeat mode.
|
|
551
|
+
*
|
|
552
|
+
* @param repeatMode The repeat mode to set.
|
|
553
|
+
* @see https://rntp.dev/docs/api/constants/repeat-mode
|
|
554
|
+
*/
|
|
555
|
+
export async function setRepeatMode(mode: RepeatMode): Promise<RepeatMode> {
|
|
556
|
+
return TrackPlayer.setRepeatMode(mode);
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
// MARK: - Getters
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* Gets the volume of the player as a number between 0 and 1.
|
|
563
|
+
*/
|
|
564
|
+
export async function getVolume(): Promise<number> {
|
|
565
|
+
return TrackPlayer.getVolume();
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* Gets the playback rate where 0.5 would be half speed, 1 would be
|
|
570
|
+
* regular speed and 2 would be double speed etc.
|
|
571
|
+
*/
|
|
572
|
+
export async function getRate(): Promise<number> {
|
|
573
|
+
return TrackPlayer.getRate();
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* Gets the pitch of the track.
|
|
578
|
+
*/
|
|
579
|
+
export async function getPitch(): Promise<number> {
|
|
580
|
+
return isAndroid ? TrackPlayer.getPitch() : 1;
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* Gets a track object from the queue.
|
|
584
|
+
*
|
|
585
|
+
* @param index The index of the track.
|
|
586
|
+
* @returns The track object or undefined if there isn't a track object at that
|
|
587
|
+
* index.
|
|
588
|
+
*/
|
|
589
|
+
export async function getTrack(index: number): Promise<Track | undefined> {
|
|
590
|
+
// @ts-expect-error codegen issues
|
|
591
|
+
return TrackPlayer.getTrack(index);
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* Gets the whole queue.
|
|
596
|
+
*/
|
|
597
|
+
export async function getQueue(): Promise<Track[]> {
|
|
598
|
+
// @ts-expect-error codegen issues
|
|
599
|
+
return TrackPlayer.getQueue();
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* Gets the index of the active track in the queue or undefined if there is no
|
|
604
|
+
* current track.
|
|
605
|
+
*/
|
|
606
|
+
export async function getActiveTrackIndex(): Promise<number | undefined> {
|
|
607
|
+
return (await TrackPlayer.getActiveTrackIndex()) ?? undefined;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
/**
|
|
611
|
+
* Gets the active track or undefined if there is no current track.
|
|
612
|
+
*/
|
|
613
|
+
export async function getActiveTrack(): Promise<Track | undefined> {
|
|
614
|
+
// @ts-expect-error codegen issues
|
|
615
|
+
return (await TrackPlayer.getActiveTrack()) ?? undefined;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* Gets information on the progress of the currently active track, including its
|
|
620
|
+
* current playback position in seconds, buffered position in seconds and
|
|
621
|
+
* duration in seconds.
|
|
622
|
+
*/
|
|
623
|
+
export async function getProgress(): Promise<Progress> {
|
|
624
|
+
// @ts-expect-error codegen issues
|
|
625
|
+
return TrackPlayer.getProgress();
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
/**
|
|
629
|
+
* Gets the playback state of the player.
|
|
630
|
+
*
|
|
631
|
+
* @see https://rntp.dev/docs/api/constants/state
|
|
632
|
+
*/
|
|
633
|
+
export async function getPlaybackState(): Promise<PlaybackState> {
|
|
634
|
+
// @ts-expect-error codegen issues
|
|
635
|
+
return TrackPlayer.getPlaybackState();
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
/**
|
|
639
|
+
* Gets the queue repeat mode.
|
|
640
|
+
*
|
|
641
|
+
* @see https://rntp.dev/docs/api/constants/repeat-mode
|
|
642
|
+
*/
|
|
643
|
+
export async function getRepeatMode(): Promise<RepeatMode> {
|
|
644
|
+
return TrackPlayer.getRepeatMode();
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
/**
|
|
648
|
+
* Retries the current item when the playback state is `State.Error`.
|
|
649
|
+
*/
|
|
650
|
+
export async function retry() {
|
|
651
|
+
return TrackPlayer.retry();
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
/**
|
|
655
|
+
* Sets the content hierarchy of Android Auto (Android only). The hierarchy structure is a dict with
|
|
656
|
+
* the mediaId as keys, and a list of MediaItem as values. To use, you must at least specify the root directory, where
|
|
657
|
+
* the key is "/". If the root directory contains BROWSABLE MediaItems, they will be shown as tabs. Do note Google requires
|
|
658
|
+
* 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.
|
|
659
|
+
*
|
|
660
|
+
* @param browseTree the content hierarchy dict.
|
|
661
|
+
* @returns a serialized copy of the browseTree set by native. For debug purposes.
|
|
662
|
+
*/
|
|
663
|
+
export async function setBrowseTree(
|
|
664
|
+
browseTree: AndroidAutoBrowseTree,
|
|
665
|
+
): Promise<string> {
|
|
666
|
+
if (!isAndroid) return new Promise(() => '');
|
|
667
|
+
return TrackPlayer.setBrowseTree(browseTree);
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
/**
|
|
671
|
+
* this method enables android auto playback progress tracking; see
|
|
672
|
+
* https://developer.android.com/training/cars/media#browse-progress-bar
|
|
673
|
+
* android only.
|
|
674
|
+
* @param mediaID the mediaID.
|
|
675
|
+
* @returns
|
|
676
|
+
*/
|
|
677
|
+
export async function setPlaybackState(mediaID: string): Promise<void> {
|
|
678
|
+
if (!isAndroid) return;
|
|
679
|
+
TrackPlayer.setPlaybackState(mediaID);
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
/**
|
|
683
|
+
* Sets the content style of Android Auto (Android only).
|
|
684
|
+
* there are list style and grid style. see https://developer.android.com/training/cars/media#apply_content_style .
|
|
685
|
+
* the styles are applicable to browsable nodes and playable nodes. setting the args to true will yield the list style.
|
|
686
|
+
* false = the grid style.
|
|
687
|
+
*/
|
|
688
|
+
export function setBrowseTreeStyle(
|
|
689
|
+
browsableStyle: AndroidAutoContentStyle,
|
|
690
|
+
playableStyle: AndroidAutoContentStyle,
|
|
691
|
+
): null {
|
|
692
|
+
if (!isAndroid) return null;
|
|
693
|
+
TrackPlayer.setBrowseTreeStyle(browsableStyle, playableStyle);
|
|
694
|
+
return null;
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
/**
|
|
698
|
+
* Sets the search results of Android Auto (Android only). The hierarchy structure is a dict with
|
|
699
|
+
* the mediaId as keys, and a list of MediaItem as values.
|
|
700
|
+
*
|
|
701
|
+
* @param searchResults the search results.
|
|
702
|
+
* @returns a serialized copy of the searchResults set by native. For debug purposes.
|
|
703
|
+
*/
|
|
704
|
+
export async function setSearchResults(
|
|
705
|
+
searchResults: MediaItem[],
|
|
706
|
+
): Promise<void> {
|
|
707
|
+
if (!isAndroid) return new Promise(() => '');
|
|
708
|
+
return TrackPlayer.setSearchResults(searchResults);
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
/**
|
|
712
|
+
* acquires the wake lock of MusicService (android only.)
|
|
713
|
+
*/
|
|
714
|
+
export async function acquireWakeLock() {
|
|
715
|
+
if (!isAndroid) return;
|
|
716
|
+
TrackPlayer.acquireWakeLock();
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
/**
|
|
720
|
+
* acquires the wake lock of MusicService (android only.)
|
|
721
|
+
*/
|
|
722
|
+
export async function abandonWakeLock() {
|
|
723
|
+
if (!isAndroid) return;
|
|
724
|
+
TrackPlayer.abandonWakeLock();
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
/**
|
|
728
|
+
* prepare to crossfade (android only.) the crossfade alternate
|
|
729
|
+
* player will be automatically primed to the current player's index,
|
|
730
|
+
* then by previous = true or not, skip to previous or next. player
|
|
731
|
+
* will be prepared. its advised to call this well before actually performing
|
|
732
|
+
* crossfade so the resource can be prepared.
|
|
733
|
+
*/
|
|
734
|
+
export async function crossFadePrepare(previous = false, seekTo = 0) {
|
|
735
|
+
if (!isAndroid) return;
|
|
736
|
+
TrackPlayer.crossFadePrepare(previous, seekTo);
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
/**
|
|
740
|
+
* perform crossfade (android only).
|
|
741
|
+
*
|
|
742
|
+
* fadeDuration and fadeInterval are both in ms.
|
|
743
|
+
*
|
|
744
|
+
* fadeToVolume is a float from 0-1.
|
|
745
|
+
*
|
|
746
|
+
* waitUntil is in ms.
|
|
747
|
+
*/
|
|
748
|
+
export async function crossFade(
|
|
749
|
+
fadeDuration = 2000,
|
|
750
|
+
fadeInterval = 20,
|
|
751
|
+
fadeToVolume = 1,
|
|
752
|
+
waitUntil = 0,
|
|
753
|
+
) {
|
|
754
|
+
if (!isAndroid) return;
|
|
755
|
+
TrackPlayer.switchExoPlayer(
|
|
756
|
+
fadeDuration,
|
|
757
|
+
fadeInterval,
|
|
758
|
+
fadeToVolume,
|
|
759
|
+
waitUntil,
|
|
760
|
+
);
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
/**
|
|
764
|
+
* get the last connected package. non android will return undefined.
|
|
765
|
+
*
|
|
766
|
+
* android without a connected package (either system.UI, android auto, or media controller) yet
|
|
767
|
+
* will return ''; else will be one of the three.
|
|
768
|
+
*
|
|
769
|
+
* I intend to use this to determine if app crashed from android auto.
|
|
770
|
+
*/
|
|
771
|
+
export async function getLastConnectedPackage(): Promise<string | undefined> {
|
|
772
|
+
if (!isAndroid) return;
|
|
773
|
+
return TrackPlayer.getLastConnectedPackage();
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
/**
|
|
777
|
+
* android only. set loudnessEnhance via audiofx's loudnessEnhancer. gain is in mB (1dB=100mB)
|
|
778
|
+
*/
|
|
779
|
+
export async function setLoudnessEnhance(gain = 0) {
|
|
780
|
+
if (!isAndroid) return;
|
|
781
|
+
TrackPlayer.setLoudnessEnhance(gain);
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
/**
|
|
785
|
+
* android only. set equalizer preset.
|
|
786
|
+
*/
|
|
787
|
+
export async function setEqualizerPreset(preset = 0) {
|
|
788
|
+
if (!isAndroid) return;
|
|
789
|
+
TrackPlayer.setEqualizerPreset(preset);
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
/**
|
|
793
|
+
* android only. get the current equalizer preset index (int).
|
|
794
|
+
*/
|
|
795
|
+
export async function getCurrentEqualizerPreset(): Promise<number> {
|
|
796
|
+
if (!isAndroid) return -1;
|
|
797
|
+
return TrackPlayer.getCurrentEqualizerPreset();
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
/**
|
|
801
|
+
* android only. get the current eq preset names.
|
|
802
|
+
*/
|
|
803
|
+
export async function getEqualizerPresets(): Promise<string[]> {
|
|
804
|
+
if (!isAndroid) return [];
|
|
805
|
+
return TrackPlayer.getEqualizerPresets();
|
|
806
|
+
}
|