我有一些NSSound
我想转换为AVAudioPlayer
实例的对象。我有NSURL
与对象关联的文件路径(s)NSSound
,但原始文件可能不存在。这是我到目前为止所拥有的:
class SoundObj: NSObject {
var path: NSURL?
var sound: NSSound?
var player: AVAudioPlayer
}
let aSound = SoundObj()
aSound.path = NSURL(fileURLWithPath: "file:///path/to/sound.m4a")
aSound.sound = NSSound(contentsOfURL: aSound.path)!
do {
try aSound.player = AVAudioPlayer(contentsOfURL: aSound.path)
} catch {
// perhaps use AVAudioPlayer(data: ...)?
}
如何将NSSound
对象转换为AVAudioPlayer
实例?