Skip to content

Yvent/Zany

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Zany

a flexible class for AVPlayer

Zany - a music(radio) player in AVPlayer

中文说明

Player

Create a player

  let player = Zany(url: url)

Create a player with progress.

  let player = Zany(url: url, observer: { (zany, progress) -> (Void) in
    // DispatchQueue.main
    // update UI about progress

  })

Manage a player

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 player
  • pause(): pause a running player
  • reset(_ 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)

Adding/Removing Observers

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)

Observing state change

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
            
       }
 }

Requirements

Zany is compatible with Swift 4.x. All Apple platforms are supported:

  • iOS 9.0+

About

a flexible class for AVPlayer

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages