我想从第15秒开始播放声音
I want to make a sound play starting from the 15th second
我想从第 15 秒开始播放声音。
我怎样才能以编程方式做到这一点?
谢谢!
据我所知,您不是从头开始播放音频。在这种情况下:
您需要使用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()
}
}
我想从第 15 秒开始播放声音。 我怎样才能以编程方式做到这一点? 谢谢!
据我所知,您不是从头开始播放音频。在这种情况下:
您需要使用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()
}
}