我想从第15秒开始发声。 我该如何以编程方式完成? 谢谢!
答案 0 :(得分:0)
据我所知,您试图从一开始就尝试启动音频。在这种情况下:
您需要使用seekToTime
import UIKit
import AVFoundation
class ViewController: UIViewController {
var myPlayer:AVPlayer? = nil
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
if let myAudioUrl = NSURL(string: "http://freetone.org/ring/stan/iPhone_5-Alarm.mp3") {
myPlayer = AVPlayer(URL: myAudioUrl)
if let myPlayer = myPlayer {
myPlayer.seekToTime(CMTimeMakeWithSeconds(15, 1))
myPlayer.play()
}
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}