I want to detect if my AVPlayer is buffering for the current location, so that I can show a loader or something. But I can't seem to find anything in the documentation for AVPlayer.
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- Get the NSRange for the visible text after scroll
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
- didBeginContact:(SKPhysicsContact *)contact not in
- Attempt to present UIAlertController on View Contr
Updated for Swift 4.2
#Updated in Swift 4 and worked fine
As through i have gone with accepted answer but didn't work in swift 4 for me so after certain research i have found this thinks from apple doc. There are two way to determine AVPlayer states that are,
and using ways is like this
And Don't forget to kill time observer to save from memory leak. method for killing instance, add this method according to your need but i have used it in viewWillDisappear method.
You can observe the values of your
player.currentItem
:then
Swift 4 observations:
Observers need to be removed after we are done observing.
To remove these three observers just set
playbackBufferEmptyObserver
,playbackLikelyToKeepUpKeyPathObserver
andplaybackBufferFullObserver
tonil
.No need to remove them manually (this is specific for
observe<Value>(_ keyPath:, options:, changeHandler:)
method.The accepted answer didn't work for me, I used the code below to show the loader efficiently.