0
在Swift中使用AVPlayer。 iPhone上沒有錯誤,但沒有聲音播放。在Swift中使用AVPlayer。 iPhone上沒有錯誤但沒有聲音播放
我是新來的斯威夫特。我會很感激迴應。
這裏是我的代碼:
import UIKit
import AVFoundation
class PlayerViewController: UIViewController {
// This time, we'll declare avPlayer as an instance variable,
// which means it exists as long as our view controller exists.
var avPlayer: AVPlayer!
override func viewDidLoad() {
super.viewDidLoad()
print("Connecting...")
// If you'd rather not use this sound file,
// replace the string below with the URL of some other MP3.
let urlString = "http://live.canstream.co.uk:8000/bangradio.mp3"
let url = NSURL(string: urlString)!
avPlayer = AVPlayer(URL: url)
print("Connected to One Radio!")
avPlayer.play()
print("Now playing...")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
嗨,歡迎來到Stack Overflow。在調試方面到目前爲止您嘗試過了什麼?例如,你確定你沒有靜音嗎?你是否試圖用Xcode模擬器等。 – tech4242
我敢打賭,iOS 9應用傳輸安全功能阻止了你的http請求。看到這裏的解決方案:http://stackoverflow.com/q/31254725/22147 –
這不是我的問題,我仍然不能聽音樂。任何解決方案 – Pavlos