-
Notifications
You must be signed in to change notification settings - Fork 853
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(darwin): Start observing AVPlayerItem.status
before being assigned to AVPlayer
#1549
Conversation
onPreparedSubscription.cancel(); | ||
try { | ||
await fun(); | ||
await preparedCompleter.future.timeout(const Duration(seconds: 30)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is not the right way here: we should avoid catching any error and instead try to not emit the prepared more than once or reinitialize the onPreparedCompleter.
Hi @blaugold thank you very much for contributing! We love that :) |
@blaugold little reminder, if you still working on this :) |
@Gustl22 Thanks for reviewing this PR and the ping. I'm still planning on addressing the comments, just haven't had the time yet :) |
# Conflicts: # packages/audioplayers_darwin/darwin/Classes/SwiftAudioplayersDarwinPlugin.swift # packages/audioplayers_darwin/darwin/Classes/WrappedMediaPlayer.swift
…audioplayers into fix/player-item-status
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added another Pull request to better distinguish the refactor from the actual logical changes, for a better review. Hope that is ok for you.
setUpPlayerItemStatusObservation(playerItem, completer, completerError) | ||
let player = updatePlayer(playerItem) ?? createPlayer(playerItem) | ||
setUpPositionObserver(player) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting up position observer for both creating and updating the player means that previously the position was not updated, when setting a new url? Is that right? So this is a fix then maybe? Or if not, why did it work in the first place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I get it: the position update is bound to the player
instance, where as the completedObserver is bound to the playerItem
instance.
I would propose the following:
- We move the
createPlayer
part to the init method or/and just useplayer = AVPlayer.init()
, as this is only called once, during its live time. - We only use
updatePlayer
insetSourceUrl
, but can be sure, that player is never nil. - Split observers in a
positionObserver
(also initialized at the beginning) and acompletedObserver
, reset every time onreset
. ThepositionObserver
is reset ondispose
. - Replacing the
positonObserver
on every source change doesn't really make sense, as the position updates keep on immediately, except url is nil. We should either remove them on every stop or leave them always running, I guess.
packages/audioplayers_darwin/darwin/Classes/WrappedMediaPlayer.swift
Outdated
Show resolved
Hide resolved
self.reset() | ||
completerError?() | ||
default: | ||
break | ||
} | ||
} | ||
|
||
playerItemStatusObservation?.invalidate() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just as note for myself: Invalidate is now called in reset()
for both creating and updating the player
packages/audioplayers_darwin/darwin/Classes/WrappedMediaPlayer.swift
Outdated
Show resolved
Hide resolved
# Description Pick refactor code of #1549 --------- Co-authored-by: Gabriel Terwesten <gabriel@terwesten.net>
# Conflicts: # packages/audioplayers_darwin/darwin/Classes/WrappedMediaPlayer.swift
@blaugold small reminder, if you still plan to work on this. Thank you ;D |
# Conflicts: # packages/audioplayers_darwin/darwin/Classes/WrappedMediaPlayer.swift
AVPlayerItem.status
before setting it on AVPlayer
AVPlayerItem.status
before being assigned to AVPlayer
@blaugold do you agree with the changes? Feel free to comment the concerns. I'll merge in the next few days :) |
…ned to `AVPlayer` (#1549) # Description * KV-Observer is now registered just after creating the `AVPlayerItem`. * Make player object non-nullable --------- Co-authored-by: Gustl22 <git@reb0.org>
Description
Beginning with
4.1.0
we are seeing a lot ofTimeoutException after 0:00:30.000000: Future not completed
exceptions on iOS.I think I have tracked it down to when the KV-Observer for
AVPlayerItem.status
is registered. Before this change this was done after setting theAVPlayerItem
on theAVPlayer
. The problem with this is thatAVPlayerItem
starts loading immediately after setting it on theAVPlayer
and can finish loading before the KV-Observer is even registered.Now the KV-Observer is registered just after creating the
AVPlayerItem
.The fix could have been done with less changes, but I though
WrappedMediaPlayer
could be clean up a bit.Checklist
fix:
,feat:
,docs:
,chore:
etc).///
, where necessary.Breaking Change