3

I want to play ts file from server with :

- (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
        }
    }
}

And the player not play the file. i check if the file can be download in my browser and it work perfectly. Any idea how to fix it?

1 Answer 1

8

AVPlayer (nor any class in the Apple framework) cannot play TS files.

The only way is to put it in a m3u8 playlist that you distribute via a local http server, and play this playlist. Otherwise, you have to convert the ts to a mp4, see TS2MP4 or GPAC.

1
  • Doesn't work any more after iOS 16, it plays audio only.
    – Fadi
    Oct 8, 2022 at 16:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.