Skip to content

Commit

Permalink
fix(ios): emit state passed to handleAudioPlayerStateChange (#1928)
Browse files Browse the repository at this point in the history
  • Loading branch information
puckey authored Feb 21, 2023
1 parent e125045 commit a65fdcd
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions ios/RNTrackPlayer/RNTrackPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -716,8 +716,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:)
Expand Down Expand Up @@ -781,9 +780,9 @@ public class RNTrackPlayer: RCTEventEmitter, AudioSessionControllerDelegate {
}
}

private func getPlaybackStateBodyKeyValues() -> Dictionary<String, Any> {
var body: Dictionary<String, Any> = ["state": State.fromPlayerState(state: player.playerState).rawValue]
if (player.playerState == AudioPlayerState.failed) {
private func getPlaybackStateBodyKeyValues(state: AudioPlayerState) -> Dictionary<String, Any> {
var body: Dictionary<String, Any> = ["state": State.fromPlayerState(state: state).rawValue]
if (state == AudioPlayerState.failed) {
body["error"] = getPlaybackStateErrorKeyValues()
}
return body
Expand All @@ -792,7 +791,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]) {
Expand Down

0 comments on commit a65fdcd

Please sign in to comment.