Created
May 11, 2017 18:27
-
-
Save tsraveling/e5faacddc617e88b94c7dff3cfd00f07 to your computer and use it in GitHub Desktop.
Sound Player
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| static var audioPlayer : AVPlayer? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func playerDidFinishPlaying() { | |
| MessageCell.lastButton?.setImage(#imageLiteral(resourceName: "play"), for: .normal) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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