You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将Hololens视频流传输至iOS?求解播放及推流失败问题

针对AVPlayer视频不显示及OBS推流失败的解决方案

先来说你的AVPlayer问题,我一眼就看到几个容易踩的坑:

  • URL转义字符错误:你的URL里用了&,这是HTML场景下的转义字符,但iOS的NSURL解析时会把它当成普通字符串,而不是参数分隔符&。你需要把所有的&替换成&,修正后的URL代码应该是:

    NSURL *url = [[NSURL alloc] initWithString:@"https://username:password@ip_address/api/holographic/stream/live_high.mp4?holo=true&pv=true&mic=true&loopback=true"];
    
  • HTTP Basic Auth的潜在兼容问题:直接把用户名密码嵌在URL里的方式,部分服务器或AVPlayer的HTTPS处理逻辑可能不兼容。如果替换&后还是无法加载,试试手动添加Authorization请求头:

    NSURL *url = [[NSURL alloc] initWithString:@"https://ip_address/api/holographic/stream/live_high.mp4?holo=true&pv=true&mic=true&loopback=true"];
    NSMutableURLRequest *mutableRequest = [NSMutableURLRequest requestWithURL:url];
    NSString *authStr = [NSString stringWithFormat:@"%@:%@", @"username", @"password"];
    NSData *authData = [authStr dataUsingEncoding:NSUTF8StringEncoding];
    NSString *authBase64 = [authData base64EncodedStringWithOptions:0];
    [mutableRequest setValue:[NSString stringWithFormat:@"Basic %@", authBase64] forHTTPHeaderField:@"Authorization"];
    
    AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURLRequest:mutableRequest];
    _player = [AVPlayer playerWithPlayerItem:playerItem];
    
  • AVPlayerViewController未完成视图添加流程:你的代码截断在[self addChildViewControl...,务必完成整个添加步骤,不然播放器视图不会显示出来:

    AVPlayerViewController *controller = [[AVPlayerViewController alloc] init];
    controller.player = _player; // 别漏了设置播放器实例!
    [self addChildViewController:controller];
    controller.view.frame = self.view.bounds; // 根据需求设置合适的布局
    [self.view addSubview:controller.view];
    [controller didMoveToParentViewController:self];
    

再来说OBS推流到iOS的问题:

  • 协议兼容性问题:iOS原生AVPlayer默认支持HLS(.m3u8)、MP4等格式,但OBS默认推送的是RTMP流,原生播放器不直接支持RTMP。你有两个方向解决:要么给OBS装插件让它直接推HLS流,要么在iOS端用第三方播放器库(比如基于FFmpeg的ijkPlayer)来接收RTMP流。

  • 网络环境排查:确保iOS设备和OBS所在电脑在同一个局域网内,没有防火墙或路由器端口限制。OBS的推流地址要填写电脑的局域网IP,对应的端口要开放。

  • 转流适配原生播放器:如果想继续用AVPlayer,可以在电脑上用ffmpeg把OBS的RTMP流转成HLS格式,再共享给iOS端播放。比如执行这条ffmpeg命令:

    ffmpeg -i rtmp://你的OBS推流地址 -c:v copy -c:a copy -f hls -hls_time 10 -hls_list_size 0 ./output.m3u8
    

    然后用Python的SimpleHTTPServer把这个.m3u8文件和生成的分片文件共享出去,iOS端直接访问对应的HTTP地址即可。

如果还是解决不了,可以补充这些信息:服务器返回的HTTP状态码(用Charles抓包查看)、OBS的推流日志、iOS端AVPlayer的status变化回调信息,这样能更精准定位问题。

内容的提问来源于stack exchange,提问作者Harish

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 08:39:03