a flexible class for AVPlayer
let player = Zany(url: url)
let player = Zany(url: url, observer: { (zany, progress) -> (Void) in
// DispatchQueue.main
// update UI about progress
})
You can create a new instance of player and play as needed by calling the play()
function.
let player = Zany(url: url, observer: { (zany, progress) -> (Void) in
// DispatchQueue.main
// update UI about progress
})
player.play()
Other functions are:
play()
: play a paused or newly created playerpause()
: pause a running playerreset(_ url: URL?, restart: Bool = true)
: reset a running player, change the URL.
Properties:
.id
: unique identifier of the player.state
: define the type of player (paused
,running
,finished
)
you can add progress Observers for the Zany instance
let token = player.observe { (zany, progress) -> (Void) in
// DispatchQueue.main
// update UI about progress
}
player.play()
You can remove an observer by using the token:
player.remove(observer: token)
You can listen for state change by assigning a function callback for .onStateChanged
property.
player.onStateChanged = {(zany,newState) in
switch newState {
case .running:
// for example: change button state
// the player is running
case .paused:
// the player is paused
case .finished:
// the player playFinished
}
}
Zany is compatible with Swift 4.x. All Apple platforms are supported:
- iOS 9.0