@javascriptcommon/react-native-track-player 1.2.9 → 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 +92 -18
- package/android/proguard-rules.txt +0 -3
- package/android/src/main/AndroidManifest.xml +10 -13
- 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/doublesymmetry/trackplayer/extensions/AudioPlayerStateExt.kt +19 -0
- 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/doublesymmetry/trackplayer/model/MetadataAdapter.kt +227 -0
- package/android/src/main/java/com/doublesymmetry/trackplayer/model/NowPlayingMetadata.kt +16 -0
- package/android/src/main/java/com/doublesymmetry/trackplayer/model/PlaybackMetadata.kt +203 -0
- package/android/src/main/java/com/doublesymmetry/trackplayer/model/State.kt +13 -0
- 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/doublesymmetry/trackplayer/module/MusicEvents.kt +67 -0
- 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/doublesymmetry/trackplayer/utils/BundleUtils.kt +147 -0
- 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/lovegaoshi/kotlinaudio/event/EventHolder.kt +30 -0
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/event/PlayerEventHolder.kt +124 -0
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/AudioContentType.kt +10 -0
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/AudioItem.kt +118 -0
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/AudioItemTransitionReason.kt +33 -0
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/AudioPlayerState.kt +30 -0
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/BufferConfig.kt +8 -0
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/CacheConfig.kt +17 -0
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/Capability.kt +19 -0
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/CustomButton.kt +19 -0
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/FocusChangeData.kt +3 -0
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/MediaSessionCallback.kt +17 -0
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/PlayWhenReadyChangeData.kt +3 -0
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/PlaybackEndedReason.kt +5 -0
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/PlaybackError.kt +6 -0
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/PlayerConfig.kt +36 -0
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/PlayerOptions.kt +40 -0
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/PositionChangedReason.kt +39 -0
- 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/lovegaoshi/kotlinaudio/player/QueuedAudioPlayer.kt +279 -0
- 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 +5 -0
- 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/java/com/guichaguri/trackplayer/TrackPlayer.java +0 -28
- package/android/src/main/java/com/guichaguri/trackplayer/module/MusicEvents.java +0 -55
- package/android/src/main/java/com/guichaguri/trackplayer/module/MusicModule.java +0 -298
- package/android/src/main/java/com/guichaguri/trackplayer/service/HeadlessJsMediaService.java +0 -174
- package/android/src/main/java/com/guichaguri/trackplayer/service/MusicBinder.java +0 -47
- package/android/src/main/java/com/guichaguri/trackplayer/service/MusicManager.java +0 -383
- package/android/src/main/java/com/guichaguri/trackplayer/service/MusicService.java +0 -271
- package/android/src/main/java/com/guichaguri/trackplayer/service/Utils.java +0 -243
- package/android/src/main/java/com/guichaguri/trackplayer/service/metadata/ButtonEvents.java +0 -148
- package/android/src/main/java/com/guichaguri/trackplayer/service/metadata/MetadataManager.java +0 -379
- package/android/src/main/java/com/guichaguri/trackplayer/service/models/Track.java +0 -141
- package/android/src/main/java/com/guichaguri/trackplayer/service/models/TrackType.java +0 -35
- package/android/src/main/res/drawable-hdpi/ic_forward.png +0 -0
- package/android/src/main/res/drawable-hdpi/ic_logo.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_logo.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_logo.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_logo.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_logo.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/index.d.ts +0 -174
- 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 -177
- /package/ios/{TrackPlayer.xcodeproj → Example/SwiftAudio.xcodeproj}/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
import { getActiveTrack } from '../trackPlayer';
|
|
3
|
+
import { Event } from '../constants';
|
|
4
|
+
import { useTrackPlayerEvents } from './useTrackPlayerEvents';
|
|
5
|
+
export const useActiveTrack = () => {
|
|
6
|
+
const [track, setTrack] = useState();
|
|
7
|
+
// Sets the initial index (if still undefined)
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
let unmounted = false;
|
|
10
|
+
getActiveTrack()
|
|
11
|
+
.then((initialTrack) => {
|
|
12
|
+
if (unmounted)
|
|
13
|
+
return;
|
|
14
|
+
setTrack((track) => track ?? initialTrack ?? undefined);
|
|
15
|
+
})
|
|
16
|
+
.catch(() => {
|
|
17
|
+
// throws when you haven't yet setup, which is fine because it also
|
|
18
|
+
// means there's no active track
|
|
19
|
+
});
|
|
20
|
+
return () => {
|
|
21
|
+
unmounted = true;
|
|
22
|
+
};
|
|
23
|
+
}, []);
|
|
24
|
+
useTrackPlayerEvents([Event.PlaybackActiveTrackChanged], async ({ track }) => {
|
|
25
|
+
setTrack(track ?? undefined);
|
|
26
|
+
});
|
|
27
|
+
return track;
|
|
28
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useAppIsInBackground(): boolean;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useState, useEffect, useRef } from 'react';
|
|
2
|
+
import { AppState } from 'react-native';
|
|
3
|
+
export function useAppIsInBackground() {
|
|
4
|
+
const [state, setState] = useState('active');
|
|
5
|
+
const eventListener = useRef(undefined);
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
const onStateChange = (nextState) => {
|
|
8
|
+
setState(nextState);
|
|
9
|
+
};
|
|
10
|
+
eventListener.current = AppState.addEventListener('change', onStateChange);
|
|
11
|
+
return () => {
|
|
12
|
+
eventListener.current?.remove();
|
|
13
|
+
};
|
|
14
|
+
}, []);
|
|
15
|
+
return state === 'background';
|
|
16
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tells whether the TrackPlayer is in a mode that most people would describe
|
|
3
|
+
* as "playing." Great for UI to decide whether to show a Play or Pause button.
|
|
4
|
+
* @returns playing - whether UI should likely show as Playing, or undefined
|
|
5
|
+
* if this isn't yet known.
|
|
6
|
+
* @returns bufferingDuringPlay - whether UI should show as Buffering, or
|
|
7
|
+
* undefined if this isn't yet known.
|
|
8
|
+
*/
|
|
9
|
+
export declare function useIsPlaying(): {
|
|
10
|
+
playing: undefined;
|
|
11
|
+
bufferingDuringPlay: undefined;
|
|
12
|
+
} | {
|
|
13
|
+
playing: boolean;
|
|
14
|
+
bufferingDuringPlay: boolean;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* This exists if you need realtime status on whether the TrackPlayer is
|
|
18
|
+
* playing, whereas the hooks all have a delay because they depend on responding
|
|
19
|
+
* to events before their state is updated.
|
|
20
|
+
*
|
|
21
|
+
* It also exists whenever you need to know the play state outside of a React
|
|
22
|
+
* component, since hooks only work in components.
|
|
23
|
+
*
|
|
24
|
+
* @returns playing - whether UI should likely show as Playing, or undefined
|
|
25
|
+
* if this isn't yet known.
|
|
26
|
+
* @returns bufferingDuringPlay - whether UI should show as Buffering, or
|
|
27
|
+
* undefined if this isn't yet known.
|
|
28
|
+
*/
|
|
29
|
+
export declare function isPlaying(): Promise<{
|
|
30
|
+
playing: undefined;
|
|
31
|
+
bufferingDuringPlay: undefined;
|
|
32
|
+
} | {
|
|
33
|
+
playing: boolean;
|
|
34
|
+
bufferingDuringPlay: boolean;
|
|
35
|
+
}>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as TrackPlayer from '../trackPlayer';
|
|
2
|
+
import { State } from '../constants';
|
|
3
|
+
import { usePlayWhenReady } from './usePlayWhenReady';
|
|
4
|
+
import { usePlaybackState } from './usePlaybackState';
|
|
5
|
+
/**
|
|
6
|
+
* Tells whether the TrackPlayer is in a mode that most people would describe
|
|
7
|
+
* as "playing." Great for UI to decide whether to show a Play or Pause button.
|
|
8
|
+
* @returns playing - whether UI should likely show as Playing, or undefined
|
|
9
|
+
* if this isn't yet known.
|
|
10
|
+
* @returns bufferingDuringPlay - whether UI should show as Buffering, or
|
|
11
|
+
* undefined if this isn't yet known.
|
|
12
|
+
*/
|
|
13
|
+
export function useIsPlaying() {
|
|
14
|
+
const state = usePlaybackState().state;
|
|
15
|
+
const playWhenReady = usePlayWhenReady();
|
|
16
|
+
return determineIsPlaying(playWhenReady, state);
|
|
17
|
+
}
|
|
18
|
+
function determineIsPlaying(playWhenReady, state) {
|
|
19
|
+
if (playWhenReady === undefined || state === undefined) {
|
|
20
|
+
return { playing: undefined, bufferingDuringPlay: undefined };
|
|
21
|
+
}
|
|
22
|
+
const isLoading = state === State.Loading || state === State.Buffering;
|
|
23
|
+
const isErrored = state === State.Error;
|
|
24
|
+
const isEnded = state === State.Ended;
|
|
25
|
+
const isNone = state === State.None;
|
|
26
|
+
return {
|
|
27
|
+
playing: playWhenReady && !(isErrored || isEnded || isNone),
|
|
28
|
+
bufferingDuringPlay: playWhenReady && isLoading,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* This exists if you need realtime status on whether the TrackPlayer is
|
|
33
|
+
* playing, whereas the hooks all have a delay because they depend on responding
|
|
34
|
+
* to events before their state is updated.
|
|
35
|
+
*
|
|
36
|
+
* It also exists whenever you need to know the play state outside of a React
|
|
37
|
+
* component, since hooks only work in components.
|
|
38
|
+
*
|
|
39
|
+
* @returns playing - whether UI should likely show as Playing, or undefined
|
|
40
|
+
* if this isn't yet known.
|
|
41
|
+
* @returns bufferingDuringPlay - whether UI should show as Buffering, or
|
|
42
|
+
* undefined if this isn't yet known.
|
|
43
|
+
*/
|
|
44
|
+
export async function isPlaying() {
|
|
45
|
+
const [playbackState, playWhenReady] = await Promise.all([
|
|
46
|
+
TrackPlayer.getPlaybackState(),
|
|
47
|
+
TrackPlayer.getPlayWhenReady(),
|
|
48
|
+
]);
|
|
49
|
+
return determineIsPlaying(playWhenReady, playbackState.state);
|
|
50
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const usePlayWhenReady: () => boolean | undefined;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
import { getPlayWhenReady, addEventListener } from '../trackPlayer';
|
|
3
|
+
import { Event } from '../constants';
|
|
4
|
+
export const usePlayWhenReady = () => {
|
|
5
|
+
const [playWhenReady, setPlayWhenReady] = useState(undefined);
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
let mounted = true;
|
|
8
|
+
getPlayWhenReady()
|
|
9
|
+
.then((initialState) => {
|
|
10
|
+
if (!mounted)
|
|
11
|
+
return;
|
|
12
|
+
// Only set the state if it wasn't already set by the Event.PlaybackPlayWhenReadyChanged listener below:
|
|
13
|
+
setPlayWhenReady((state) => state ?? initialState);
|
|
14
|
+
})
|
|
15
|
+
.catch(() => {
|
|
16
|
+
/** getState only throw while you haven't yet setup, ignore failure. */
|
|
17
|
+
});
|
|
18
|
+
const sub = addEventListener(Event.PlaybackPlayWhenReadyChanged, (event) => {
|
|
19
|
+
setPlayWhenReady(event.playWhenReady);
|
|
20
|
+
});
|
|
21
|
+
return () => {
|
|
22
|
+
mounted = false;
|
|
23
|
+
sub.remove();
|
|
24
|
+
};
|
|
25
|
+
}, []);
|
|
26
|
+
return playWhenReady;
|
|
27
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PlaybackState } from '../interfaces';
|
|
2
|
+
/**
|
|
3
|
+
* Get current playback state and subsequent updates.
|
|
4
|
+
*
|
|
5
|
+
* Note: While it is fetching the initial state from the native module, the
|
|
6
|
+
* returned state property will be `undefined`.
|
|
7
|
+
* */
|
|
8
|
+
export declare const usePlaybackState: () => PlaybackState | {
|
|
9
|
+
state: undefined;
|
|
10
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { getPlaybackState, addEventListener } from '../trackPlayer';
|
|
3
|
+
import { Event } from '../constants';
|
|
4
|
+
/**
|
|
5
|
+
* Get current playback state and subsequent updates.
|
|
6
|
+
*
|
|
7
|
+
* Note: While it is fetching the initial state from the native module, the
|
|
8
|
+
* returned state property will be `undefined`.
|
|
9
|
+
* */
|
|
10
|
+
export const usePlaybackState = () => {
|
|
11
|
+
const [playbackState, setPlaybackState] = useState({
|
|
12
|
+
state: undefined,
|
|
13
|
+
});
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
let mounted = true;
|
|
16
|
+
getPlaybackState()
|
|
17
|
+
.then((fetchedState) => {
|
|
18
|
+
if (!mounted)
|
|
19
|
+
return;
|
|
20
|
+
// Only set the state if it wasn't already set by the Event.PlaybackState listener below:
|
|
21
|
+
setPlaybackState((currentState) => currentState.state ? currentState : fetchedState);
|
|
22
|
+
})
|
|
23
|
+
.catch(() => {
|
|
24
|
+
/** getState only throw while you haven't yet setup, ignore failure. */
|
|
25
|
+
});
|
|
26
|
+
const sub = addEventListener(Event.PlaybackState, (state) => {
|
|
27
|
+
setPlaybackState(state);
|
|
28
|
+
});
|
|
29
|
+
return () => {
|
|
30
|
+
mounted = false;
|
|
31
|
+
sub.remove();
|
|
32
|
+
};
|
|
33
|
+
}, []);
|
|
34
|
+
return playbackState;
|
|
35
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Progress } from '../interfaces';
|
|
2
|
+
/**
|
|
3
|
+
* Poll for track progress for the given interval (in miliseconds)
|
|
4
|
+
* @param updateInterval - ms interval
|
|
5
|
+
* @param background - if update state in background. default true. may severely affects performance.
|
|
6
|
+
*/
|
|
7
|
+
export declare function useProgress(updateInterval?: number, background?: boolean): Progress;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { AppState } from 'react-native';
|
|
3
|
+
import { getProgress } from '../trackPlayer';
|
|
4
|
+
import { Event } from '../constants';
|
|
5
|
+
import { useTrackPlayerEvents } from './useTrackPlayerEvents';
|
|
6
|
+
const INITIAL_STATE = {
|
|
7
|
+
position: 0,
|
|
8
|
+
duration: 0,
|
|
9
|
+
buffered: 0,
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Poll for track progress for the given interval (in miliseconds)
|
|
13
|
+
* @param updateInterval - ms interval
|
|
14
|
+
* @param background - if update state in background. default true. may severely affects performance.
|
|
15
|
+
*/
|
|
16
|
+
export function useProgress(updateInterval = 1000, background = true) {
|
|
17
|
+
const [state, setState] = useState(INITIAL_STATE);
|
|
18
|
+
useTrackPlayerEvents([Event.PlaybackActiveTrackChanged], () => {
|
|
19
|
+
setState(INITIAL_STATE);
|
|
20
|
+
});
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
let mounted = true;
|
|
23
|
+
const update = async () => {
|
|
24
|
+
try {
|
|
25
|
+
if (!mounted)
|
|
26
|
+
return;
|
|
27
|
+
if (!background && AppState.currentState !== 'active')
|
|
28
|
+
return;
|
|
29
|
+
const { position, duration, buffered } = await getProgress();
|
|
30
|
+
setState((state) => position === state.position &&
|
|
31
|
+
duration === state.duration &&
|
|
32
|
+
buffered === state.buffered
|
|
33
|
+
? state
|
|
34
|
+
: { position, duration, buffered });
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
// these method only throw while you haven't yet setup, ignore failure.
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const poll = async () => {
|
|
41
|
+
await update();
|
|
42
|
+
if (!mounted)
|
|
43
|
+
return;
|
|
44
|
+
await new Promise((resolve) => setTimeout(resolve, updateInterval));
|
|
45
|
+
if (!mounted)
|
|
46
|
+
return;
|
|
47
|
+
poll();
|
|
48
|
+
};
|
|
49
|
+
poll();
|
|
50
|
+
return () => {
|
|
51
|
+
mounted = false;
|
|
52
|
+
};
|
|
53
|
+
}, [updateInterval]);
|
|
54
|
+
return state;
|
|
55
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Event } from '../constants';
|
|
2
|
+
import type { EventPayloadByEventWithType } from '../interfaces';
|
|
3
|
+
/**
|
|
4
|
+
* Attaches a handler to the given TrackPlayer events and performs cleanup on unmount
|
|
5
|
+
* @param events - TrackPlayer events to subscribe to
|
|
6
|
+
* @param handler - callback invoked when the event fires
|
|
7
|
+
*/
|
|
8
|
+
export declare const useTrackPlayerEvents: <T extends Event[], H extends (data: EventPayloadByEventWithType[T[number]]) => void>(events: T, handler: H) => void;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { addEventListener } from '../trackPlayer';
|
|
3
|
+
import { Event } from '../constants';
|
|
4
|
+
/**
|
|
5
|
+
* Attaches a handler to the given TrackPlayer events and performs cleanup on unmount
|
|
6
|
+
* @param events - TrackPlayer events to subscribe to
|
|
7
|
+
* @param handler - callback invoked when the event fires
|
|
8
|
+
*/
|
|
9
|
+
export const useTrackPlayerEvents = (events, handler) => {
|
|
10
|
+
const savedHandler = useRef(handler);
|
|
11
|
+
savedHandler.current = handler;
|
|
12
|
+
/* eslint-disable react-hooks/exhaustive-deps */
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
if (__DEV__) {
|
|
15
|
+
const allowedTypes = Object.values(Event);
|
|
16
|
+
const invalidTypes = events.filter((type) => !allowedTypes.includes(type));
|
|
17
|
+
if (invalidTypes.length) {
|
|
18
|
+
console.warn('One or more of the events provided to useTrackPlayerEvents is ' +
|
|
19
|
+
`not a valid TrackPlayer event: ${invalidTypes.join("', '")}. ` +
|
|
20
|
+
'A list of available events can be found at ' +
|
|
21
|
+
'https://rntp.dev/docs/api/events');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const subs = events.map((type) => addEventListener(type, (payload) => {
|
|
25
|
+
// @ts-expect-error - we know the type is correct
|
|
26
|
+
savedHandler.current({ ...payload, type });
|
|
27
|
+
}));
|
|
28
|
+
return () => subs.forEach((sub) => sub.remove());
|
|
29
|
+
}, events);
|
|
30
|
+
};
|
package/lib/src/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { AppKilledPlaybackBehavior } from '../constants';
|
|
2
|
+
export interface AndroidOptions {
|
|
3
|
+
/**
|
|
4
|
+
* parses embedded artwork on local files to a dedicated png path.
|
|
5
|
+
* This is only necessary for certain MediaBrowsers, namely Android Auto to
|
|
6
|
+
* read embedded artwork.
|
|
7
|
+
* @default false
|
|
8
|
+
*/
|
|
9
|
+
androidParseEmbeddedArtwork?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Whether the audio playback notification is also removed when the playback
|
|
12
|
+
* stops. **If `stoppingAppPausesPlayback` is set to false, this will be
|
|
13
|
+
* ignored.**
|
|
14
|
+
*/
|
|
15
|
+
appKilledPlaybackBehavior?: AppKilledPlaybackBehavior;
|
|
16
|
+
/**
|
|
17
|
+
* Whether the remote-duck event will be triggered on every interruption
|
|
18
|
+
*/
|
|
19
|
+
alwaysPauseOnInterruption?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Time in seconds to wait once the player should transition to not
|
|
22
|
+
* considering the service as in the foreground. If playback resumes within
|
|
23
|
+
* this grace period, the service remains in the foreground state.
|
|
24
|
+
* Defaults to 5 seconds.
|
|
25
|
+
*/
|
|
26
|
+
stopForegroundGracePeriod?: number;
|
|
27
|
+
/**
|
|
28
|
+
* https://developer.android.com/media/media3/exoplayer/track-selection#audioOffload
|
|
29
|
+
*/
|
|
30
|
+
audioOffload?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* enables exoplayer's skipSilence parser
|
|
33
|
+
* @default false
|
|
34
|
+
*/
|
|
35
|
+
androidSkipSilence?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* enables exoplayer's shuffle mode
|
|
38
|
+
* @default false
|
|
39
|
+
*/
|
|
40
|
+
shuffle?: boolean;
|
|
41
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ResourceObject } from './ResourceObject';
|
|
2
|
+
import { MediaItemPlayable } from '../constants';
|
|
3
|
+
export interface MediaItem {
|
|
4
|
+
mediaId: string;
|
|
5
|
+
title: string;
|
|
6
|
+
subtitle?: string;
|
|
7
|
+
/**mediaUri doesn't seem to work. use Event.RemotePlayId to handle playback instead. */
|
|
8
|
+
mediaUri?: string | ResourceObject;
|
|
9
|
+
iconUri?: string | ResourceObject;
|
|
10
|
+
/** playable has 2 states: 1 as browsable, or any other as playable. */
|
|
11
|
+
playable: MediaItemPlayable.MediaBrowsable | string;
|
|
12
|
+
groupTitle?: string;
|
|
13
|
+
contentStyle?: string;
|
|
14
|
+
childrenPlayableContentStyle?: string;
|
|
15
|
+
childrenBrowsableContentStyle?: string;
|
|
16
|
+
/** playbackProgress should contain a string representation of a number between 0 and 1 if present */
|
|
17
|
+
playbackProgress?: string;
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { AndroidAudioContentType, IOSCategory, IOSCategoryMode, IOSCategoryOptions } from '../constants';
|
|
2
|
+
export interface PlayerOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Minimum duration of media that the player will attempt to buffer in seconds.
|
|
5
|
+
*
|
|
6
|
+
* Supported on Android & iOS.
|
|
7
|
+
*
|
|
8
|
+
* @throws Will throw on Android if min buffer is higher than max buffer.
|
|
9
|
+
* @default 50
|
|
10
|
+
*/
|
|
11
|
+
minBuffer?: number;
|
|
12
|
+
/**
|
|
13
|
+
* Maximum duration of media that the player will attempt to buffer in seconds.
|
|
14
|
+
* Max buffer may not be lower than min buffer.
|
|
15
|
+
*
|
|
16
|
+
* Supported on Android only.
|
|
17
|
+
*
|
|
18
|
+
* @throws Will throw if max buffer is lower than min buffer.
|
|
19
|
+
* @default 50
|
|
20
|
+
*/
|
|
21
|
+
maxBuffer?: number;
|
|
22
|
+
/**
|
|
23
|
+
* Duration in seconds that should be kept in the buffer behind the current
|
|
24
|
+
* playhead time.
|
|
25
|
+
*
|
|
26
|
+
* Supported on Android only.
|
|
27
|
+
*
|
|
28
|
+
* @default 0
|
|
29
|
+
*/
|
|
30
|
+
backBuffer?: number;
|
|
31
|
+
/**
|
|
32
|
+
* Duration of media in seconds that must be buffered for playback to start or
|
|
33
|
+
* resume following a user action such as a seek.
|
|
34
|
+
*
|
|
35
|
+
* Supported on Android only.
|
|
36
|
+
*
|
|
37
|
+
* @default 2.5
|
|
38
|
+
*/
|
|
39
|
+
playBuffer?: number;
|
|
40
|
+
/**
|
|
41
|
+
* Maximum cache size in kilobytes.
|
|
42
|
+
*
|
|
43
|
+
* Supported on Android only.
|
|
44
|
+
*
|
|
45
|
+
* @default 0
|
|
46
|
+
*/
|
|
47
|
+
maxCacheSize?: number;
|
|
48
|
+
/**
|
|
49
|
+
* [AVAudioSession.Category](https://developer.apple.com/documentation/avfoundation/avaudiosession/1616615-category)
|
|
50
|
+
* for iOS. Sets on `play()`.
|
|
51
|
+
*/
|
|
52
|
+
iosCategory?: IOSCategory;
|
|
53
|
+
/**
|
|
54
|
+
* (iOS only) The audio session mode, together with the audio session category,
|
|
55
|
+
* indicates to the system how you intend to use audio in your app. You can use
|
|
56
|
+
* a mode to configure the audio system for specific use cases such as video
|
|
57
|
+
* recording, voice or video chat, or audio analysis.
|
|
58
|
+
* Sets on `play()`.
|
|
59
|
+
*
|
|
60
|
+
* See https://developer.apple.com/documentation/avfoundation/avaudiosession/1616508-mode
|
|
61
|
+
*/
|
|
62
|
+
iosCategoryMode?: IOSCategoryMode;
|
|
63
|
+
/**
|
|
64
|
+
* [AVAudioSession.CategoryOptions](https://developer.apple.com/documentation/avfoundation/avaudiosession/1616503-categoryoptions) for iOS.
|
|
65
|
+
* Sets on `play()`.
|
|
66
|
+
*/
|
|
67
|
+
iosCategoryOptions?: IOSCategoryOptions[];
|
|
68
|
+
/**
|
|
69
|
+
* (Android only) The audio content type indicates to the android system how
|
|
70
|
+
* you intend to use audio in your app.
|
|
71
|
+
*
|
|
72
|
+
* With `autoHandleInterruptions: true` and
|
|
73
|
+
* `androidAudioContentType: AndroidAudioContentType.Speech`, the audio will be
|
|
74
|
+
* paused during short interruptions, such as when a message arrives.
|
|
75
|
+
* Otherwise the playback volume is reduced while the notification is playing.
|
|
76
|
+
*
|
|
77
|
+
* @default AndroidAudioContentType.Music
|
|
78
|
+
*/
|
|
79
|
+
androidAudioContentType?: AndroidAudioContentType;
|
|
80
|
+
/**
|
|
81
|
+
* auto pause playback when playback device changes from headset to speaker.
|
|
82
|
+
* @default true
|
|
83
|
+
*/
|
|
84
|
+
androidHandleAudioBecomingNoisy?: boolean;
|
|
85
|
+
/**
|
|
86
|
+
* always show next and previous as android player command. this overrides
|
|
87
|
+
* exoplayer disabling the next button on playmode != all and at queue's end.
|
|
88
|
+
* @default true
|
|
89
|
+
*/
|
|
90
|
+
androidAlwaysShowNext?: boolean;
|
|
91
|
+
/**
|
|
92
|
+
* enables exoplayer's skipSilence parser
|
|
93
|
+
* @default false
|
|
94
|
+
*/
|
|
95
|
+
androidSkipSilence?: boolean;
|
|
96
|
+
/**
|
|
97
|
+
* set android exoplayer wake mode. 1 is WAKE_MODE_LOCAL, 2 is WAKE_MODE_NETWORK,
|
|
98
|
+
* and others is WAKE_MODE_NONE.
|
|
99
|
+
* @default 0
|
|
100
|
+
*/
|
|
101
|
+
androidWakeMode?: number;
|
|
102
|
+
/**
|
|
103
|
+
* Indicates whether the player should automatically delay playback in order to minimize stalling.
|
|
104
|
+
* Defaults to `true`.
|
|
105
|
+
* @deprecated This option has been nominated for removal in a future version
|
|
106
|
+
* of RNTP. If you have this set to `true`, you can safely remove this from
|
|
107
|
+
* the options. If you are setting this to `false` and have a reason for that,
|
|
108
|
+
* please post a comment in the following discussion: https://github.com/doublesymmetry/react-native-track-player/pull/1695
|
|
109
|
+
* and describe why you are doing so.
|
|
110
|
+
*/
|
|
111
|
+
waitForBuffer?: boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Indicates whether the player should automatically update now playing metadata data in control center / notification.
|
|
114
|
+
* Defaults to `true`.
|
|
115
|
+
*/
|
|
116
|
+
autoUpdateMetadata?: boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Indicates whether the player should automatically handle audio interruptions.
|
|
119
|
+
* Defaults to `false`.
|
|
120
|
+
*/
|
|
121
|
+
autoHandleInterruptions?: boolean;
|
|
122
|
+
/**
|
|
123
|
+
* enables crossfade. android only.
|
|
124
|
+
* Defaults to `false`.
|
|
125
|
+
*/
|
|
126
|
+
crossfade?: boolean;
|
|
127
|
+
/**
|
|
128
|
+
* applies an FFT processor with the given sampling size. android only.
|
|
129
|
+
* Defaults to 0 (disables it).
|
|
130
|
+
*/
|
|
131
|
+
useFFTProcessor?: number;
|
|
132
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface Progress {
|
|
2
|
+
/**
|
|
3
|
+
* The playback position of the current track in seconds.
|
|
4
|
+
* See https://rntp.dev/docs/api/functions/player#getposition
|
|
5
|
+
**/
|
|
6
|
+
position: number;
|
|
7
|
+
/** The duration of the current track in seconds.
|
|
8
|
+
* See https://rntp.dev/docs/api/functions/player#getduration
|
|
9
|
+
**/
|
|
10
|
+
duration: number;
|
|
11
|
+
/**
|
|
12
|
+
* The buffered position of the current track in seconds.
|
|
13
|
+
**/
|
|
14
|
+
buffered: number;
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type ResourceObject = number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type ServiceHandler = () => Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|