我正在开发一个可通过rtmp接收视频流的iOS应用。我正在使用MobileVLCKit库执行此任务,但是播放器的性能非常差。 我希望每次视频缓冲后的视频都可以实时再次显示,而不增加延迟时间。
这是我的代码
class ScreenPlayer: UIViewController, VLCMediaPlayerDelegate {
@IBOutlet weak var viewPlayer: UIView!
@IBOutlet weak var loading: UIActivityIndicatorView!
let player: VLCMediaPlayer = {
let p = VLCMediaPlayer()
return p
}()
override func viewDidAppear(_ animated: Bool) {
super.viewDidLoad()
let streamUrl = URL(string: rtmp.nome)
let media = VLCMedia(url: streamUrl!)
player.media = media
// I'm using this because the video stops and only the audio continues, but I still do not have a good result, if you can help me with this too it will be great
player.media .addOptions([
"network-caching" : 10000,
"codec": "avcodec"
])
player.delegate = self
player.drawable = self.viewPlayer
player.play()
}
func mediaPlayerStateChanged(_ aNotification: Notification!) {
switch player.state {
case .buffering:
// This is when the video stops and starts to buffering
print("loading")
loading.startAnimating()
loading.isHidden = false
break
case .playing:
print("playing")
break
case .stopped:
print("stopped")
break
case .error:
print("erro")
break
case .ended:
print("finished")
break
case .esAdded:
print("i don't know what is this")
break
default: break
}
print(player.state.rawValue, player.rate, player.time, player.media.state.rawValue, player.position)
print(self.player.media.metaDictionary)
}