【发布时间】:2018-10-26 08:31:51
【问题描述】:
我正在开发一个 iOS 应用,它只播放 HLS 直播视频。
我的问题是我已经使用 AVPlayer 和视图控制器来设置操场,一切正常,视图控制器已启动,播放器也已启动,但流未启动。该流是一种 .m3u8 类型,在 safari 和 chrome 中工作得非常好。 iOS 不会在模拟器或真实设备上显示视频。
我还搜索了其他 SO 解决方案,但它们都没有对我有用。
/* Button to play live news streaming */
@IBAction func liveNews(_ sender: Any)
{
guard let NewsUrl = URL(string: "http://cdn39.live247stream.com/A1TVuk/tv/playlist.m3u8")
else {
return }
/* Create an AV PLAYER and passed the HLS URL to it */
let player = AVPlayer(url: NewsUrl)
player.allowsExternalPlayback = true
/* Setup a player view controller to handle the stream */
let playerViewController = AVPlayerViewController()
playerViewController.player = player
/* Using method of play() to load and play the stream */
present(playerViewController, animated: true){
playerViewController.player?.play()
}
【问题讨论】:
-
查看编辑帖
-
一切似乎都井然有序。你试过检查玩家的
error属性吗?另外,尝试在玩家的status属性上放置一个观察者。
标签: ios swift xcode avplayer http-live-streaming