【发布时间】:2020-02-15 23:53:56
【问题描述】:
为什么下面的代码没有声音?它为 play() 返回“true”,但我什么也听不见。
let path = "/Users/account/Music/sound.mp3";
let fileURL = NSURL(fileURLWithPath: path)
var Player = AVAudioPlayer(contentsOfURL:fileURL, error:nil);
Player.delegate = self;
Player.prepareToPlay();
Player.volume = 1.0;
var res = Player.play();
println(res);
如果我改用下面的代码,我可以听到声音。
var inFileURL:CFURL = fileURL!;
var mySound = UnsafeMutablePointer<SystemSoundID>.alloc(sizeof(SystemSoundID));
AudioServicesCreateSystemSoundID(inFileURL, mySound);
AudioServicesPlaySystemSound(mySound.memory)
- OS X Yosemite 10.10.3
- Xcode 6.2
【问题讨论】:
标签: macos swift audio avfoundation