我想从服务器播放 ts 文件:
- (void)play {
NSURL *url= [NSURL URLWithString:@"http://10.0.0.18/11.ts"];
player = [[AVPlayer alloc] initWithURL:url];
[player addObserver:self forKeyPath:@"status" options:0 context:nil];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change context:(void *)context {
if (object == player && [keyPath isEqualToString:@"status"]) {
if (player.status == AVPlayerStatusReadyToPlay) {
[player setVolume:1.0];
[player play];
} else if (player.status == AVPlayerStatusFailed) {
// something went wrong. player.error should contain some information
}
}
}
并且播放器不播放该文件。
我检查该文件是否可以在我的浏览器中下载并且它运行良好。
知道如何修复它吗?
AVPlayer(以及Apple框架中的任何类)无法播放TS文件。
唯一的方法是将其放入通过本地 http 服务器分发的 m3u8 播放列表中,然后播放该播放列表。否则,您必须将 ts 转换为 mp4,请参阅TS2MP4 https://github.com/Keemotion/TS2MP4 or GPAC http://gpac.wp.mines-telecom.fr/.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)