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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With