Search code examples
iosswiftavplayer

problems while playing video from s3 using AVplayer


Hi all i am trying to play a video from s3 using Avplayer. Now if i play the video, the video starts playback after the whole video is buffered. so I added player.automaticallyWaitsToMinimizeStalling = false, but now the video automatically pauses

import UIKit
import AVFoundation
import AVKit
class ViewController: UIViewController {
    var player: AVPlayer!
    var item : AVPlayerItem!

    override func viewDidLoad() {
        super.viewDidLoad()
        item = AVPlayerItem(url: URL(string: "https://cent-churchconnect.s3-ap-southeast-2.amazonaws.com/cent-churchconnect/testAdmin/eb8cc8b5-80e0-468a-a2c9-979cf1b5ac76_toystory.mp4")!)
        player = AVPlayer(playerItem: item)
        let controller = AVPlayerViewController()
        present(controller, animated: true) { _ in }
        controller.player = player
        addChildViewController(controller)
        view.addSubview(controller.view)
        controller.view.frame = CGRect(x: 0, y: 50, width: self.view.frame.size.width, height: 300)
        controller.player = player
        controller.showsPlaybackControls = true
        if #available(iOS 10.0, *) {
            player.automaticallyWaitsToMinimizeStalling = false
            player.play()
        } else {
            // Fallback on earlier versions
        }
    }
}

Solution

  • I had the same issue below steps worked for me, Try to use method func playImmediately(atRate:) and make sure the property player.automaticallyWaitsToMinimizeStalling = false is set properly.