AVPlayer播放TS文件。

3

我想通过以下方式从服务器播放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
        }
    }
}

播放器无法播放该文件。 我检查过在浏览器中下载该文件,发现可以正常工作。 有什么办法可以解决这个问题吗?

1个回答

8

AVPlayer(或Apple框架中的任何类)无法播放TS文件。

唯一的方法是将其放入通过本地http服务器分发的m3u8播放列表中,并播放此播放列表。否则,您必须将ts转换为mp4,请参见TS2MP4GPAC


iOS 16后不再工作,仅播放音频。 - Fadi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接