首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >RTSP Stream xcode 12.5

RTSP Stream xcode 12.5
EN

Stack Overflow用户
提问于 2021-07-04 18:22:26
回答 2查看 54关注 0票数 0

我正在尝试在Xcode12.5的ios应用程序中播放30秒的rtsp视频。不幸的是,我找不到这样做的方法。有没有人能给我一个插件或者解决这个问题的方法?

先谢谢你,帕特里克

EN

回答 2

Stack Overflow用户

发布于 2021-07-05 05:01:39

尝试使用VLCKit/MobileVLCKit完成此任务。

票数 0
EN

Stack Overflow用户

发布于 2021-10-15 10:01:18

好吧,这是一个老问题,但我也发现了这个问题,而且没有太多的数据……

正如德米特罗指出的那样,MobileVLCKit是最好的选择。

我使用swiftui作为接口来实现它,所以首先我必须创建一个UIViewRepresentable来显示流视图

首先导入MobileVLCKit

代码语言:javascript
复制
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)
}}

然后启动播放器

代码语言:javascript
复制
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()
  }}

然后只需将可表示的视图添加到结构中,现在您可以将此结构添加到您想要显示流的任何位置。

代码语言:javascript
复制
struct VideoViewStructure: View {
var body: some View {
    return VStack{
        VlcPlayerRepresentable()
    }
}}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68243722

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档