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

How to play video with AVPlayerViewController (AVKit) in Swift

Swift 3.x – 5.x Necessary: import AVKit, import AVFoundation AVFoundation framework is needed even if you use AVPlayer If you want to use AVPlayerViewController: let videoURL = URL(string: “https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4”) let player = AVPlayer(url: videoURL!) let playerViewController = AVPlayerViewController() playerViewController.player = player self.present(playerViewController, animated: true) { playerViewController.player!.play() } or just AVPlayer: let videoURL = URL(string: “https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4”) … Read more