如何将解析后的音频文件添加到AVAudioPlayer
而不是AVPlayer
?我希望能够暂停,播放,停止,重放和使用滑块来控制音频播放。我试过这个:
我的尝试:
var query = PFQuery(className:"Song1")
query.getObjectInBackgroundWithId("YSuNRfKq3n") {
(object : PFObject?, error : NSError?) -> Void in
if let AudioFileURLTemp = object?.objectForKey("SongFile")?.url {
AudioPlayer = AVPlayer(URL: NSURL(string: AudioFileURLTemp!))
AudioPlayer.play()
}
)
}
答案 0 :(得分:0)
试试这个
var query = PFQuery(className:"Song1")
query.getObjectInBackgroundWithId("objectId") {
(object : PFObject?, error : NSError?) -> Void in
if let AudioFileURLTemp = object?.objectForKey("SongFile")?.url {
AudioPlayer = AVPlayer(URL: NSURL(string: AudioFileURLTemp!))
AudioPlayer.play()
}
)
}
答案 1 :(得分:0)
类ViewController:UIViewController,AVAudioPlayerDelegate,AVAudioRecorderDelegate {
var goAudio = AVPlayer()
var show = AVAudioPlayer()
var soundData : NSData!
override func viewDidLoad() {
super.viewDidLoad()
streamShow()
}
@IBAction func playShow(sender: UIButton) {
self.show.prepareToPlay()
self.show.volume = 1.0
self.show.delegate = self
self.show.play()
}
func streamShow(){
var query = PFQuery(className:"sveglia")
query.getObjectInBackgroundWithId("hQHeNCqccH") {
(object : PFObject?, error : NSError?) -> Void in
if let AudioFileURLTemp = object?.objectForKey("audio")?.url {
self.goAudio = AVPlayer(URL: NSURL(string: AudioFileURLTemp!))
let fileURL = NSURL(string: AudioFileURLTemp!)
var error: NSError?
let data = NSData(contentsOfURL: fileURL!)
self.show = AVAudioPlayer(data: data, error: &error)
}
}
}
}