I'm developing ebook reader based app with PDF book consists of multiple PDF pages. Each page have video icon to play video assets. I used AVPlayer
to play video using AVPlayerItem
and AVURLAsset
(stream from URL
). Its working fine for 10-15 times of playing the same or different video from the same page or different page. But after some time the video is not playing instead it show play icon with cross line.
I have used the below code.
NSURL *videoUrl = [NSURL URLWithString:@"http://WWW.google.com/media/test_1.mp4"]
NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies];
NSDictionary *optionsDic = @{AVURLAssetHTTPCookiesKey : cookies};
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:videoUrl options:optionsDic];
AVPlayerItem *playeritem = [AVPlayerItem playerItemWithAsset:asset];
AVPlayer *player = [[AVPlayer alloc] initWithPlayerItem:playeritem];
AVPlayerViewController *moviePlayerVC = [[AVPlayerViewController alloc]init];
moviePlayerVC.player = player;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self presentViewController:moviePlayerVC animated:NO completion:nil];
});