Pre-buffering for AVQueuePlayer

Ok, I’ve looked over this problem again and written some code to check out AVQueuePlayer. jollyCocoa’s answer pointed me in the right direction by suggesting to observe the status property on AVPlayerItem. However the documentation doesn’t seem to point out that this property (and it’s AVPlayerItemStatusReadyToPlay value in particular) might be related to buffering. However … Read more

How to detect when AVPlayer video ends playing?

To get the AVPlayerItemDidPlayToEndTimeNotification your object needs to be an AVPlayerItem. To do so, just use the .currentItem property on your AVPlayer Now you will get a notification once the video ends! See my example: let videoPlayer = AVPlayer(URL: url) NSNotificationCenter.defaultCenter().addObserver(self, selector: “playerDidFinishPlaying:”, name: AVPlayerItemDidPlayToEndTimeNotification, object: videoPlayer.currentItem) func playerDidFinishPlaying(note: NSNotification) { print(“Video Finished”) } Swift … Read more

Add custom header field in request of AVPlayer

You can use AVURLAssetHTTPHeaderFieldsKey of AVURLAsset‘s init option to modify request headers. For example: NSMutableDictionary * headers = [NSMutableDictionary dictionary]; [headers setObject:@”Your UA” forKey:@”User-Agent”]; AVURLAsset * asset = [AVURLAsset URLAssetWithURL:URL options:@{@”AVURLAssetHTTPHeaderFieldsKey” : headers}]; AVPlayerItem * item = [AVPlayerItem playerItemWithAsset:asset]; self.player = [[AVPlayer alloc] initWithPlayerItem:item]; Note: I found this key in sources of WebKit, but this … Read more

No AVPlayer Delegate? How to track when song finished playing? Objective C iPhone development

Yes, the AVPlayer class does not have a delegate protocol like the AVAudioPlayer. You need to subscribe to notifications on an AVPlayerItem. You can create an AVPlayerItem using the same URL that you would otherwise pass to -initWithURL: on AVPlayer. -(void)startPlaybackForItemWithURL:(NSURL*)url { // First create an AVPlayerItem AVPlayerItem* playerItem = [AVPlayerItem playerItemWithURL:url]; // Subscribe to … Read more