gpt4 book ai didi

ios - 尝试使用 Swift AVPlayer 播放音频

转载 作者:搜寻专家 更新时间:2023-10-31 22:07:34 25 4
gpt4 key购买 nike

这是我当前的 ViewController:

import UIKit
import AVFoundation

class SecondViewController: UIViewController {
override func viewDidLoad() {
var player = AVPlayer()
let url = "http://www.nasa.gov/mp3/640149main_Computers%20are%20in%20Control.mp3"
let playerItem = AVPlayerItem( URL:NSURL( string:url ) )
player = AVPlayer(playerItem:playerItem)
player.rate = 1.0;
player.play()
}
}

当我在模拟器中运行它时,我听不到音频,可能是 iOS sim 不播放音频,还是我的代码有问题?

最佳答案

移动线:

    var player = AVPlayer()

... 所以它在行之前:

override func viewDidLoad() {

关于ios - 尝试使用 Swift AVPlayer 播放音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32151737/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com