我正在尝试在Xcode12.5的ios应用程序中播放30秒的rtsp视频。不幸的是,我找不到这样做的方法。有没有人能给我一个插件或者解决这个问题的方法?
先谢谢你,帕特里克
发布于 2021-07-05 05:01:39
尝试使用VLCKit/MobileVLCKit完成此任务。
发布于 2021-10-15 10:01:18
好吧,这是一个老问题,但我也发现了这个问题,而且没有太多的数据……
正如德米特罗指出的那样,MobileVLCKit是最好的选择。
我使用swiftui作为接口来实现它,所以首先我必须创建一个UIViewRepresentable来显示流视图
首先导入MobileVLCKit
struct VlcPlayerRepresentable: UIViewRepresentable{ //MARK: Transform from a UIView into swiftUI compatible
func updateUIView(_ uiView: UIView, context: UIViewRepresentableContext<VlcPlayerRepresentable>) {
}
func makeUIView(context: Context) -> UIView {
return PlayerUIView(frame: .zero)
}}然后启动播放器
class PlayerUIView: UIView, VLCMediaPlayerDelegate,ObservableObject{
let mediaPlayer : VLCMediaPlayer = VLCMediaPlayer()// You can also add options in here
override init(frame: CGRect) {
super.init(frame: UIScreen.screens[0].bounds)
let url = URL(string: "rtsp://rtspURLString:8554/live")!//replace your resource here
let media = VLCMedia(url: url)
media.addOptions([// Add options here
"network-caching": 300,
"--rtsp-frame-buffer-size":100,
"--vout": "ios",
"--glconv" : "glconv_cvpx",
"--rtsp-caching=": 150,
"--tcp-caching=": 150,
"--realrtsp-caching=": 150,
"--h264-fps": 20.0,
"--mms-timeout": 60000
])
mediaPlayer.media = media
mediaPlayer.delegate = self
mediaPlayer.drawable = self
mediaPlayer.audio.isMuted = true
mediaPlayer.videoAspectRatio = UnsafeMutablePointer<Int8>(mutating: ("16:9" as NSString).utf8String)
mediaPlayer.play()}
func checkConnection() -> Bool{
let isPlaying: Bool = mediaPlayer.isPlaying
return isPlaying
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func layoutSubviews() {
super.layoutSubviews()
}}然后只需将可表示的视图添加到结构中,现在您可以将此结构添加到您想要显示流的任何位置。
struct VideoViewStructure: View {
var body: some View {
return VStack{
VlcPlayerRepresentable()
}
}}https://stackoverflow.com/questions/68243722
复制相似问题