Guest User

Untitled

a guest
Dec 10th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. func checkCurrentTime(playerTimeMilliseconds: Int) {
  2.  
  3. for (millisecond, beatCount) in beatCounts {
  4. if playerTimeMilliseconds == millisecond {
  5. //show beatCount in label on UI
  6. }
  7. }
  8. }
  9.  
  10.  
  11.  
  12.  
  13.  
  14. func playSound(url: URL) {
  15.  
  16. let playerItem: AVPlayerItem = AVPlayerItem(url: url)
  17. player = AVPlayer(playerItem: playerItem)
  18.  
  19.  
  20. try! AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
  21. try! AVAudioSession.sharedInstance().setActive(true)
  22. player?.play()
  23.  
  24. player?.addPeriodicTimeObserver(forInterval: CMTimeMakeWithSeconds(1, 1000), queue: DispatchQueue.main, using: { [weak self] (CMTime) in
  25.  
  26. print("cmtime is (CMTime)")
  27. CMTime.value
  28.  
  29. if self?.player?.currentItem?.status == .readyToPlay {
  30.  
  31. }
  32. })
  33.  
  34. }//end playSound
Add Comment
Please, Sign In to add comment