6

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 !!

Bhanu
  • 1,249
  • 10
  • 17
IOS Dev
  • 286
  • 2
  • 14
  • What do you need exactly? You just need to show subtitles on video in app or do you want compose the video with embedded subtitles? These two are different things and complexity differs for the later case. – blancos Sep 04 '15 at 08:41
  • I need to show subtitles on video. I am able to play video.The only thing is i am not able to show subtitles . Adding a view as subview of Player to show a label in it. But after player starts playing a video it doesn't show subtitles. – IOS Dev Sep 07 '15 at 04:33
  • Still not on the same page. Subtitles are already embedded in the video? Or you are creating subtitles to show it just on the AVPlayer? – blancos Sep 07 '15 at 08:55
  • 1
    I am getting separate srt file for each video from the web api, have to read the file and show subtitles on the player. I am not creating any subtitle. Now i am able to show subtitles but done button is gone after adding subtitle. I have created a category of AVPlayerViewController – IOS Dev Sep 07 '15 at 09:45
  • did you get any solution for this? – Parth Doshi May 15 '16 at 04:41

0 Answers0