Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ios): emit state passed to handleAudioPlayerStateChange #1928

Merged
merged 1 commit into from
Feb 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions ios/RNTrackPlayer/RNTrackPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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:)
Expand Down Expand Up @@ -768,9 +767,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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious and want to learn more about the codebase; shouldn't the state be passed to the getPlaybackStateErrorKeyValues as well, if changing this? Now The state === AudioPlayerState.failed check will not be the same state as the error-values function are checking on in line 741?

}
return body
Expand All @@ -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]) {
Expand Down