From b21470cf5bb582b3f8ee537dbc72522c0e4ae47f Mon Sep 17 00:00:00 2001 From: puckey Date: Wed, 15 Feb 2023 16:08:37 +0100 Subject: [PATCH] fix(ios): emit state passed to handleAudioPlayerStateChange --- ios/RNTrackPlayer/RNTrackPlayer.swift | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/ios/RNTrackPlayer/RNTrackPlayer.swift b/ios/RNTrackPlayer/RNTrackPlayer.swift index 1eb5b67da..cddf1c723 100644 --- a/ios/RNTrackPlayer/RNTrackPlayer.swift +++ b/ios/RNTrackPlayer/RNTrackPlayer.swift @@ -703,8 +703,7 @@ public class RNTrackPlayer: RCTEventEmitter, AudioSessionControllerDelegate { @objc(getPlaybackState:rejecter:) public func getPlaybackState(resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) { if (rejectWhenNotInitialized(reject: reject)) { return } - - resolve(getPlaybackStateBodyKeyValues()) + resolve(getPlaybackStateBodyKeyValues(state: player.playerState)) } @objc(updateMetadataForTrack:metadata:resolver:rejecter:) @@ -768,9 +767,9 @@ public class RNTrackPlayer: RCTEventEmitter, AudioSessionControllerDelegate { } } - private func getPlaybackStateBodyKeyValues() -> Dictionary { - var body: Dictionary = ["state": State.fromPlayerState(state: player.playerState).rawValue] - if (player.playerState == AudioPlayerState.failed) { + private func getPlaybackStateBodyKeyValues(state: AudioPlayerState) -> Dictionary { + var body: Dictionary = ["state": State.fromPlayerState(state: state).rawValue] + if (state == AudioPlayerState.failed) { body["error"] = getPlaybackStateErrorKeyValues() } return body @@ -779,7 +778,7 @@ public class RNTrackPlayer: RCTEventEmitter, AudioSessionControllerDelegate { // MARK: - QueuedAudioPlayer Event Handlers func handleAudioPlayerStateChange(state: AVPlayerWrapperState) { - emit(event: EventType.PlaybackState, body: getPlaybackStateBodyKeyValues()) + emit(event: EventType.PlaybackState, body: getPlaybackStateBodyKeyValues(state: state)) } func handleAudioPlayerMetadataReceived(metadata: [AVTimedMetadataGroup]) {