1

I want to make a sound play starting from the 15th second. How can I do it programmatically? Thanks!

Leo Dabus
  • 229,809
  • 59
  • 489
  • 571
  • No. I want to sound began to play with 15 seconds. Thanks! –  Jan 15 '15 at 00:24
  • What do you mean "with 15 seconds"? Do you mean you want a delay before it plays? Do you mean you want it to play for 15 seconds and then stop? Etc... Also, explain what you have tried and show your code. – Fogmeister Jan 15 '15 at 00:26

1 Answers1

0

As I can understand you are trying to start your audio not from the beginning. In this case:

You need to use seekToTime

import UIKit
import AVFoundation

class ViewController: UIViewController {
    var player: AVPlayer!
    override func viewDidLoad() {
        super.viewDidLoad()
        let audioUrl = URL(string: "https://www.ringtonemobi.com/storage/upload/user_id_1/iphone-5-alarm-2016-08-21-01-49-25.mp3")!
        player = AVPlayer(url: audioUrl)
        player.seek(to: .init(seconds: 15, preferredTimescale: 1))
        player.play()
    }
}
Leo Dabus
  • 229,809
  • 59
  • 489
  • 571