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

ref(ios, events): improve disabling of playback-progress-updated #1706

Conversation

puckey
Copy link
Collaborator

@puckey puckey commented Sep 7, 2022

  • When 0 is passed to options["progressUpdateEventInterval”] in order to disable ‘playback-progress-updated’ event, set timeEventFrequency back to the default of every second.
  • rename (private) shouldEmitUpdateEventInterval to shouldEmitProgressEvent

- When 0 is passed to `options["progressUpdateEventInterval”]` in order to disable ‘playback-progress-updated’ event, set `timeEventFrequency` back to the default of every second.
- rename shouldEmitUpdateEventInterval to shouldEmitProgressEvent
@puckey puckey requested a review from dcvz as a code owner September 7, 2022 10:23
@jspizziri
Copy link
Collaborator

@puckey was this already the default behavior on the Kotlin side?

@jspizziri jspizziri changed the title chore(ios): improve disabling of playback-progress-updated ref(ios, events): improve disabling of playback-progress-updated Sep 8, 2022
@puckey
Copy link
Collaborator Author

puckey commented Sep 8, 2022

@puckey was this already the default behavior on the Kotlin side?

Good point – I haven't checked that yet. Let's keep this open until I have done so.

@puckey
Copy link
Collaborator Author

puckey commented Sep 14, 2022

@jspizziri I am unable to find the same issue on the kotlin side that ios has where you are unable to 'cancel' this interval  (see your comments here:

// because you cannot prevent the `event.secondElapse` from firing
// do not emit an event if `progressUpdateEventInterval` is nil
// additionally, there are certain instances in which this event is emitted
// _after_ a manipulation to the queu causing no currentItem to exist (see reset)
// in which case we shouldn't emit anything or we'll get an exception.
)

Here is the kotlin side which looks like it cancels the job and then doesn't recreate it when set to 0:

// setup progress update events if configured
progressUpdateJob?.cancel()
val updateInterval = Utils.getIntOrNull(options, PROGRESS_UPDATE_EVENT_INTERVAL_KEY)
if (updateInterval != null && updateInterval > 0) {
progressUpdateJob = scope.launch {
progressUpdateEventFlow(updateInterval.toLong()).collect { emit(MusicEvents.PLAYBACK_PROGRESS_UPDATED, it) }
}
}

shouldEmitProgressEvent = interval > 0
self.player.timeEventFrequency = shouldEmitProgressEvent
? .custom(time: CMTime(seconds: interval, preferredTimescale: 1))
: .everySecond
Copy link
Collaborator

Choose a reason for hiding this comment

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

The big difference I see here is that we're setting the interval to 1s when we cancel, which we weren't doing before. Are we sure this is desired?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the reason I am doing this is that the user might have set the interval to something very small temporarily, expecting that setting it back to 0 would return stuff to normal.. (I was going off the comment that says it is impossible to turn it off..)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@jspizziri
Copy link
Collaborator

Left a question, but lgtm apart from that.

Copy link
Collaborator

@jspizziri jspizziri left a comment

Choose a reason for hiding this comment

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

LGTM!

@jspizziri jspizziri merged commit 57de8b5 into doublesymmetry:main Sep 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants