I want to make a sound play starting from the 15th second [closed]

牧云@^-^@ 提交于 2020-06-18 11:59:10

问题


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


回答1:


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()
    }
}


来源:https://stackoverflow.com/questions/27954696/i-want-to-make-a-sound-play-starting-from-the-15th-second

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!