Skip to content

Instantly share code, notes, and snippets.

@tsraveling
Created May 11, 2017 18:27
Show Gist options
  • Save tsraveling/e5faacddc617e88b94c7dff3cfd00f07 to your computer and use it in GitHub Desktop.
Save tsraveling/e5faacddc617e88b94c7dff3cfd00f07 to your computer and use it in GitHub Desktop.
Sound Player
static var audioPlayer : AVPlayer?
func playerDidFinishPlaying() {
MessageCell.lastButton?.setImage(#imageLiteral(resourceName: "play"), for: .normal)
}
let player_item = AVPlayerItem(url: url)
MessageCell.audioPlayer = AVPlayer(playerItem: player_item)
MessageCell.audioPlayer?.rate = 1
MessageCell.audioPlayer?.play()
// Set up tracker
NotificationCenter.default.addObserver(self,selector:#selector(self.playerDidFinishPlaying), name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: player_item)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment