I am using AVPlayerViewController
of AVKit
framework for playing videos directly in landscape mode. I want to know how to show subtitles. I searched but dint find any solution about. I was using MPMoviePlayerViewController
for playing Videos but as it is depreciated in IOS 9 and later versions i am implementing the same using AVKit
.
NSURL *videoURL = [NSURL URLWithString:video.videoLink];
AVPlayer *newPlayer = [AVPlayer playerWithURL:videoURL];
AVPlayerViewController *playerViewController = [AVPlayerViewController new];
playerViewController.player = newPlayer;
int32_t timeScale = newPlayer.currentItem.asset.duration.timescale;
CMTime seektime=CMTimeMakeWithSeconds(startPlayBackTime, timeScale);
[playerViewController.player seekToTime:seektime toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero];
}
[playerViewController.player play];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[newPlayer currentItem]];
playerViewController.player.closedCaptionDisplayEnabled = YES;
[self presentViewController:playerViewController animated:YES completion:nil];
It's working perfectly but problem is i am not able to show subtitles. I found few examples for subtitles but all are using AVPlayer
as subview so, those methods are not working for me.
Any idea how to achieve this ?
Thanks !!