我想从第15秒[关闭]开始播放声音

问题描述 投票:0回答:1

我想从15秒开始播放声音。如何以编程方式进行?谢谢!

ios swift avfoundation avplayer seektotime
1个回答
0
投票

您需要使用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() } }

© www.soinside.com 2019 - 2024. All rights reserved.