Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation could use note on how to loop background videos #171

Open
RamblinWreck77 opened this issue Feb 17, 2017 · 0 comments
Open

Comments

@RamblinWreck77
Copy link

RamblinWreck77 commented Feb 17, 2017

Wrestled with this for longer than I'd like to admit. Turns out background videos do not loop by default and none of the examples I found worked. The eventual solution was below (leaving the ? off moviePlayerController will throw an unexpected nil error):

Some type of .shouldLoopVideo = true/false would be a nice feature!

let vc = OnboardingViewController(backgroundVideoURL: generateVideo(file: "engineBackground"), contents: [firstPage, secondPage, thirdPage])!
vc.shouldBlurBackground = false
vc.shouldFadeTransitions = true
vc.swipingEnabled = true

NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: vc.moviePlayerController?.player?.currentItem, queue: nil, using: { (_) in
DispatchQueue.main.async {
vc.moviePlayerController?.player?.seek(to: kCMTimeZero)
vc.moviePlayerController?.player?.play()
}
})

static private func generateVideo(file: String) -> URL {
let bundle = Bundle.main
let moviePath = bundle.path(forResource: file, ofType: "mp4")
let movieURL = URL(fileURLWithPath: moviePath!)
return movieURL
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant