@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,158 @@
|
|
|
1
|
+
//
|
|
2
|
+
// AudioItem.swift
|
|
3
|
+
// SwiftAudio
|
|
4
|
+
//
|
|
5
|
+
// Created by Jørgen Henrichsen on 18/03/2018.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import AVFoundation
|
|
10
|
+
|
|
11
|
+
#if os(iOS)
|
|
12
|
+
import UIKit
|
|
13
|
+
public typealias AudioItemImage = UIImage
|
|
14
|
+
#elseif os(macOS)
|
|
15
|
+
import AppKit
|
|
16
|
+
public typealias AudioItemImage = NSImage
|
|
17
|
+
#endif
|
|
18
|
+
|
|
19
|
+
public enum SourceType {
|
|
20
|
+
case stream
|
|
21
|
+
case file
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public protocol AudioItem {
|
|
25
|
+
func getSourceUrl() -> String
|
|
26
|
+
func getArtist() -> String?
|
|
27
|
+
func getTitle() -> String?
|
|
28
|
+
func getAlbumTitle() -> String?
|
|
29
|
+
func getSourceType() -> SourceType
|
|
30
|
+
func getArtwork(_ handler: @escaping (AudioItemImage?) -> Void)
|
|
31
|
+
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/// Make your `AudioItem`-subclass conform to this protocol to control which AVAudioTimePitchAlgorithm is used for each item.
|
|
35
|
+
public protocol TimePitching {
|
|
36
|
+
func getPitchAlgorithmType() -> AVAudioTimePitchAlgorithm
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/// Make your `AudioItem`-subclass conform to this protocol to control enable the ability to start an item at a specific time of playback.
|
|
41
|
+
public protocol InitialTiming {
|
|
42
|
+
func getInitialTime() -> TimeInterval
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/// Make your `AudioItem`-subclass conform to this protocol to set initialization options for the asset. Available keys available at [Apple Developer Documentation](https://developer.apple.com/documentation/avfoundation/avurlasset/initialization_options).
|
|
46
|
+
public protocol AssetOptionsProviding {
|
|
47
|
+
func getAssetOptions() -> [String: Any]
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public class DefaultAudioItem: AudioItem, Identifiable {
|
|
51
|
+
|
|
52
|
+
public var audioUrl: String
|
|
53
|
+
|
|
54
|
+
public var artist: String?
|
|
55
|
+
|
|
56
|
+
public var title: String?
|
|
57
|
+
|
|
58
|
+
public var albumTitle: String?
|
|
59
|
+
|
|
60
|
+
public var sourceType: SourceType
|
|
61
|
+
|
|
62
|
+
public var artwork: AudioItemImage?
|
|
63
|
+
|
|
64
|
+
public init(audioUrl: String, artist: String? = nil, title: String? = nil, albumTitle: String? = nil, sourceType: SourceType, artwork: AudioItemImage? = nil) {
|
|
65
|
+
self.audioUrl = audioUrl
|
|
66
|
+
self.artist = artist
|
|
67
|
+
self.title = title
|
|
68
|
+
self.albumTitle = albumTitle
|
|
69
|
+
self.sourceType = sourceType
|
|
70
|
+
self.artwork = artwork
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public func getSourceUrl() -> String {
|
|
74
|
+
audioUrl
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public func getArtist() -> String? {
|
|
78
|
+
artist
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
public func getTitle() -> String? {
|
|
82
|
+
title
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public func getAlbumTitle() -> String? {
|
|
86
|
+
albumTitle
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public func getSourceType() -> SourceType {
|
|
90
|
+
sourceType
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
public func getArtwork(_ handler: @escaping (AudioItemImage?) -> Void) {
|
|
94
|
+
handler(artwork)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/// An AudioItem that also conforms to the `TimePitching`-protocol
|
|
100
|
+
public class DefaultAudioItemTimePitching: DefaultAudioItem, TimePitching {
|
|
101
|
+
|
|
102
|
+
public var pitchAlgorithmType: AVAudioTimePitchAlgorithm
|
|
103
|
+
|
|
104
|
+
public override init(audioUrl: String, artist: String?, title: String?, albumTitle: String?, sourceType: SourceType, artwork: AudioItemImage?) {
|
|
105
|
+
pitchAlgorithmType = AVAudioTimePitchAlgorithm.timeDomain
|
|
106
|
+
super.init(audioUrl: audioUrl, artist: artist, title: title, albumTitle: albumTitle, sourceType: sourceType, artwork: artwork)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
public init(audioUrl: String, artist: String?, title: String?, albumTitle: String?, sourceType: SourceType, artwork: AudioItemImage?, audioTimePitchAlgorithm: AVAudioTimePitchAlgorithm) {
|
|
110
|
+
pitchAlgorithmType = audioTimePitchAlgorithm
|
|
111
|
+
super.init(audioUrl: audioUrl, artist: artist, title: title, albumTitle: albumTitle, sourceType: sourceType, artwork: artwork)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
public func getPitchAlgorithmType() -> AVAudioTimePitchAlgorithm {
|
|
115
|
+
pitchAlgorithmType
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/// An AudioItem that also conforms to the `InitialTiming`-protocol
|
|
120
|
+
public class DefaultAudioItemInitialTime: DefaultAudioItem, InitialTiming {
|
|
121
|
+
|
|
122
|
+
public var initialTime: TimeInterval
|
|
123
|
+
|
|
124
|
+
public override init(audioUrl: String, artist: String?, title: String?, albumTitle: String?, sourceType: SourceType, artwork: AudioItemImage?) {
|
|
125
|
+
initialTime = 0.0
|
|
126
|
+
super.init(audioUrl: audioUrl, artist: artist, title: title, albumTitle: albumTitle, sourceType: sourceType, artwork: artwork)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
public init(audioUrl: String, artist: String?, title: String?, albumTitle: String?, sourceType: SourceType, artwork: AudioItemImage?, initialTime: TimeInterval) {
|
|
130
|
+
self.initialTime = initialTime
|
|
131
|
+
super.init(audioUrl: audioUrl, artist: artist, title: title, albumTitle: albumTitle, sourceType: sourceType, artwork: artwork)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
public func getInitialTime() -> TimeInterval {
|
|
135
|
+
initialTime
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/// An AudioItem that also conforms to the `AssetOptionsProviding`-protocol
|
|
141
|
+
public class DefaultAudioItemAssetOptionsProviding: DefaultAudioItem, AssetOptionsProviding {
|
|
142
|
+
|
|
143
|
+
public var options: [String: Any]
|
|
144
|
+
|
|
145
|
+
public override init(audioUrl: String, artist: String?, title: String?, albumTitle: String?, sourceType: SourceType, artwork: AudioItemImage?) {
|
|
146
|
+
options = [:]
|
|
147
|
+
super.init(audioUrl: audioUrl, artist: artist, title: title, albumTitle: albumTitle, sourceType: sourceType, artwork: artwork)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
public init(audioUrl: String, artist: String?, title: String?, albumTitle: String?, sourceType: SourceType, artwork: AudioItemImage?, options: [String: Any]) {
|
|
151
|
+
self.options = options
|
|
152
|
+
super.init(audioUrl: audioUrl, artist: artist, title: title, albumTitle: albumTitle, sourceType: sourceType, artwork: artwork)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
public func getAssetOptions() -> [String: Any] {
|
|
156
|
+
options
|
|
157
|
+
}
|
|
158
|
+
}
|
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
//
|
|
2
|
+
// AudioPlayer.swift
|
|
3
|
+
// SwiftAudio
|
|
4
|
+
//
|
|
5
|
+
// Created by Jørgen Henrichsen on 15/03/2018.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import MediaPlayer
|
|
10
|
+
|
|
11
|
+
public typealias AudioPlayerState = AVPlayerWrapperState
|
|
12
|
+
|
|
13
|
+
public class AudioPlayer: AVPlayerWrapperDelegate {
|
|
14
|
+
/// The wrapper around the underlying AVPlayer
|
|
15
|
+
let wrapper: AVPlayerWrapperProtocol = AVPlayerWrapper()
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
Set an instance of AudioTap, to receive frame information and audio buffer access during playback.
|
|
20
|
+
*/
|
|
21
|
+
public var audioTap: AudioTap? {
|
|
22
|
+
get { return wrapper.audioTap }
|
|
23
|
+
set(value) { wrapper.audioTap = value }
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
public let nowPlayingInfoController: NowPlayingInfoControllerProtocol
|
|
28
|
+
public let remoteCommandController: RemoteCommandController
|
|
29
|
+
public let event = EventHolder()
|
|
30
|
+
|
|
31
|
+
private(set) var currentItem: AudioItem?
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
Set this to false to disable automatic updating of now playing info for control center and lock screen.
|
|
35
|
+
*/
|
|
36
|
+
public var automaticallyUpdateNowPlayingInfo: Bool = true
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
Controls the time pitch algorithm applied to each item loaded into the player.
|
|
40
|
+
If the loaded `AudioItem` conforms to `TimePitcher`-protocol this will be overriden.
|
|
41
|
+
*/
|
|
42
|
+
public var audioTimePitchAlgorithm: AVAudioTimePitchAlgorithm = AVAudioTimePitchAlgorithm.timeDomain
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
Default remote commands to use for each playing item
|
|
46
|
+
*/
|
|
47
|
+
public var remoteCommands: [RemoteCommand] = [] {
|
|
48
|
+
didSet {
|
|
49
|
+
if let item = currentItem {
|
|
50
|
+
self.enableRemoteCommands(forItem: item)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
Handles the `playWhenReady` setting while executing a given action.
|
|
57
|
+
|
|
58
|
+
This method takes an optional `Bool` value and a closure representing an action to execute.
|
|
59
|
+
If the `Bool` value is not `nil`, `self.playWhenReady` is set accordingly either before or
|
|
60
|
+
after executing the action.
|
|
61
|
+
|
|
62
|
+
- Parameters:
|
|
63
|
+
- playWhenReady: Optional `Bool` to set `self.playWhenReady`.
|
|
64
|
+
- If `true`, `self.playWhenReady` will be set after executing the action.
|
|
65
|
+
- If `false`, `self.playWhenReady` will be set before executing the action.
|
|
66
|
+
- If `nil`, `self.playWhenReady` will not be changed.
|
|
67
|
+
- action: A closure representing the action to execute. This closure can throw an error.
|
|
68
|
+
|
|
69
|
+
- Throws: This function will propagate any errors thrown by the `action` closure.
|
|
70
|
+
*/
|
|
71
|
+
internal func handlePlayWhenReady(_ playWhenReady: Bool?, action: () throws -> Void) rethrows {
|
|
72
|
+
if playWhenReady == false {
|
|
73
|
+
self.playWhenReady = false
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
try action()
|
|
77
|
+
|
|
78
|
+
if playWhenReady == true, playbackError == nil {
|
|
79
|
+
self.playWhenReady = true
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// MARK: - Getters from AVPlayerWrapper
|
|
84
|
+
|
|
85
|
+
public var playbackError: AudioPlayerError.PlaybackError? {
|
|
86
|
+
wrapper.playbackError
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
The elapsed playback time of the current item.
|
|
91
|
+
*/
|
|
92
|
+
public var currentTime: Double {
|
|
93
|
+
wrapper.currentTime
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
The duration of the current AudioItem.
|
|
98
|
+
*/
|
|
99
|
+
public var duration: Double {
|
|
100
|
+
wrapper.duration
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
The bufferedPosition of the current AudioItem.
|
|
105
|
+
*/
|
|
106
|
+
public var bufferedPosition: Double {
|
|
107
|
+
wrapper.bufferedPosition
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
The current state of the underlying `AudioPlayer`.
|
|
112
|
+
*/
|
|
113
|
+
public var playerState: AudioPlayerState {
|
|
114
|
+
wrapper.state
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// MARK: - Setters for AVPlayerWrapper
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
Whether the player should start playing automatically when the item is ready.
|
|
121
|
+
*/
|
|
122
|
+
public var playWhenReady: Bool {
|
|
123
|
+
get { wrapper.playWhenReady }
|
|
124
|
+
set {
|
|
125
|
+
wrapper.playWhenReady = newValue
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
The amount of seconds to be buffered by the player. Default value is 0 seconds, this means the AVPlayer will choose an appropriate level of buffering. Setting `bufferDuration` to larger than zero automatically disables `automaticallyWaitsToMinimizeStalling`. Setting it back to zero automatically enables `automaticallyWaitsToMinimizeStalling`.
|
|
131
|
+
|
|
132
|
+
[Read more from Apple Documentation](https://developer.apple.com/documentation/avfoundation/avplayeritem/1643630-preferredforwardbufferduration)
|
|
133
|
+
*/
|
|
134
|
+
public var bufferDuration: TimeInterval {
|
|
135
|
+
get { wrapper.bufferDuration }
|
|
136
|
+
set {
|
|
137
|
+
wrapper.bufferDuration = newValue
|
|
138
|
+
wrapper.automaticallyWaitsToMinimizeStalling = wrapper.bufferDuration == 0
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
Indicates whether the player should automatically delay playback in order to minimize stalling. Setting this to true will also set `bufferDuration` back to `0`.
|
|
144
|
+
|
|
145
|
+
[Read more from Apple Documentation](https://developer.apple.com/documentation/avfoundation/avplayer/1643482-automaticallywaitstominimizestal)
|
|
146
|
+
*/
|
|
147
|
+
public var automaticallyWaitsToMinimizeStalling: Bool {
|
|
148
|
+
get { wrapper.automaticallyWaitsToMinimizeStalling }
|
|
149
|
+
set {
|
|
150
|
+
if (newValue) {
|
|
151
|
+
wrapper.bufferDuration = 0
|
|
152
|
+
}
|
|
153
|
+
wrapper.automaticallyWaitsToMinimizeStalling = newValue
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
Set this to decide how often the player should call the delegate with time progress events.
|
|
159
|
+
*/
|
|
160
|
+
public var timeEventFrequency: TimeEventFrequency {
|
|
161
|
+
get { wrapper.timeEventFrequency }
|
|
162
|
+
set { wrapper.timeEventFrequency = newValue }
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
public var volume: Float {
|
|
166
|
+
get { wrapper.volume }
|
|
167
|
+
set { wrapper.volume = newValue }
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
public var isMuted: Bool {
|
|
171
|
+
get { wrapper.isMuted }
|
|
172
|
+
set { wrapper.isMuted = newValue }
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
public var rate: Float {
|
|
176
|
+
get { wrapper.rate }
|
|
177
|
+
set {
|
|
178
|
+
wrapper.rate = newValue
|
|
179
|
+
if (automaticallyUpdateNowPlayingInfo) {
|
|
180
|
+
updateNowPlayingPlaybackValues()
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// MARK: - Init
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
Create a new AudioPlayer.
|
|
189
|
+
|
|
190
|
+
- parameter infoCenter: The InfoCenter to update. Default is `MPNowPlayingInfoCenter.default()`.
|
|
191
|
+
*/
|
|
192
|
+
public init(nowPlayingInfoController: NowPlayingInfoControllerProtocol = NowPlayingInfoController(),
|
|
193
|
+
remoteCommandController: RemoteCommandController = RemoteCommandController()) {
|
|
194
|
+
self.nowPlayingInfoController = nowPlayingInfoController
|
|
195
|
+
self.remoteCommandController = remoteCommandController
|
|
196
|
+
|
|
197
|
+
wrapper.delegate = self
|
|
198
|
+
self.remoteCommandController.audioPlayer = self
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// MARK: - Player Actions
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
Load an AudioItem into the manager.
|
|
205
|
+
|
|
206
|
+
- parameter item: The AudioItem to load. The info given in this item is the one used for the InfoCenter.
|
|
207
|
+
- parameter playWhenReady: Optional, whether to start playback when the item is ready.
|
|
208
|
+
*/
|
|
209
|
+
public func load(item: AudioItem, playWhenReady: Bool? = nil) {
|
|
210
|
+
handlePlayWhenReady(playWhenReady) {
|
|
211
|
+
currentItem = item
|
|
212
|
+
|
|
213
|
+
if (automaticallyUpdateNowPlayingInfo) {
|
|
214
|
+
// Reset playback values without updating, because that will happen in
|
|
215
|
+
// the loadNowPlayingMetaValues call straight after:
|
|
216
|
+
nowPlayingInfoController.setWithoutUpdate(keyValues: [
|
|
217
|
+
MediaItemProperty.duration(nil),
|
|
218
|
+
NowPlayingInfoProperty.playbackRate(nil),
|
|
219
|
+
NowPlayingInfoProperty.elapsedPlaybackTime(nil)
|
|
220
|
+
])
|
|
221
|
+
loadNowPlayingMetaValues()
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
enableRemoteCommands(forItem: item)
|
|
225
|
+
|
|
226
|
+
wrapper.load(
|
|
227
|
+
from: item.getSourceUrl(),
|
|
228
|
+
type: item.getSourceType(),
|
|
229
|
+
playWhenReady: self.playWhenReady,
|
|
230
|
+
initialTime: (item as? InitialTiming)?.getInitialTime(),
|
|
231
|
+
options:(item as? AssetOptionsProviding)?.getAssetOptions()
|
|
232
|
+
)
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
Toggle playback status.
|
|
238
|
+
*/
|
|
239
|
+
public func togglePlaying() {
|
|
240
|
+
wrapper.togglePlaying()
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
Start playback
|
|
245
|
+
*/
|
|
246
|
+
public func play() {
|
|
247
|
+
wrapper.play()
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
Pause playback
|
|
252
|
+
*/
|
|
253
|
+
public func pause() {
|
|
254
|
+
wrapper.pause()
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
Stop playback
|
|
259
|
+
*/
|
|
260
|
+
public func stop() {
|
|
261
|
+
let wasActive = wrapper.playbackActive
|
|
262
|
+
wrapper.stop()
|
|
263
|
+
if (wasActive) {
|
|
264
|
+
event.playbackEnd.emit(data: .playerStopped)
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
Reload the current item.
|
|
270
|
+
*/
|
|
271
|
+
public func reload(startFromCurrentTime: Bool) {
|
|
272
|
+
wrapper.reload(startFromCurrentTime: startFromCurrentTime)
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
Seek to a specific time in the item.
|
|
277
|
+
*/
|
|
278
|
+
public func seek(to seconds: TimeInterval) {
|
|
279
|
+
wrapper.seek(to: seconds)
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
Seek by relative a time offset in the item.
|
|
284
|
+
*/
|
|
285
|
+
public func seek(by offset: TimeInterval) {
|
|
286
|
+
wrapper.seek(by: offset)
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// MARK: - Remote Command Center
|
|
290
|
+
|
|
291
|
+
func enableRemoteCommands(_ commands: [RemoteCommand]) {
|
|
292
|
+
remoteCommandController.enable(commands: commands)
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
func enableRemoteCommands(forItem item: AudioItem) {
|
|
296
|
+
if let item = item as? RemoteCommandable {
|
|
297
|
+
self.enableRemoteCommands(item.getCommands())
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
self.enableRemoteCommands(remoteCommands)
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
Syncs the current remoteCommands with the iOS command center.
|
|
306
|
+
Can be used to update item states - e.g. like, dislike and bookmark.
|
|
307
|
+
*/
|
|
308
|
+
@available(*, deprecated, message: "Directly set .remoteCommands instead")
|
|
309
|
+
public func syncRemoteCommandsWithCommandCenter() {
|
|
310
|
+
self.enableRemoteCommands(remoteCommands)
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// MARK: - NowPlayingInfo
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
Loads NowPlayingInfo-meta values with the values found in the current `AudioItem`. Use this if a change to the `AudioItem` is made and you want to update the `NowPlayingInfoController`s values.
|
|
317
|
+
|
|
318
|
+
Reloads:
|
|
319
|
+
- Artist
|
|
320
|
+
- Title
|
|
321
|
+
- Album title
|
|
322
|
+
- Album artwork
|
|
323
|
+
*/
|
|
324
|
+
public func loadNowPlayingMetaValues() {
|
|
325
|
+
guard let item = currentItem else { return }
|
|
326
|
+
|
|
327
|
+
nowPlayingInfoController.set(keyValues: [
|
|
328
|
+
MediaItemProperty.artist(item.getArtist()),
|
|
329
|
+
MediaItemProperty.title(item.getTitle()),
|
|
330
|
+
MediaItemProperty.albumTitle(item.getAlbumTitle()),
|
|
331
|
+
])
|
|
332
|
+
loadArtwork(forItem: item)
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
Resyncs the playbackvalues of the currently playing `AudioItem`.
|
|
337
|
+
|
|
338
|
+
Will resync:
|
|
339
|
+
- Current time
|
|
340
|
+
- Duration
|
|
341
|
+
- Playback rate
|
|
342
|
+
*/
|
|
343
|
+
func updateNowPlayingPlaybackValues() {
|
|
344
|
+
nowPlayingInfoController.set(keyValues: [
|
|
345
|
+
MediaItemProperty.duration(wrapper.duration),
|
|
346
|
+
NowPlayingInfoProperty.playbackRate(wrapper.playWhenReady ? Double(wrapper.rate) : 0),
|
|
347
|
+
NowPlayingInfoProperty.elapsedPlaybackTime(wrapper.currentTime)
|
|
348
|
+
])
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
public func clear() {
|
|
352
|
+
let playbackWasActive = wrapper.playbackActive
|
|
353
|
+
currentItem = nil
|
|
354
|
+
wrapper.unload()
|
|
355
|
+
nowPlayingInfoController.clear()
|
|
356
|
+
if (playbackWasActive) {
|
|
357
|
+
event.playbackEnd.emit(data: .cleared)
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// MARK: - Private
|
|
362
|
+
|
|
363
|
+
private func setNowPlayingCurrentTime(seconds: Double) {
|
|
364
|
+
nowPlayingInfoController.set(
|
|
365
|
+
keyValue: NowPlayingInfoProperty.elapsedPlaybackTime(seconds)
|
|
366
|
+
)
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
private func loadArtwork(forItem item: AudioItem) {
|
|
370
|
+
item.getArtwork { (image) in
|
|
371
|
+
if let image = image {
|
|
372
|
+
let artwork = MPMediaItemArtwork(boundsSize: image.size, requestHandler: { _ in image })
|
|
373
|
+
self.nowPlayingInfoController.set(keyValue: MediaItemProperty.artwork(artwork))
|
|
374
|
+
} else {
|
|
375
|
+
self.nowPlayingInfoController.set(keyValue: MediaItemProperty.artwork(nil))
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
private func setTimePitchingAlgorithmForCurrentItem() {
|
|
381
|
+
if let item = currentItem as? TimePitching {
|
|
382
|
+
wrapper.currentItem?.audioTimePitchAlgorithm = item.getPitchAlgorithmType()
|
|
383
|
+
} else {
|
|
384
|
+
wrapper.currentItem?.audioTimePitchAlgorithm = audioTimePitchAlgorithm
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// MARK: - AVPlayerWrapperDelegate
|
|
389
|
+
|
|
390
|
+
func AVWrapper(didChangeState state: AVPlayerWrapperState) {
|
|
391
|
+
switch state {
|
|
392
|
+
case .ready, .loading:
|
|
393
|
+
setTimePitchingAlgorithmForCurrentItem()
|
|
394
|
+
default: break
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
switch state {
|
|
398
|
+
case .ready, .loading, .playing, .paused:
|
|
399
|
+
if (automaticallyUpdateNowPlayingInfo) {
|
|
400
|
+
updateNowPlayingPlaybackValues()
|
|
401
|
+
}
|
|
402
|
+
default: break
|
|
403
|
+
}
|
|
404
|
+
event.stateChange.emit(data: state)
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
func AVWrapper(secondsElapsed seconds: Double) {
|
|
408
|
+
event.secondElapse.emit(data: seconds)
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
func AVWrapper(failedWithError error: Error?) {
|
|
412
|
+
event.fail.emit(data: error)
|
|
413
|
+
event.playbackEnd.emit(data: .failed)
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
func AVWrapper(seekTo seconds: Double, didFinish: Bool) {
|
|
417
|
+
if automaticallyUpdateNowPlayingInfo {
|
|
418
|
+
setNowPlayingCurrentTime(seconds: Double(seconds))
|
|
419
|
+
}
|
|
420
|
+
event.seek.emit(data: (seconds, didFinish))
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
func AVWrapper(didUpdateDuration duration: Double) {
|
|
424
|
+
event.updateDuration.emit(data: duration)
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
func AVWrapper(didReceiveCommonMetadata metadata: [AVMetadataItem]) {
|
|
428
|
+
event.receiveCommonMetadata.emit(data: metadata)
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
func AVWrapper(didReceiveChapterMetadata metadata: [AVTimedMetadataGroup]) {
|
|
432
|
+
event.receiveChapterMetadata.emit(data: metadata)
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
func AVWrapper(didReceiveTimedMetadata metadata: [AVTimedMetadataGroup]) {
|
|
436
|
+
event.receiveTimedMetadata.emit(data: metadata)
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
func AVWrapper(didChangePlayWhenReady playWhenReady: Bool) {
|
|
440
|
+
event.playWhenReadyChange.emit(data: playWhenReady)
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
func AVWrapperItemDidPlayToEndTime() {
|
|
444
|
+
event.playbackEnd.emit(data: .playedUntilEnd)
|
|
445
|
+
wrapper.state = .ended
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
func AVWrapperItemFailedToPlayToEndTime() {
|
|
449
|
+
AVWrapper(failedWithError: AudioPlayerError.PlaybackError.playbackFailed)
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
func AVWrapperItemPlaybackStalled() {
|
|
453
|
+
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
func AVWrapperDidRecreateAVPlayer() {
|
|
457
|
+
event.didRecreateAVPlayer.emit(data: ())
|
|
458
|
+
}
|
|
459
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//
|
|
2
|
+
// AudioPlayerError.swift
|
|
3
|
+
// SwiftAudio
|
|
4
|
+
//
|
|
5
|
+
// Created by Jørgen Henrichsen on 25/03/2018.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
public enum AudioPlayerError: Error {
|
|
12
|
+
|
|
13
|
+
public enum PlaybackError: Error {
|
|
14
|
+
case failedToLoadKeyValue
|
|
15
|
+
case invalidSourceUrl(String)
|
|
16
|
+
case notConnectedToInternet
|
|
17
|
+
case playbackFailed
|
|
18
|
+
case itemWasUnplayable
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public enum QueueError: Error {
|
|
22
|
+
case noCurrentItem
|
|
23
|
+
case invalidIndex(index: Int, message: String)
|
|
24
|
+
case empty
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//
|
|
2
|
+
// AudioSession.swift
|
|
3
|
+
// SwiftAudio
|
|
4
|
+
//
|
|
5
|
+
// Created by Jørgen Henrichsen on 02/11/2018.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import AVFoundation
|
|
10
|
+
|
|
11
|
+
#if os(iOS)
|
|
12
|
+
protocol AudioSession {
|
|
13
|
+
|
|
14
|
+
var isOtherAudioPlaying: Bool { get }
|
|
15
|
+
|
|
16
|
+
var category: AVAudioSession.Category { get }
|
|
17
|
+
|
|
18
|
+
var mode: AVAudioSession.Mode { get }
|
|
19
|
+
|
|
20
|
+
var categoryOptions: AVAudioSession.CategoryOptions { get }
|
|
21
|
+
|
|
22
|
+
var availableCategories: [AVAudioSession.Category] { get }
|
|
23
|
+
|
|
24
|
+
func setCategory(_ category: AVAudioSession.Category, mode: AVAudioSession.Mode, options: AVAudioSession.CategoryOptions) throws
|
|
25
|
+
|
|
26
|
+
func setCategory(_ category: AVAudioSession.Category, mode: AVAudioSession.Mode, policy: AVAudioSession.RouteSharingPolicy, options: AVAudioSession.CategoryOptions) throws
|
|
27
|
+
|
|
28
|
+
func setActive(_ active: Bool, options: AVAudioSession.SetActiveOptions) throws
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
extension AVAudioSession: AudioSession {}
|
|
33
|
+
#endif
|