Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVPlayer play ts file

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?

like image 707
YosiFZ Avatar asked Dec 27 '25 15:12

YosiFZ


1 Answers

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.

like image 172
smad Avatar answered Dec 30 '25 04:12

smad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!