我不是一个
IOS程序员,但是我需要一个简单的应用程序来播放一个wowza服务器的音频流.这是我的代码,我没有错误,但也没有音频.任何指导或帮助?
import UIKit import AVFoundation class ViewController: UIViewController { var player = AVAudioPlayer() override func viewDidLoad() { super.viewDidLoad() var fileURL: NSURL = NSURL(string: "http://url----.com/playlist.m3u8") var error:NSError? player = AVAudioPlayer(contentsOfURL: fileURL,error: &error) if player.prepareToPlay() && player.play(){ println("yes") } else { println("no") } }
解决方法
这对我有用:
var player = AVPlayer() func configureView() { let url = "http://stream.your.url.com" let playerItem = AVPlayerItem( URL:NSURL( string:url ) ) player = AVPlayer(playerItem:playerItem) player.rate = 1.0; player.play() }