@javascriptcommon/react-native-track-player 1.2.23 → 4.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -21
- package/README.md +8 -0
- package/android/build.gradle +80 -63
- package/android/proguard-rules.txt +0 -3
- package/android/src/main/AndroidManifest.xml +10 -11
- package/android/src/main/java/com/doublesymmetry/trackplayer/HeadlessJsMediaService.kt +199 -0
- package/android/src/main/java/com/doublesymmetry/trackplayer/TrackPlayer.kt +33 -0
- package/android/src/main/java/com/{guichaguri → doublesymmetry}/trackplayer/extensions/AudioPlayerStateExt.kt +3 -3
- package/android/src/main/java/com/doublesymmetry/trackplayer/extensions/EnumExtensions.kt +5 -0
- package/android/src/main/java/com/doublesymmetry/trackplayer/extensions/NumberExt.kt +13 -0
- package/android/src/main/java/com/{guichaguri → doublesymmetry}/trackplayer/model/MetadataAdapter.kt +20 -17
- package/android/src/main/java/com/doublesymmetry/trackplayer/model/NowPlayingMetadata.kt +16 -0
- package/android/src/main/java/com/{guichaguri/trackplayer/kotlinaudio/models → doublesymmetry/trackplayer/model}/PlaybackMetadata.kt +31 -28
- package/android/src/main/java/com/{guichaguri → doublesymmetry}/trackplayer/model/State.kt +1 -1
- package/android/src/main/java/com/doublesymmetry/trackplayer/model/Track.kt +67 -0
- package/android/src/main/java/com/doublesymmetry/trackplayer/model/TrackAudioItem.kt +18 -0
- package/android/src/main/java/com/doublesymmetry/trackplayer/model/TrackMetadata.kt +38 -0
- package/android/src/main/java/com/{guichaguri → doublesymmetry}/trackplayer/module/MusicEvents.kt +10 -9
- package/android/src/main/java/com/doublesymmetry/trackplayer/module/MusicModule.kt +778 -0
- package/android/src/main/java/com/doublesymmetry/trackplayer/service/MusicService.kt +1286 -0
- package/android/src/main/java/com/doublesymmetry/trackplayer/utils/AppForegroundTracker.kt +35 -0
- package/android/src/main/java/com/{guichaguri/trackplayer/service → doublesymmetry/trackplayer/utils}/BundleUtils.kt +50 -20
- package/android/src/main/java/com/doublesymmetry/trackplayer/utils/CoilBitmapLoader.kt +65 -0
- package/android/src/main/java/com/doublesymmetry/trackplayer/utils/MediaItemBuilder.kt +41 -0
- package/android/src/main/java/com/doublesymmetry/trackplayer/utils/RejectionException.kt +11 -0
- package/android/src/main/java/com/doublesymmetry/trackplayer/video/TrackPlayerVideoView.kt +42 -0
- package/android/src/main/java/com/doublesymmetry/trackplayer/video/TrackPlayerVideoViewManager.kt +18 -0
- package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/event/EventHolder.kt +7 -7
- package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/event/PlayerEventHolder.kt +22 -9
- package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/models/AudioContentType.kt +1 -1
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/AudioItem.kt +118 -0
- package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/models/AudioItemTransitionReason.kt +3 -3
- package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/models/AudioPlayerState.kt +2 -2
- package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/models/BufferConfig.kt +1 -1
- package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/models/CacheConfig.kt +1 -1
- package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/models/Capability.kt +1 -1
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/CustomButton.kt +19 -0
- package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/models/FocusChangeData.kt +1 -1
- package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/models/MediaSessionCallback.kt +1 -1
- package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/models/PlayWhenReadyChangeData.kt +1 -3
- package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/models/PlaybackEndedReason.kt +1 -1
- package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/models/PlaybackError.kt +1 -1
- package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/models/PlayerConfig.kt +8 -5
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/PlayerOptions.kt +40 -0
- package/android/src/main/java/com/{guichaguri/trackplayer → lovegaoshi}/kotlinaudio/models/PositionChangedReason.kt +1 -1
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/RepeatMode.kt +16 -0
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/models/WakeMode.kt +7 -0
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/player/AudioPlayer.kt +756 -0
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/player/ForwardingPlayer.java +1124 -0
- package/android/src/main/java/com/{guichaguri/trackplayer/kotlinaudio/players → lovegaoshi/kotlinaudio/player}/QueuedAudioPlayer.kt +68 -58
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/player/components/APMRenderersFactory.kt +33 -0
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/player/components/Buffer.kt +34 -0
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/player/components/Cache.kt +27 -0
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/player/components/FocusManager.kt +59 -0
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/player/components/MediaFactory.kt +130 -0
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/processors/TeeListener.kt +171 -0
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/service/MusicService.kt +127 -0
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/utils/FFT.java +99 -0
- package/android/src/main/java/com/lovegaoshi/kotlinaudio/utils/Utils.kt +113 -0
- package/android/src/main/res/drawable/baseline_repeat_24.xml +5 -0
- package/android/src/main/res/drawable/baseline_repeat_one_24.xml +5 -0
- package/android/src/main/res/drawable/forward.xml +5 -0
- package/android/src/main/res/drawable/heart_24px.xml +5 -0
- package/android/src/main/res/drawable/hearte_24px.xml +5 -0
- package/android/src/main/res/drawable/ifl_24px.xml +5 -0
- package/android/src/main/res/drawable/rewind.xml +5 -0
- package/android/src/main/res/drawable/shuffle_24px.xml +5 -0
- package/android/src/main/res/values/strings.xml +3 -4
- package/android/src/main/res/xml/automotive_app_desc.xml +3 -0
- package/ios/Example/SwiftAudio/Assets.xcassets/22AMI.imageset/22AMillion.jpg +0 -0
- package/ios/Example/SwiftAudio/Assets.xcassets/22AMI.imageset/Contents.json +21 -0
- package/ios/Example/SwiftAudio/Assets.xcassets/AccentColor.colorset/Contents.json +11 -0
- package/ios/Example/SwiftAudio/Assets.xcassets/AppIcon.appiconset/Contents.json +58 -0
- package/ios/Example/SwiftAudio/Assets.xcassets/Contents.json +6 -0
- package/ios/Example/SwiftAudio/Assets.xcassets/cover.imageset/Contents.json +21 -0
- package/ios/Example/SwiftAudio/Assets.xcassets/cover.imageset/cover.jpg +0 -0
- package/ios/Example/SwiftAudio/AudioController.swift +46 -0
- package/ios/Example/SwiftAudio/Extensions.swift +22 -0
- package/ios/Example/SwiftAudio/PlayerView.swift +172 -0
- package/ios/Example/SwiftAudio/PlayerViewModel.swift +120 -0
- package/ios/Example/SwiftAudio/Preview Content/Preview Assets.xcassets/Contents.json +6 -0
- package/ios/Example/SwiftAudio/QueueView.swift +65 -0
- package/ios/{TrackPlayer.xcodeproj/xcuserdata/marco.xcuserdatad/xcschemes/xcschememanagement.plist → Example/SwiftAudio/SwiftAudio.entitlements} +6 -8
- package/ios/Example/SwiftAudio/SwiftAudioApp.swift +17 -0
- package/ios/Example/SwiftAudio.xcodeproj/project.pbxproj +412 -0
- package/ios/{TrackPlayer.xcodeproj → Example/SwiftAudio.xcodeproj}/project.xcworkspace/contents.xcworkspacedata +1 -1
- package/ios/RNTrackPlayer/Models/Capabilities.swift +39 -4
- package/ios/RNTrackPlayer/Models/MediaURL.swift +12 -6
- package/ios/RNTrackPlayer/Models/MetadataAdapter.swift +147 -0
- package/ios/RNTrackPlayer/Models/PitchAlgorithms.swift +13 -0
- package/ios/RNTrackPlayer/Models/SessionCategories.swift +106 -0
- package/ios/RNTrackPlayer/Models/State.swift +26 -0
- package/ios/RNTrackPlayer/Models/Track.swift +74 -54
- package/ios/RNTrackPlayer/RNTrackPlayer.swift +867 -406
- package/ios/RNTrackPlayer/Support/RNTrackPlayer-Bridging-Header.h +1 -0
- package/ios/RNTrackPlayer/TrackPlayer.h +14 -0
- package/ios/RNTrackPlayer/TrackPlayer.mm +249 -0
- package/ios/RNTrackPlayer/Utils/EventType.swift +45 -0
- package/ios/RNTrackPlayer/Utils/Metadata.swift +60 -0
- package/ios/RNTrackPlayer/Video/RNTrackPlayerVideoView.swift +83 -0
- package/ios/RNTrackPlayer/Video/RNTrackPlayerVideoViewManager.m +5 -0
- package/ios/RNTrackPlayer/Video/RNTrackPlayerVideoViewManager.swift +17 -0
- package/ios/SwiftAudioEx/Package.swift +20 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/AVPlayerWrapper/AVPlayerWrapper.swift +531 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/AVPlayerWrapper/AVPlayerWrapperDelegate.swift +27 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/AVPlayerWrapper/AVPlayerWrapperProtocol.swift +69 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/AVPlayerWrapper/AVPlayerWrapperState.swift +43 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/AudioItem.swift +158 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/AudioPlayer.swift +459 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/AudioPlayerError.swift +26 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/AudioSessionController/AudioSession.swift +33 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/AudioSessionController/AudioSessionController.swift +135 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/AudioTap.swift +96 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/Event.swift +155 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/NowPlayingInfoController/MediaItemProperty.swift +95 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/NowPlayingInfoController/NowPlayingInfoCenter.swift +17 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/NowPlayingInfoController/NowPlayingInfoController.swift +73 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/NowPlayingInfoController/NowPlayingInfoControllerProtocol.swift +26 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/NowPlayingInfoController/NowPlayingInfoKeyValue.swift +14 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/NowPlayingInfoController/NowPlayingInfoProperty.swift +234 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/Observer/AVPlayerItemNotificationObserver.swift +102 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/Observer/AVPlayerItemObserver.swift +136 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/Observer/AVPlayerObserver.swift +120 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/Observer/AVPlayerTimeObserver.swift +112 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/QueueManager.swift +356 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/QueuedAudioPlayer.swift +236 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/RemoteCommandController/RemoteCommand.swift +170 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/RemoteCommandController/RemoteCommandController.swift +206 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/RepeatMode.swift +15 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/TimeEventFrequency.swift +26 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/Utils/DispatchQueueType.swift +18 -0
- package/ios/SwiftAudioEx/Sources/SwiftAudioEx/WaveformAudioTap.swift +159 -0
- package/lib/specs/NativeTrackPlayer.d.ts +134 -0
- package/lib/specs/NativeTrackPlayer.js +4 -0
- package/lib/src/TrackPlayerModule.web.d.ts +2 -0
- package/lib/src/TrackPlayerModule.web.js +2 -0
- package/lib/src/VideoView.d.ts +16 -0
- package/lib/src/VideoView.js +25 -0
- package/lib/src/constants/AndroidAudioContentType.d.ts +35 -0
- package/lib/src/constants/AndroidAudioContentType.js +36 -0
- package/lib/src/constants/AndroidAutoContentStyle.d.ts +10 -0
- package/lib/src/constants/AndroidAutoContentStyle.js +11 -0
- package/lib/src/constants/AppKilledPlaybackBehavior.d.ts +17 -0
- package/lib/src/constants/AppKilledPlaybackBehavior.js +18 -0
- package/lib/src/constants/Capability.d.ts +17 -0
- package/lib/src/constants/Capability.js +19 -0
- package/lib/src/constants/Event.d.ts +172 -0
- package/lib/src/constants/Event.js +173 -0
- package/lib/src/constants/IOSCategory.d.ts +36 -0
- package/lib/src/constants/IOSCategory.js +37 -0
- package/lib/src/constants/IOSCategoryMode.d.ts +47 -0
- package/lib/src/constants/IOSCategoryMode.js +48 -0
- package/lib/src/constants/IOSCategoryOptions.d.ts +44 -0
- package/lib/src/constants/IOSCategoryOptions.js +45 -0
- package/lib/src/constants/MediaItemPlayable.d.ts +4 -0
- package/lib/src/constants/MediaItemPlayable.js +5 -0
- package/lib/src/constants/PitchAlgorithm.d.ts +14 -0
- package/lib/src/constants/PitchAlgorithm.js +16 -0
- package/lib/src/constants/RatingType.d.ts +8 -0
- package/lib/src/constants/RatingType.js +10 -0
- package/lib/src/constants/RepeatMode.d.ts +8 -0
- package/lib/src/constants/RepeatMode.js +10 -0
- package/lib/src/constants/State.d.ts +34 -0
- package/lib/src/constants/State.js +35 -0
- package/lib/src/constants/TrackType.d.ts +6 -0
- package/lib/src/constants/TrackType.js +7 -0
- package/lib/src/constants/index.d.ts +14 -0
- package/lib/src/constants/index.js +14 -0
- package/lib/src/hooks/index.d.ts +6 -0
- package/lib/src/hooks/index.js +6 -0
- package/lib/src/hooks/useActiveTrack.d.ts +2 -0
- package/lib/src/hooks/useActiveTrack.js +28 -0
- package/lib/src/hooks/useAppIsInBackground.d.ts +1 -0
- package/lib/src/hooks/useAppIsInBackground.js +16 -0
- package/lib/src/hooks/useIsPlaying.d.ts +35 -0
- package/lib/src/hooks/useIsPlaying.js +50 -0
- package/lib/src/hooks/usePlayWhenReady.d.ts +1 -0
- package/lib/src/hooks/usePlayWhenReady.js +27 -0
- package/lib/src/hooks/usePlaybackState.d.ts +10 -0
- package/lib/src/hooks/usePlaybackState.js +35 -0
- package/lib/src/hooks/useProgress.d.ts +7 -0
- package/lib/src/hooks/useProgress.js +55 -0
- package/lib/src/hooks/useTrackPlayerEvents.d.ts +8 -0
- package/lib/src/hooks/useTrackPlayerEvents.js +30 -0
- package/lib/src/index.d.ts +6 -0
- package/lib/src/index.js +6 -0
- package/lib/src/interfaces/AndroidAutoBrowseTree.d.ts +5 -0
- package/lib/src/interfaces/AndroidAutoBrowseTree.js +1 -0
- package/lib/src/interfaces/AndroidOptions.d.ts +41 -0
- package/lib/src/interfaces/AndroidOptions.js +1 -0
- package/lib/src/interfaces/CustomButtons.d.ts +5 -0
- package/lib/src/interfaces/CustomButtons.js +1 -0
- package/lib/src/interfaces/FeedbackOptions.d.ts +6 -0
- package/lib/src/interfaces/FeedbackOptions.js +1 -0
- package/lib/src/interfaces/MediaItem.d.ts +18 -0
- package/lib/src/interfaces/MediaItem.js +1 -0
- package/lib/src/interfaces/MetadataOptions.d.ts +3 -0
- package/lib/src/interfaces/MetadataOptions.js +1 -0
- package/lib/src/interfaces/NowPlayingMetadata.d.ts +4 -0
- package/lib/src/interfaces/NowPlayingMetadata.js +1 -0
- package/lib/src/interfaces/PlaybackState.d.ts +8 -0
- package/lib/src/interfaces/PlaybackState.js +1 -0
- package/lib/src/interfaces/PlayerOptions.d.ts +132 -0
- package/lib/src/interfaces/PlayerOptions.js +1 -0
- package/lib/src/interfaces/Progress.d.ts +15 -0
- package/lib/src/interfaces/Progress.js +1 -0
- package/lib/src/interfaces/ResourceObject.d.ts +1 -0
- package/lib/src/interfaces/ResourceObject.js +1 -0
- package/lib/src/interfaces/ServiceHandler.d.ts +1 -0
- package/lib/src/interfaces/ServiceHandler.js +1 -0
- package/lib/src/interfaces/Track.d.ts +21 -0
- package/lib/src/interfaces/Track.js +1 -0
- package/lib/src/interfaces/TrackMetadataBase.d.ts +28 -0
- package/lib/src/interfaces/TrackMetadataBase.js +1 -0
- package/lib/src/interfaces/UpdateOptions.d.ts +52 -0
- package/lib/src/interfaces/UpdateOptions.js +1 -0
- package/lib/src/interfaces/events/AudioMetadataReceivedEvent.d.ts +33 -0
- package/lib/src/interfaces/events/AudioMetadataReceivedEvent.js +1 -0
- package/lib/src/interfaces/events/ControllerConnectedEvent.d.ts +8 -0
- package/lib/src/interfaces/events/ControllerConnectedEvent.js +1 -0
- package/lib/src/interfaces/events/EventPayloadByEvent.d.ts +77 -0
- package/lib/src/interfaces/events/EventPayloadByEvent.js +1 -0
- package/lib/src/interfaces/events/FFTUpdateEvent.d.ts +7 -0
- package/lib/src/interfaces/events/FFTUpdateEvent.js +1 -0
- package/lib/src/interfaces/events/PlaybackActiveTrackChangedEvent.d.ts +24 -0
- package/lib/src/interfaces/events/PlaybackActiveTrackChangedEvent.js +1 -0
- package/lib/src/interfaces/events/PlaybackAnimatedVolumeChangedEvent.d.ts +4 -0
- package/lib/src/interfaces/events/PlaybackAnimatedVolumeChangedEvent.js +1 -0
- package/lib/src/interfaces/events/PlaybackErrorEvent.d.ts +6 -0
- package/lib/src/interfaces/events/PlaybackErrorEvent.js +1 -0
- package/lib/src/interfaces/events/PlaybackMetadataReceivedEvent.d.ts +16 -0
- package/lib/src/interfaces/events/PlaybackMetadataReceivedEvent.js +1 -0
- package/lib/src/interfaces/events/PlaybackPlayWhenReadyChangedEvent.d.ts +4 -0
- package/lib/src/interfaces/events/PlaybackPlayWhenReadyChangedEvent.js +1 -0
- package/lib/src/interfaces/events/PlaybackProgressUpdatedEvent.d.ts +4 -0
- package/lib/src/interfaces/events/PlaybackProgressUpdatedEvent.js +1 -0
- package/lib/src/interfaces/events/PlaybackQueueEndedEvent.d.ts +9 -0
- package/lib/src/interfaces/events/PlaybackQueueEndedEvent.js +1 -0
- package/lib/src/interfaces/events/PlaybackResumeEvent.d.ts +3 -0
- package/lib/src/interfaces/events/PlaybackResumeEvent.js +1 -0
- package/lib/src/interfaces/events/PlaybackTrackChangedEvent.d.ts +11 -0
- package/lib/src/interfaces/events/PlaybackTrackChangedEvent.js +1 -0
- package/lib/src/interfaces/events/PlayerErrorEvent.d.ts +6 -0
- package/lib/src/interfaces/events/PlayerErrorEvent.js +1 -0
- package/lib/src/interfaces/events/RemoteBrowseEvent.d.ts +4 -0
- package/lib/src/interfaces/events/RemoteBrowseEvent.js +1 -0
- package/lib/src/interfaces/events/RemoteCustomActionEvent.d.ts +7 -0
- package/lib/src/interfaces/events/RemoteCustomActionEvent.js +1 -0
- package/lib/src/interfaces/events/RemoteDuckEvent.d.ts +13 -0
- package/lib/src/interfaces/events/RemoteDuckEvent.js +1 -0
- package/lib/src/interfaces/events/RemoteJumpBackwardEvent.d.ts +7 -0
- package/lib/src/interfaces/events/RemoteJumpBackwardEvent.js +1 -0
- package/lib/src/interfaces/events/RemoteJumpForwardEvent.d.ts +7 -0
- package/lib/src/interfaces/events/RemoteJumpForwardEvent.js +1 -0
- package/lib/src/interfaces/events/RemotePlayIdEvent.d.ts +4 -0
- package/lib/src/interfaces/events/RemotePlayIdEvent.js +1 -0
- package/lib/src/interfaces/events/RemotePlaySearchEvent.d.ts +9 -0
- package/lib/src/interfaces/events/RemotePlaySearchEvent.js +1 -0
- package/lib/src/interfaces/events/RemoteSearchEvent.d.ts +3 -0
- package/lib/src/interfaces/events/RemoteSearchEvent.js +1 -0
- package/lib/src/interfaces/events/RemoteSeekEvent.d.ts +4 -0
- package/lib/src/interfaces/events/RemoteSeekEvent.js +1 -0
- package/lib/src/interfaces/events/RemoteSetRatingEvent.d.ts +4 -0
- package/lib/src/interfaces/events/RemoteSetRatingEvent.js +1 -0
- package/lib/src/interfaces/events/RemoteSkipEvent.d.ts +3 -0
- package/lib/src/interfaces/events/RemoteSkipEvent.js +1 -0
- package/lib/src/interfaces/events/index.d.ts +20 -0
- package/lib/src/interfaces/events/index.js +20 -0
- package/lib/src/interfaces/index.d.ts +15 -0
- package/lib/src/interfaces/index.js +15 -0
- package/lib/src/resolveAssetSource.d.ts +2 -0
- package/lib/src/resolveAssetSource.js +3 -0
- package/lib/src/resolveAssetSource.web.d.ts +2 -0
- package/lib/src/resolveAssetSource.web.js +8 -0
- package/lib/src/trackPlayer.d.ts +371 -0
- package/lib/src/trackPlayer.js +627 -0
- package/lib/web/TrackPlayer/Player.d.ts +40 -0
- package/lib/web/TrackPlayer/Player.js +188 -0
- package/lib/web/TrackPlayer/PlaylistPlayer.d.ts +31 -0
- package/lib/web/TrackPlayer/PlaylistPlayer.js +181 -0
- package/lib/web/TrackPlayer/RepeatMode.d.ts +5 -0
- package/lib/web/TrackPlayer/RepeatMode.js +6 -0
- package/lib/web/TrackPlayer/SetupNotCalledError.d.ts +3 -0
- package/lib/web/TrackPlayer/SetupNotCalledError.js +5 -0
- package/lib/web/TrackPlayer/index.d.ts +3 -0
- package/lib/web/TrackPlayer/index.js +3 -0
- package/lib/web/TrackPlayerModule.d.ts +63 -0
- package/lib/web/TrackPlayerModule.js +153 -0
- package/lib/web/index.d.ts +3 -0
- package/lib/web/index.js +3 -0
- package/package.json +85 -6
- package/react-native-track-player.podspec +13 -13
- package/specs/NativeTrackPlayer.ts +153 -0
- package/src/TrackPlayerModule.web.ts +2 -0
- package/src/VideoView.tsx +51 -0
- package/src/constants/AndroidAudioContentType.ts +35 -0
- package/src/constants/AndroidAutoContentStyle.ts +10 -0
- package/src/constants/AppKilledPlaybackBehavior.ts +19 -0
- package/src/constants/Capability.ts +19 -0
- package/src/constants/Event.ts +173 -0
- package/src/constants/IOSCategory.ts +36 -0
- package/src/constants/IOSCategoryMode.ts +47 -0
- package/src/constants/IOSCategoryOptions.ts +44 -0
- package/src/constants/MediaItemPlayable.ts +4 -0
- package/src/constants/PitchAlgorithm.ts +16 -0
- package/src/constants/RatingType.ts +10 -0
- package/src/constants/RepeatMode.ts +10 -0
- package/src/constants/State.ts +34 -0
- package/src/constants/TrackType.ts +6 -0
- package/src/constants/index.ts +14 -0
- package/src/hooks/index.ts +6 -0
- package/src/hooks/useActiveTrack.ts +36 -0
- package/src/hooks/useAppIsInBackground.ts +20 -0
- package/src/hooks/useIsPlaying.ts +56 -0
- package/src/hooks/usePlayWhenReady.ts +37 -0
- package/src/hooks/usePlaybackState.ts +45 -0
- package/src/hooks/useProgress.ts +64 -0
- package/src/hooks/useTrackPlayerEvents.ts +48 -0
- package/src/index.ts +8 -0
- package/src/interfaces/AndroidAutoBrowseTree.ts +6 -0
- package/src/interfaces/AndroidOptions.ts +48 -0
- package/src/interfaces/CustomButtons.ts +6 -0
- package/src/interfaces/FeedbackOptions.ts +7 -0
- package/src/interfaces/MediaItem.ts +19 -0
- package/src/interfaces/MetadataOptions.ts +4 -0
- package/src/interfaces/NowPlayingMetadata.ts +5 -0
- package/src/interfaces/PlaybackState.ts +11 -0
- package/src/interfaces/PlayerOptions.ts +138 -0
- package/src/interfaces/Progress.ts +15 -0
- package/src/interfaces/ResourceObject.ts +1 -0
- package/src/interfaces/ServiceHandler.ts +1 -0
- package/src/interfaces/Track.ts +23 -0
- package/src/interfaces/TrackMetadataBase.ts +29 -0
- package/src/interfaces/UpdateOptions.ts +59 -0
- package/src/interfaces/events/AudioMetadataReceivedEvent.ts +37 -0
- package/src/interfaces/events/ControllerConnectedEvent.ts +9 -0
- package/src/interfaces/events/EventPayloadByEvent.ts +80 -0
- package/src/interfaces/events/FFTUpdateEvent.ts +9 -0
- package/src/interfaces/events/PlaybackActiveTrackChangedEvent.ts +29 -0
- package/src/interfaces/events/PlaybackAnimatedVolumeChangedEvent.ts +4 -0
- package/src/interfaces/events/PlaybackErrorEvent.ts +6 -0
- package/src/interfaces/events/PlaybackMetadataReceivedEvent.ts +16 -0
- package/src/interfaces/events/PlaybackPlayWhenReadyChangedEvent.ts +4 -0
- package/src/interfaces/events/PlaybackProgressUpdatedEvent.ts +5 -0
- package/src/interfaces/events/PlaybackQueueEndedEvent.ts +9 -0
- package/src/interfaces/events/PlaybackResumeEvent.ts +5 -0
- package/src/interfaces/events/PlaybackTrackChangedEvent.ts +11 -0
- package/src/interfaces/events/PlayerErrorEvent.ts +6 -0
- package/src/interfaces/events/RemoteBrowseEvent.ts +4 -0
- package/src/interfaces/events/RemoteCustomActionEvent.ts +7 -0
- package/src/interfaces/events/RemoteDuckEvent.ts +13 -0
- package/src/interfaces/events/RemoteJumpBackwardEvent.ts +7 -0
- package/src/interfaces/events/RemoteJumpForwardEvent.ts +7 -0
- package/src/interfaces/events/RemotePlayIdEvent.ts +4 -0
- package/src/interfaces/events/RemotePlaySearchEvent.ts +21 -0
- package/src/interfaces/events/RemoteSearchEvent.ts +3 -0
- package/src/interfaces/events/RemoteSeekEvent.ts +4 -0
- package/src/interfaces/events/RemoteSetRatingEvent.ts +5 -0
- package/src/interfaces/events/RemoteSkipEvent.ts +3 -0
- package/src/interfaces/events/index.ts +20 -0
- package/src/interfaces/index.ts +15 -0
- package/src/resolveAssetSource.ts +3 -0
- package/src/resolveAssetSource.web.ts +10 -0
- package/src/trackPlayer.ts +806 -0
- package/web/TrackPlayer/Player.ts +201 -0
- package/web/TrackPlayer/PlaylistPlayer.ts +215 -0
- package/web/TrackPlayer/RepeatMode.ts +6 -0
- package/web/TrackPlayer/SetupNotCalledError.ts +5 -0
- package/web/TrackPlayer/index.ts +3 -0
- package/web/TrackPlayerModule.ts +181 -0
- package/web/index.ts +4 -0
- package/CHANGELOG.md +0 -75
- package/android/react-native-music-control.iml +0 -139
- package/android/react-native-track-player.iml +0 -151
- package/android/src/main/ic_home-playstore.png +0 -0
- package/android/src/main/ic_repeat-playstore.png +0 -0
- package/android/src/main/ic_repeat_50-playstore.png +0 -0
- package/android/src/main/ic_shuffle-playstore.png +0 -0
- package/android/src/main/ic_shuffle_50-playstore.png +0 -0
- package/android/src/main/ic_shuffle_sm-playstore.png +0 -0
- package/android/src/main/ic_stop-playstore.png +0 -0
- package/android/src/main/ic_test-playstore.png +0 -0
- package/android/src/main/java/com/guichaguri/trackplayer/HeadlessJsMediaService.java +0 -225
- package/android/src/main/java/com/guichaguri/trackplayer/TrackPlayer.kt +0 -25
- package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/event/NotificationEventHolder.kt +0 -20
- package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/models/AAMediaSessionCallback.kt +0 -10
- package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/models/AudioItem.kt +0 -66
- package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/models/NotificationConfig.kt +0 -43
- package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/models/NotificationMetadata.kt +0 -8
- package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/models/NotificationState.kt +0 -8
- package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/models/PlayerOptions.kt +0 -9
- package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/models/QueuedPlayerOptions.kt +0 -49
- package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/notification/NotificationManager.kt +0 -678
- package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/players/AudioPlayer.kt +0 -10
- package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/players/BaseAudioPlayer.kt +0 -864
- package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/players/components/MediaSourceExt.kt +0 -35
- package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/players/components/PlayerCache.kt +0 -26
- package/android/src/main/java/com/guichaguri/trackplayer/kotlinaudio/utils/Utils.kt +0 -12
- package/android/src/main/java/com/guichaguri/trackplayer/model/Track.kt +0 -120
- package/android/src/main/java/com/guichaguri/trackplayer/model/TrackAudioItem.kt +0 -19
- package/android/src/main/java/com/guichaguri/trackplayer/model/TrackType.kt +0 -11
- package/android/src/main/java/com/guichaguri/trackplayer/module/AutoConnectionDetector.kt +0 -151
- package/android/src/main/java/com/guichaguri/trackplayer/module/MusicModule.kt +0 -1177
- package/android/src/main/java/com/guichaguri/trackplayer/service/MusicBinder.kt +0 -31
- package/android/src/main/java/com/guichaguri/trackplayer/service/MusicManager.kt +0 -347
- package/android/src/main/java/com/guichaguri/trackplayer/service/MusicService.kt +0 -1254
- package/android/src/main/java/com/guichaguri/trackplayer/service/Utils.kt +0 -228
- package/android/src/main/java/com/guichaguri/trackplayer/service/metadata/ButtonEvents.kt +0 -141
- package/android/src/main/java/com/guichaguri/trackplayer/service/metadata/MetadataManager.kt +0 -396
- package/android/src/main/res/drawable-hdpi/ic_forward.png +0 -0
- package/android/src/main/res/drawable-hdpi/ic_home.png +0 -0
- package/android/src/main/res/drawable-hdpi/ic_next.png +0 -0
- package/android/src/main/res/drawable-hdpi/ic_pause.png +0 -0
- package/android/src/main/res/drawable-hdpi/ic_play.png +0 -0
- package/android/src/main/res/drawable-hdpi/ic_previous.png +0 -0
- package/android/src/main/res/drawable-hdpi/ic_rewind.png +0 -0
- package/android/src/main/res/drawable-hdpi/ic_stop.png +0 -0
- package/android/src/main/res/drawable-mdpi/ic_forward.png +0 -0
- package/android/src/main/res/drawable-mdpi/ic_home.png +0 -0
- package/android/src/main/res/drawable-mdpi/ic_next.png +0 -0
- package/android/src/main/res/drawable-mdpi/ic_pause.png +0 -0
- package/android/src/main/res/drawable-mdpi/ic_play.png +0 -0
- package/android/src/main/res/drawable-mdpi/ic_previous.png +0 -0
- package/android/src/main/res/drawable-mdpi/ic_rewind.png +0 -0
- package/android/src/main/res/drawable-mdpi/ic_stop.png +0 -0
- package/android/src/main/res/drawable-xhdpi/ic_forward.png +0 -0
- package/android/src/main/res/drawable-xhdpi/ic_home.png +0 -0
- package/android/src/main/res/drawable-xhdpi/ic_next.png +0 -0
- package/android/src/main/res/drawable-xhdpi/ic_pause.png +0 -0
- package/android/src/main/res/drawable-xhdpi/ic_play.png +0 -0
- package/android/src/main/res/drawable-xhdpi/ic_previous.png +0 -0
- package/android/src/main/res/drawable-xhdpi/ic_rewind.png +0 -0
- package/android/src/main/res/drawable-xhdpi/ic_stop.png +0 -0
- package/android/src/main/res/drawable-xxhdpi/ic_forward.png +0 -0
- package/android/src/main/res/drawable-xxhdpi/ic_home.png +0 -0
- package/android/src/main/res/drawable-xxhdpi/ic_next.png +0 -0
- package/android/src/main/res/drawable-xxhdpi/ic_pause.png +0 -0
- package/android/src/main/res/drawable-xxhdpi/ic_play.png +0 -0
- package/android/src/main/res/drawable-xxhdpi/ic_previous.png +0 -0
- package/android/src/main/res/drawable-xxhdpi/ic_rewind.png +0 -0
- package/android/src/main/res/drawable-xxhdpi/ic_stop.png +0 -0
- package/android/src/main/res/drawable-xxxhdpi/ic_forward.png +0 -0
- package/android/src/main/res/drawable-xxxhdpi/ic_home.png +0 -0
- package/android/src/main/res/drawable-xxxhdpi/ic_next.png +0 -0
- package/android/src/main/res/drawable-xxxhdpi/ic_pause.png +0 -0
- package/android/src/main/res/drawable-xxxhdpi/ic_play.png +0 -0
- package/android/src/main/res/drawable-xxxhdpi/ic_previous.png +0 -0
- package/android/src/main/res/drawable-xxxhdpi/ic_rewind.png +0 -0
- package/android/src/main/res/drawable-xxxhdpi/ic_stop.png +0 -0
- package/android/src/main/res/mipmap-hdpi/ic_arrow_down_circle_foreground.png +0 -0
- package/android/src/main/res/mipmap-hdpi/ic_clock_now_foreground.png +0 -0
- package/android/src/main/res/mipmap-hdpi/ic_close_foreground.png +0 -0
- package/android/src/main/res/mipmap-hdpi/ic_heart_foreground.png +0 -0
- package/android/src/main/res/mipmap-hdpi/ic_heart_outlined_foreground.png +0 -0
- package/android/src/main/res/mipmap-hdpi/ic_repeat_off_foreground.png +0 -0
- package/android/src/main/res/mipmap-hdpi/ic_repeat_on_foreground.png +0 -0
- package/android/src/main/res/mipmap-hdpi/ic_shuffle_off_foreground.png +0 -0
- package/android/src/main/res/mipmap-hdpi/ic_shuffle_on_foreground.png +0 -0
- package/android/src/main/res/mipmap-mdpi/ic_arrow_down_circle_foreground.png +0 -0
- package/android/src/main/res/mipmap-mdpi/ic_clock_now_foreground.png +0 -0
- package/android/src/main/res/mipmap-mdpi/ic_close_foreground.png +0 -0
- package/android/src/main/res/mipmap-mdpi/ic_heart_foreground.png +0 -0
- package/android/src/main/res/mipmap-mdpi/ic_heart_outlined_foreground.png +0 -0
- package/android/src/main/res/mipmap-mdpi/ic_repeat_off_foreground.png +0 -0
- package/android/src/main/res/mipmap-mdpi/ic_repeat_on_foreground.png +0 -0
- package/android/src/main/res/mipmap-mdpi/ic_shuffle_off_foreground.png +0 -0
- package/android/src/main/res/mipmap-mdpi/ic_shuffle_on_foreground.png +0 -0
- package/android/src/main/res/mipmap-xhdpi/ic_arrow_down_circle_foreground.png +0 -0
- package/android/src/main/res/mipmap-xhdpi/ic_clock_now_foreground.png +0 -0
- package/android/src/main/res/mipmap-xhdpi/ic_close_foreground.png +0 -0
- package/android/src/main/res/mipmap-xhdpi/ic_heart_foreground.png +0 -0
- package/android/src/main/res/mipmap-xhdpi/ic_heart_outlined_foreground.png +0 -0
- package/android/src/main/res/mipmap-xhdpi/ic_repeat_off_foreground.png +0 -0
- package/android/src/main/res/mipmap-xhdpi/ic_repeat_on_foreground.png +0 -0
- package/android/src/main/res/mipmap-xhdpi/ic_shuffle_off_foreground.png +0 -0
- package/android/src/main/res/mipmap-xhdpi/ic_shuffle_on_foreground.png +0 -0
- package/android/src/main/res/mipmap-xxhdpi/ic_arrow_down_circle_foreground.png +0 -0
- package/android/src/main/res/mipmap-xxhdpi/ic_clock_now_foreground.png +0 -0
- package/android/src/main/res/mipmap-xxhdpi/ic_close_foreground.png +0 -0
- package/android/src/main/res/mipmap-xxhdpi/ic_heart_foreground.png +0 -0
- package/android/src/main/res/mipmap-xxhdpi/ic_heart_outlined_foreground.png +0 -0
- package/android/src/main/res/mipmap-xxhdpi/ic_repeat_off_foreground.png +0 -0
- package/android/src/main/res/mipmap-xxhdpi/ic_repeat_on_foreground.png +0 -0
- package/android/src/main/res/mipmap-xxhdpi/ic_shuffle_off_foreground.png +0 -0
- package/android/src/main/res/mipmap-xxhdpi/ic_shuffle_on_foreground.png +0 -0
- package/android/src/main/res/mipmap-xxxhdpi/ic_arrow_down_circle_foreground.png +0 -0
- package/android/src/main/res/mipmap-xxxhdpi/ic_clock_now_foreground.png +0 -0
- package/android/src/main/res/mipmap-xxxhdpi/ic_close_foreground.png +0 -0
- package/android/src/main/res/mipmap-xxxhdpi/ic_heart_foreground.png +0 -0
- package/android/src/main/res/mipmap-xxxhdpi/ic_heart_outlined_foreground.png +0 -0
- package/android/src/main/res/mipmap-xxxhdpi/ic_repeat_off_foreground.png +0 -0
- package/android/src/main/res/mipmap-xxxhdpi/ic_repeat_on_foreground.png +0 -0
- package/android/src/main/res/mipmap-xxxhdpi/ic_shuffle_off_foreground.png +0 -0
- package/android/src/main/res/mipmap-xxxhdpi/ic_shuffle_on_foreground.png +0 -0
- package/android/src/main/res/raw/silent_5_seconds.mp3 +0 -0
- package/android/src/main/res/strings.xml +0 -6
- package/index.d.ts +0 -235
- package/index.js +0 -4
- package/ios/RNTrackPlayer/RNTrackPlayerBridge.h +0 -12
- package/ios/RNTrackPlayer/RNTrackPlayerBridge.m +0 -29
- package/ios/TrackPlayer.xcodeproj/project.pbxproj +0 -495
- package/ios/TrackPlayer.xcodeproj/project.xcworkspace/xcuserdata/marco.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/lib/ProgressComponent.js +0 -70
- package/lib/eventTypes.js +0 -28
- package/lib/hooks.js +0 -160
- package/lib/index.js +0 -178
- /package/ios/{TrackPlayer.xcodeproj → Example/SwiftAudio.xcodeproj}/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -0
package/ios/SwiftAudioEx/Sources/SwiftAudioEx/NowPlayingInfoController/NowPlayingInfoProperty.swift
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
//
|
|
2
|
+
// NowPlayingInfo.swift
|
|
3
|
+
// SwiftAudio
|
|
4
|
+
//
|
|
5
|
+
// Created by Jørgen Henrichsen on 15/03/2018.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import MediaPlayer
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
Enum representing MPNowPlayingInfoProperties.
|
|
14
|
+
Docs for each property is taken from [Apple docs](https://developer.apple.com/documentation/mediaplayer/mpnowplayinginfocenter/additional_metadata_properties).
|
|
15
|
+
*/
|
|
16
|
+
public enum NowPlayingInfoProperty: NowPlayingInfoKeyValue {
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
The identifier of the collection the now playing item belongs to.
|
|
20
|
+
The identifier can be an album, artist, playlist, etc.
|
|
21
|
+
*/
|
|
22
|
+
case collectionIdentifier(String?)
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
The available language option groups for the now playing item.
|
|
26
|
+
Value is an array of MPNowPlayingInfoLanguageOptionGroup items. Only one language option in a given group can be played at a time.
|
|
27
|
+
*/
|
|
28
|
+
case availableLanguageOptions([MPNowPlayingInfoLanguageOptionGroup]?)
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
The URL pointing to the now playing item's underlying asset.
|
|
32
|
+
This constant is used by the system UI when video thumbnails or audio waveform visualizations are applicable.
|
|
33
|
+
*/
|
|
34
|
+
case assetUrl(URL?)
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
The total number of chapters in the now-playing item.
|
|
38
|
+
Value is an NSNumber object configured as an NSUInteger.
|
|
39
|
+
*/
|
|
40
|
+
case chapterCount(UInt64?)
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
The number corresponding to the chapter currently being played.
|
|
44
|
+
Value is an NSNumber object configured as an NSUInteger. Chapter numbering uses zero-based indexing. If you want the first chapter in the now-playing item to be displayed as “Chapter 1,” for example, set the chapter number to 0.
|
|
45
|
+
*/
|
|
46
|
+
case chapterNumber(UInt64?)
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
The currently active language options for the now playing item.
|
|
50
|
+
Value is an array of MPNowPlayingInfoLanguageOption items.
|
|
51
|
+
*/
|
|
52
|
+
case currentLanguageOptions([MPNowPlayingInfoLanguageOption]?)
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
The default playback rate for the now playing item.
|
|
56
|
+
Value is an NSNumber object configured as a double. Set this property if your app is playing a media item at a playback rate other than 1.0 as its default rate.
|
|
57
|
+
*/
|
|
58
|
+
case defaultPlaybackRate(Double?)
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
The elapsed time of the now playing item, in seconds.
|
|
62
|
+
Value is an NSNumber object configured as a double. Elapsed time is automatically calculated, by the system, from the previously provided elapsed time and the playback rate. Do not update this property frequently—it is not necessary
|
|
63
|
+
*/
|
|
64
|
+
case elapsedPlaybackTime(Double?)
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
The opaque identifier that uniquely identifies the now playing item, even through app relaunches.
|
|
68
|
+
This is only used to reference the item to the now playing app and can be in any format.
|
|
69
|
+
*/
|
|
70
|
+
case externalContentIdentifier(Any?)
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
The opaque identifier that uniquely identifies the profile the now playing item is played from, even through app relaunches.
|
|
74
|
+
This is only used to reference the profile to the now playing app and can be in any format.
|
|
75
|
+
*/
|
|
76
|
+
case externalUserProfileIdentifier(Any?)
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
Denotes whether the now playing item is a live stream.
|
|
80
|
+
Value is an NSNumber object configured as a boolean. A value of 1.0 indicates the now playing item is a live stream.
|
|
81
|
+
*/
|
|
82
|
+
case isLiveStream(Bool?)
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
The media type of the now playing item.
|
|
86
|
+
Value is an NSNumber object configured as a MPNowPlayingInfoMediaType.
|
|
87
|
+
*/
|
|
88
|
+
case mediaType(MPNowPlayingInfoMediaType?)
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
The current progress of the now playing item.
|
|
92
|
+
Value is an NSNumber object configured as a float. A value of 0.0 indicates the item has not been watched while a value of 1.0 indicates the item has been fully watched. This is a high-level indicator. Use MPNowPlayingInfoPropertyElapsedPlaybackTime for fine-detailed information on how much of the item has been watched.
|
|
93
|
+
*/
|
|
94
|
+
case playbackProgress(Float?)
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
The total number of items in the app’s playback queue.
|
|
98
|
+
Value is an NSNumber object configured as an NSUInteger.
|
|
99
|
+
*/
|
|
100
|
+
case playbackQueueCount(UInt64?)
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
The index of the now-playing item in the app’s playback queue.
|
|
104
|
+
Value is an NSNumber object configured as an NSUInteger. The playback queue uses zero-based indexing. If you want the first item in the queue to be displayed as “item 1 of 10,” for example, set the item’s index to 0.
|
|
105
|
+
*/
|
|
106
|
+
case playbackQueueIndex(UInt64?)
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
The playback rate of the now-playing item, with a value of 1.0 indicating the normal playback rate.
|
|
110
|
+
Value is an NSNumber object configured as a double. The default value is 1.0. A playback rate value of 2.0 means twice the normal playback rate; a piece of media played at this rate would take half as long to play to completion. A value of 0.5 means half the normal playback rate; a piece of media played at this rate would take twice as long to play to completion.
|
|
111
|
+
*/
|
|
112
|
+
case playbackRate(Double?)
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
The service provider associated with the now-playing item.
|
|
116
|
+
Value is a unique NSString that identifies the service provider for the now-playing item. If the now-playing item belongs to a channel or subscription service, this key can be used to coordinate various types of now-playing content from the service provider.
|
|
117
|
+
*/
|
|
118
|
+
case serviceIdentifier(String?)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
public func getKey() -> String {
|
|
122
|
+
switch self {
|
|
123
|
+
|
|
124
|
+
case .collectionIdentifier(_):
|
|
125
|
+
return MPNowPlayingInfoCollectionIdentifier
|
|
126
|
+
|
|
127
|
+
case .availableLanguageOptions(_):
|
|
128
|
+
return MPNowPlayingInfoPropertyAvailableLanguageOptions
|
|
129
|
+
|
|
130
|
+
case .assetUrl(_):
|
|
131
|
+
return MPNowPlayingInfoPropertyAssetURL
|
|
132
|
+
case .chapterCount(_):
|
|
133
|
+
return MPNowPlayingInfoPropertyChapterCount
|
|
134
|
+
|
|
135
|
+
case .chapterNumber(_):
|
|
136
|
+
return MPNowPlayingInfoPropertyChapterNumber
|
|
137
|
+
|
|
138
|
+
case .currentLanguageOptions(_):
|
|
139
|
+
return MPNowPlayingInfoPropertyCurrentLanguageOptions
|
|
140
|
+
|
|
141
|
+
case .defaultPlaybackRate(_):
|
|
142
|
+
return MPNowPlayingInfoPropertyDefaultPlaybackRate
|
|
143
|
+
|
|
144
|
+
case .elapsedPlaybackTime(_):
|
|
145
|
+
return MPNowPlayingInfoPropertyElapsedPlaybackTime
|
|
146
|
+
|
|
147
|
+
case .externalContentIdentifier(_):
|
|
148
|
+
return MPNowPlayingInfoPropertyExternalContentIdentifier
|
|
149
|
+
|
|
150
|
+
case .externalUserProfileIdentifier(_):
|
|
151
|
+
return MPNowPlayingInfoPropertyExternalUserProfileIdentifier
|
|
152
|
+
|
|
153
|
+
case .isLiveStream(_):
|
|
154
|
+
return MPNowPlayingInfoPropertyIsLiveStream
|
|
155
|
+
|
|
156
|
+
case .mediaType(_):
|
|
157
|
+
return MPNowPlayingInfoPropertyMediaType
|
|
158
|
+
|
|
159
|
+
case .playbackProgress(_):
|
|
160
|
+
return MPNowPlayingInfoPropertyPlaybackProgress
|
|
161
|
+
|
|
162
|
+
case .playbackQueueCount(_):
|
|
163
|
+
return MPNowPlayingInfoPropertyPlaybackQueueCount
|
|
164
|
+
|
|
165
|
+
case .playbackQueueIndex(_):
|
|
166
|
+
return MPNowPlayingInfoPropertyPlaybackQueueIndex
|
|
167
|
+
|
|
168
|
+
case .playbackRate(_):
|
|
169
|
+
return MPNowPlayingInfoPropertyPlaybackRate
|
|
170
|
+
|
|
171
|
+
case .serviceIdentifier(_):
|
|
172
|
+
return MPNowPlayingInfoPropertyServiceIdentifier
|
|
173
|
+
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
public func getValue() -> Any? {
|
|
178
|
+
switch self {
|
|
179
|
+
|
|
180
|
+
case .collectionIdentifier(let identifier):
|
|
181
|
+
return identifier
|
|
182
|
+
|
|
183
|
+
case .availableLanguageOptions(let options):
|
|
184
|
+
return options
|
|
185
|
+
|
|
186
|
+
case .assetUrl(let url):
|
|
187
|
+
return url
|
|
188
|
+
|
|
189
|
+
case .chapterCount(let count):
|
|
190
|
+
return count != nil ? NSNumber(value: count!) : nil
|
|
191
|
+
|
|
192
|
+
case .chapterNumber(let number):
|
|
193
|
+
return number != nil ? NSNumber(value: number!) : nil
|
|
194
|
+
|
|
195
|
+
case .currentLanguageOptions(let options):
|
|
196
|
+
return options
|
|
197
|
+
|
|
198
|
+
case .defaultPlaybackRate(let rate):
|
|
199
|
+
return rate != nil ? NSNumber(floatLiteral: rate!) : nil
|
|
200
|
+
|
|
201
|
+
case .elapsedPlaybackTime(let time):
|
|
202
|
+
return time != nil ? NSNumber(floatLiteral: time!) : nil
|
|
203
|
+
|
|
204
|
+
case .externalContentIdentifier(let id):
|
|
205
|
+
return id
|
|
206
|
+
|
|
207
|
+
case .externalUserProfileIdentifier(let id):
|
|
208
|
+
return id
|
|
209
|
+
|
|
210
|
+
case .isLiveStream(let status):
|
|
211
|
+
return status
|
|
212
|
+
|
|
213
|
+
case .mediaType(let type):
|
|
214
|
+
return type != nil ? NSNumber(value: type!.rawValue) : nil
|
|
215
|
+
|
|
216
|
+
case .playbackProgress(let progress):
|
|
217
|
+
return progress != nil ? NSNumber(value: progress!) : nil
|
|
218
|
+
|
|
219
|
+
case .playbackQueueCount(let count):
|
|
220
|
+
return count != nil ? NSNumber(value: count!) : nil
|
|
221
|
+
|
|
222
|
+
case .playbackQueueIndex(let index):
|
|
223
|
+
return index != nil ? NSNumber(value: index!) : nil
|
|
224
|
+
|
|
225
|
+
case .playbackRate(let rate):
|
|
226
|
+
return rate != nil ? NSNumber(floatLiteral: rate!) : nil
|
|
227
|
+
|
|
228
|
+
case .serviceIdentifier(let id):
|
|
229
|
+
return id != nil ? NSString(string: id!) : nil
|
|
230
|
+
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
//
|
|
2
|
+
// AVPlayerItemNotificationObserver.swift
|
|
3
|
+
// SwiftAudio
|
|
4
|
+
//
|
|
5
|
+
// Created by Jørgen Henrichsen on 12/03/2018.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import AVFoundation
|
|
10
|
+
|
|
11
|
+
protocol AVPlayerItemNotificationObserverDelegate: AnyObject {
|
|
12
|
+
func itemDidPlayToEndTime()
|
|
13
|
+
func itemFailedToPlayToEndTime()
|
|
14
|
+
func itemPlaybackStalled()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
Observes notifications posted by an AVPlayerItem.
|
|
19
|
+
|
|
20
|
+
Currently only listening for the AVPlayerItemDidPlayToEndTime notification.
|
|
21
|
+
*/
|
|
22
|
+
class AVPlayerItemNotificationObserver {
|
|
23
|
+
|
|
24
|
+
private let notificationCenter: NotificationCenter = NotificationCenter.default
|
|
25
|
+
|
|
26
|
+
private(set) weak var observingItem: AVPlayerItem?
|
|
27
|
+
weak var delegate: AVPlayerItemNotificationObserverDelegate?
|
|
28
|
+
|
|
29
|
+
private(set) var isObserving: Bool = false
|
|
30
|
+
|
|
31
|
+
deinit {
|
|
32
|
+
stopObservingCurrentItem()
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
Will start observing notifications from an item.
|
|
37
|
+
|
|
38
|
+
- parameter item: The item to observe.
|
|
39
|
+
- important: Cannot observe more than one item at a time.
|
|
40
|
+
*/
|
|
41
|
+
func startObserving(item: AVPlayerItem) {
|
|
42
|
+
stopObservingCurrentItem()
|
|
43
|
+
observingItem = item
|
|
44
|
+
isObserving = true
|
|
45
|
+
notificationCenter.addObserver(
|
|
46
|
+
self,
|
|
47
|
+
selector: #selector(itemDidPlayToEndTime),
|
|
48
|
+
name: NSNotification.Name.AVPlayerItemDidPlayToEndTime,
|
|
49
|
+
object: item
|
|
50
|
+
)
|
|
51
|
+
notificationCenter.addObserver(
|
|
52
|
+
self,
|
|
53
|
+
selector: #selector(itemFailedToPlayToEndTime),
|
|
54
|
+
name: NSNotification.Name.AVPlayerItemFailedToPlayToEndTime,
|
|
55
|
+
object: item
|
|
56
|
+
)
|
|
57
|
+
notificationCenter.addObserver(
|
|
58
|
+
self,
|
|
59
|
+
selector: #selector(itemPlaybackStalled),
|
|
60
|
+
name: NSNotification.Name.AVPlayerItemPlaybackStalled,
|
|
61
|
+
object: item
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
Stop receiving notifications for the current item.
|
|
67
|
+
*/
|
|
68
|
+
func stopObservingCurrentItem() {
|
|
69
|
+
guard let observingItem = observingItem, isObserving else {
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
notificationCenter.removeObserver(
|
|
73
|
+
self,
|
|
74
|
+
name: NSNotification.Name.AVPlayerItemDidPlayToEndTime,
|
|
75
|
+
object: observingItem
|
|
76
|
+
)
|
|
77
|
+
notificationCenter.removeObserver(
|
|
78
|
+
self,
|
|
79
|
+
name: NSNotification.Name.AVPlayerItemFailedToPlayToEndTime,
|
|
80
|
+
object: observingItem
|
|
81
|
+
)
|
|
82
|
+
notificationCenter.removeObserver(
|
|
83
|
+
self,
|
|
84
|
+
name: NSNotification.Name.AVPlayerItemPlaybackStalled,
|
|
85
|
+
object: observingItem
|
|
86
|
+
)
|
|
87
|
+
self.observingItem = nil
|
|
88
|
+
isObserving = false
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
@objc private func itemDidPlayToEndTime() {
|
|
92
|
+
delegate?.itemDidPlayToEndTime()
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
@objc private func itemFailedToPlayToEndTime() {
|
|
96
|
+
delegate?.itemFailedToPlayToEndTime()
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
@objc private func itemPlaybackStalled() {
|
|
100
|
+
delegate?.itemPlaybackStalled()
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
//
|
|
2
|
+
// AVPlayerItemObserver.swift
|
|
3
|
+
// SwiftAudio
|
|
4
|
+
//
|
|
5
|
+
// Created by Jørgen Henrichsen on 28/07/2018.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import AVFoundation
|
|
10
|
+
|
|
11
|
+
protocol AVPlayerItemObserverDelegate: AnyObject {
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
Called when the duration of the observed item is updated.
|
|
15
|
+
*/
|
|
16
|
+
func item(didUpdateDuration duration: Double)
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
Called when the playback of the observed item is or is no longer likely to keep up.
|
|
20
|
+
*/
|
|
21
|
+
func item(didUpdatePlaybackLikelyToKeepUp playbackLikelyToKeepUp: Bool)
|
|
22
|
+
/**
|
|
23
|
+
Called when the observed item receives metadata
|
|
24
|
+
*/
|
|
25
|
+
func item(didReceiveTimedMetadata metadata: [AVTimedMetadataGroup])
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
Observing an AVPlayers status changes.
|
|
31
|
+
*/
|
|
32
|
+
class AVPlayerItemObserver: NSObject {
|
|
33
|
+
|
|
34
|
+
private static var context = 0
|
|
35
|
+
private var currentMetadataOutput: AVPlayerItemMetadataOutput?
|
|
36
|
+
|
|
37
|
+
private struct AVPlayerItemKeyPath {
|
|
38
|
+
static let duration = #keyPath(AVPlayerItem.duration)
|
|
39
|
+
static let loadedTimeRanges = #keyPath(AVPlayerItem.loadedTimeRanges)
|
|
40
|
+
static let playbackLikelyToKeepUp = #keyPath(AVPlayerItem.isPlaybackLikelyToKeepUp)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private(set) var isObserving: Bool = false
|
|
44
|
+
|
|
45
|
+
private(set) weak var observingItem: AVPlayerItem?
|
|
46
|
+
weak var delegate: AVPlayerItemObserverDelegate?
|
|
47
|
+
|
|
48
|
+
override init() {
|
|
49
|
+
super.init()
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
deinit {
|
|
53
|
+
stopObservingCurrentItem()
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
Start observing an item. Will remove self as observer from old item, if any.
|
|
58
|
+
|
|
59
|
+
- parameter item: The player item to observe.
|
|
60
|
+
*/
|
|
61
|
+
func startObserving(item: AVPlayerItem) {
|
|
62
|
+
stopObservingCurrentItem()
|
|
63
|
+
|
|
64
|
+
self.isObserving = true
|
|
65
|
+
self.observingItem = item
|
|
66
|
+
item.addObserver(self, forKeyPath: AVPlayerItemKeyPath.duration, options: [.new], context: &AVPlayerItemObserver.context)
|
|
67
|
+
item.addObserver(self, forKeyPath: AVPlayerItemKeyPath.loadedTimeRanges, options: [.new], context: &AVPlayerItemObserver.context)
|
|
68
|
+
item.addObserver(self, forKeyPath: AVPlayerItemKeyPath.playbackLikelyToKeepUp, options: [.new], context: &AVPlayerItemObserver.context)
|
|
69
|
+
|
|
70
|
+
// Create and add a new metadata output to the item.
|
|
71
|
+
let metadataOutput = AVPlayerItemMetadataOutput()
|
|
72
|
+
metadataOutput.setDelegate(self, queue: .main)
|
|
73
|
+
item.add(metadataOutput)
|
|
74
|
+
self.currentMetadataOutput = metadataOutput
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
func stopObservingCurrentItem() {
|
|
78
|
+
guard let observingItem = observingItem, isObserving else {
|
|
79
|
+
return
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
observingItem.removeObserver(self, forKeyPath: AVPlayerItemKeyPath.duration, context: &AVPlayerItemObserver.context)
|
|
83
|
+
observingItem.removeObserver(self, forKeyPath: AVPlayerItemKeyPath.loadedTimeRanges, context: &AVPlayerItemObserver.context)
|
|
84
|
+
observingItem.removeObserver(self, forKeyPath: AVPlayerItemKeyPath.playbackLikelyToKeepUp, context: &AVPlayerItemObserver.context)
|
|
85
|
+
|
|
86
|
+
// Remove all metadata outputs from the item.
|
|
87
|
+
observingItem.removeAllMetadataOutputs()
|
|
88
|
+
|
|
89
|
+
isObserving = false
|
|
90
|
+
self.observingItem = nil
|
|
91
|
+
self.currentMetadataOutput = nil
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
|
|
95
|
+
guard context == &AVPlayerItemObserver.context, let observedKeyPath = keyPath else {
|
|
96
|
+
super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context)
|
|
97
|
+
return
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
switch observedKeyPath {
|
|
101
|
+
case AVPlayerItemKeyPath.duration:
|
|
102
|
+
if let duration = change?[.newKey] as? CMTime {
|
|
103
|
+
delegate?.item(didUpdateDuration: duration.seconds)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
case AVPlayerItemKeyPath.loadedTimeRanges:
|
|
107
|
+
if let ranges = change?[.newKey] as? [NSValue], let duration = ranges.first?.timeRangeValue.duration {
|
|
108
|
+
delegate?.item(didUpdateDuration: duration.seconds)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
case AVPlayerItemKeyPath.playbackLikelyToKeepUp:
|
|
112
|
+
if let playbackLikelyToKeepUp = change?[.newKey] as? Bool {
|
|
113
|
+
delegate?.item(didUpdatePlaybackLikelyToKeepUp: playbackLikelyToKeepUp)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
default: break
|
|
117
|
+
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
extension AVPlayerItemObserver: AVPlayerItemMetadataOutputPushDelegate {
|
|
123
|
+
func metadataOutput(_ output: AVPlayerItemMetadataOutput, didOutputTimedMetadataGroups groups: [AVTimedMetadataGroup], from track: AVPlayerItemTrack?) {
|
|
124
|
+
if output == currentMetadataOutput {
|
|
125
|
+
delegate?.item(didReceiveTimedMetadata: groups)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
extension AVPlayerItem {
|
|
131
|
+
func removeAllMetadataOutputs() {
|
|
132
|
+
for output in self.outputs.filter({ $0 is AVPlayerItemMetadataOutput }) {
|
|
133
|
+
self.remove(output)
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
//
|
|
2
|
+
// AudioPlayerObserver.swift
|
|
3
|
+
// SwiftAudio
|
|
4
|
+
//
|
|
5
|
+
// Created by Jørgen Henrichsen on 09/03/2018.
|
|
6
|
+
// Copyright © 2018 Jørgen Henrichsen. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
import Foundation
|
|
10
|
+
import AVFoundation
|
|
11
|
+
|
|
12
|
+
protocol AVPlayerObserverDelegate: AnyObject {
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
Called when the AVPlayer.status changes.
|
|
16
|
+
*/
|
|
17
|
+
func player(statusDidChange status: AVPlayer.Status)
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
Called when the AVPlayer.timeControlStatus changes.
|
|
21
|
+
*/
|
|
22
|
+
func player(didChangeTimeControlStatus status: AVPlayer.TimeControlStatus)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
Observing an AVPlayers status changes.
|
|
27
|
+
*/
|
|
28
|
+
class AVPlayerObserver: NSObject {
|
|
29
|
+
|
|
30
|
+
private static var context = 0
|
|
31
|
+
private let main: DispatchQueue = .main
|
|
32
|
+
|
|
33
|
+
private struct AVPlayerKeyPath {
|
|
34
|
+
static let status = #keyPath(AVPlayer.status)
|
|
35
|
+
static let timeControlStatus = #keyPath(AVPlayer.timeControlStatus)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private let statusChangeOptions: NSKeyValueObservingOptions = [.new, .initial]
|
|
39
|
+
private let timeControlStatusChangeOptions: NSKeyValueObservingOptions = [.new]
|
|
40
|
+
private(set) var isObserving: Bool = false
|
|
41
|
+
|
|
42
|
+
weak var delegate: AVPlayerObserverDelegate?
|
|
43
|
+
weak var player: AVPlayer? {
|
|
44
|
+
willSet {
|
|
45
|
+
stopObserving()
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
deinit {
|
|
50
|
+
stopObserving()
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
Start receiving events from this observer.
|
|
55
|
+
*/
|
|
56
|
+
func startObserving() {
|
|
57
|
+
if (isObserving) { return };
|
|
58
|
+
guard let player = player else {
|
|
59
|
+
return
|
|
60
|
+
}
|
|
61
|
+
isObserving = true
|
|
62
|
+
player.addObserver(
|
|
63
|
+
self,
|
|
64
|
+
forKeyPath: AVPlayerKeyPath.status,
|
|
65
|
+
options: statusChangeOptions,
|
|
66
|
+
context: &AVPlayerObserver.context
|
|
67
|
+
)
|
|
68
|
+
player.addObserver(
|
|
69
|
+
self,
|
|
70
|
+
forKeyPath: AVPlayerKeyPath.timeControlStatus,
|
|
71
|
+
options: timeControlStatusChangeOptions,
|
|
72
|
+
context: &AVPlayerObserver.context
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
func stopObserving() {
|
|
77
|
+
guard let player = player, isObserving else {
|
|
78
|
+
return
|
|
79
|
+
}
|
|
80
|
+
player.removeObserver(self, forKeyPath: AVPlayerKeyPath.status, context: &AVPlayerObserver.context)
|
|
81
|
+
player.removeObserver(self, forKeyPath: AVPlayerKeyPath.timeControlStatus, context: &AVPlayerObserver.context)
|
|
82
|
+
isObserving = false
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey: Any]?, context: UnsafeMutableRawPointer?) {
|
|
86
|
+
guard context == &AVPlayerObserver.context, let observedKeyPath = keyPath else {
|
|
87
|
+
super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context)
|
|
88
|
+
return
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
switch observedKeyPath {
|
|
92
|
+
case AVPlayerKeyPath.status:
|
|
93
|
+
handleStatusChange(change)
|
|
94
|
+
|
|
95
|
+
case AVPlayerKeyPath.timeControlStatus:
|
|
96
|
+
handleTimeControlStatusChange(change)
|
|
97
|
+
|
|
98
|
+
default:
|
|
99
|
+
break
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private func handleStatusChange(_ change: [NSKeyValueChangeKey: Any]?) {
|
|
104
|
+
let status: AVPlayer.Status
|
|
105
|
+
if let statusNumber = change?[.newKey] as? NSNumber {
|
|
106
|
+
status = AVPlayer.Status(rawValue: statusNumber.intValue)!
|
|
107
|
+
} else {
|
|
108
|
+
status = .unknown
|
|
109
|
+
}
|
|
110
|
+
delegate?.player(statusDidChange: status)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
private func handleTimeControlStatusChange(_ change: [NSKeyValueChangeKey: Any]?) {
|
|
114
|
+
let status: AVPlayer.TimeControlStatus
|
|
115
|
+
if let statusNumber = change?[.newKey] as? NSNumber {
|
|
116
|
+
status = AVPlayer.TimeControlStatus(rawValue: statusNumber.intValue)!
|
|
117
|
+
delegate?.player(didChangeTimeControlStatus: status)
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
//
|
|
2
|
+
// AudioPlayerTimeEventObserver.swift
|
|
3
|
+
// SwiftAudio
|
|
4
|
+
//
|
|
5
|
+
// Created by Jørgen Henrichsen on 09/03/2018.
|
|
6
|
+
// Copyright © 2018 Jørgen Henrichsen. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
import Foundation
|
|
10
|
+
import AVFoundation
|
|
11
|
+
|
|
12
|
+
protocol AVPlayerTimeObserverDelegate: AnyObject {
|
|
13
|
+
func audioDidStart()
|
|
14
|
+
func timeEvent(time: CMTime)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
Class for observing time-based events from the AVPlayer
|
|
19
|
+
*/
|
|
20
|
+
class AVPlayerTimeObserver {
|
|
21
|
+
|
|
22
|
+
/// The time to use as start boundary time. Cannot be zero.
|
|
23
|
+
private static let startBoundaryTime: CMTime = CMTime(value: 1, timescale: 1000)
|
|
24
|
+
|
|
25
|
+
var boundaryTimeStartObserverToken: Any?
|
|
26
|
+
var periodicTimeObserverToken: Any?
|
|
27
|
+
|
|
28
|
+
weak var player: AVPlayer? {
|
|
29
|
+
willSet {
|
|
30
|
+
unregisterForBoundaryTimeEvents()
|
|
31
|
+
unregisterForPeriodicEvents()
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/// The frequence to receive periodic time events.
|
|
36
|
+
/// Setting this to a new value will trigger a re-registering to the periodic events of the player.
|
|
37
|
+
var periodicObserverTimeInterval: CMTime {
|
|
38
|
+
didSet {
|
|
39
|
+
if oldValue != periodicObserverTimeInterval {
|
|
40
|
+
registerForPeriodicTimeEvents()
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
weak var delegate: AVPlayerTimeObserverDelegate?
|
|
46
|
+
|
|
47
|
+
init(periodicObserverTimeInterval: CMTime) {
|
|
48
|
+
self.periodicObserverTimeInterval = periodicObserverTimeInterval
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
deinit {
|
|
52
|
+
unregisterForPeriodicEvents()
|
|
53
|
+
unregisterForBoundaryTimeEvents()
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
Will register for the AVPlayer BoundaryTimeEvents, to trigger start and complete events.
|
|
58
|
+
*/
|
|
59
|
+
func registerForBoundaryTimeEvents() {
|
|
60
|
+
guard let player = player else {
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
unregisterForBoundaryTimeEvents()
|
|
64
|
+
boundaryTimeStartObserverToken = player.addBoundaryTimeObserver(
|
|
65
|
+
forTimes: [AVPlayerTimeObserver.startBoundaryTime].map({
|
|
66
|
+
NSValue(time: $0)
|
|
67
|
+
}),
|
|
68
|
+
queue: nil,
|
|
69
|
+
using: { [weak self] in
|
|
70
|
+
self?.delegate?.audioDidStart()
|
|
71
|
+
}
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
Unregister from the boundary events of the player.
|
|
77
|
+
*/
|
|
78
|
+
func unregisterForBoundaryTimeEvents() {
|
|
79
|
+
guard
|
|
80
|
+
let player = player,
|
|
81
|
+
let boundaryTimeStartObserverToken = boundaryTimeStartObserverToken
|
|
82
|
+
else { return }
|
|
83
|
+
player.removeTimeObserver(boundaryTimeStartObserverToken)
|
|
84
|
+
self.boundaryTimeStartObserverToken = nil
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
Start observing periodic time events.
|
|
89
|
+
Will trigger unregisterForPeriodicEvents() first to avoid multiple subscriptions.
|
|
90
|
+
*/
|
|
91
|
+
func registerForPeriodicTimeEvents() {
|
|
92
|
+
guard let player = player else {
|
|
93
|
+
return
|
|
94
|
+
}
|
|
95
|
+
unregisterForPeriodicEvents()
|
|
96
|
+
periodicTimeObserverToken = player.addPeriodicTimeObserver(forInterval: periodicObserverTimeInterval, queue: nil, using: { (time) in
|
|
97
|
+
self.delegate?.timeEvent(time: time)
|
|
98
|
+
})
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
Unregister for periodic events.
|
|
103
|
+
*/
|
|
104
|
+
func unregisterForPeriodicEvents() {
|
|
105
|
+
guard let player = player, let periodicTimeObserverToken = periodicTimeObserverToken else {
|
|
106
|
+
return
|
|
107
|
+
}
|
|
108
|
+
player.removeTimeObserver(periodicTimeObserverToken)
|
|
109
|
+
self.periodicTimeObserverToken = nil
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
}
|