harshal jadhav
harshal jadhav

Reputation: 5684

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

Upvotes: 2

Views: 1115

Answers (3)

chaitali gorhe
chaitali gorhe

Reputation: 36

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.

Upvotes: 2

harshal jadhav
harshal jadhav

Reputation: 5684

I used the cocoa pod https://github.com/piemonte/Player.

You can use the delegate methods to control the playback.

Upvotes: 0

Taras Chernyshenko
Taras Chernyshenko

Reputation: 2829

Use method func playImmediately(atRate:) instead of func play()

Upvotes: 0

Related Questions