Oren Edrich
Oren Edrich

Reputation: 674

Playing background video

I am trying to play a background video but i am having a problem with one line of code. I get an error that says "Cannot invoke initializer for type 'URL' with no arrangements" At this line "open var contentURL: URL = URL()"

open class VideoSplashViewController: UIViewController {

  fileprivate let moviePlayer = AVPlayerViewController()
  fileprivate var moviePlayerSoundLevel: Float = 1.0
  open var contentURL: URL = URL() {
    didSet {
      setMoviePlayer(contentURL)
    }
  }

  open var videoFrame: CGRect = CGRect()
  open var startTime: CGFloat = 0.0
  open var duration: CGFloat = 0.0
  open var backgroundColor: UIColor = UIColor.black {
    didSet {
     view.backgroundColor = backgroundColor
   }
 }

I don't know how to fix this, please help

Upvotes: 0

Views: 110

Answers (2)

Arslan Javed
Arslan Javed

Reputation: 83

You should replace the following code

open var contentURL: URL = URL() {
didSet {
  setMoviePlayer(contentURL)
}}

with this:

 public var contentURL: NSURL = NSURL() {
didSet {
  setMoviePlayer(contentURL)
}}

This will fix your problems.

Upvotes: 0

3li
3li

Reputation: 618

The error message is self-explanatory, URL class doesn't have an initializer with no arguments :)

If you take a look at URL class -Hold down CMD key and click on URL-, you will notice that there is no initializer like this:

init() {}

Therefore you can't just write URL() because that requires the above initializer. However, there is a variety of other initializers in URL class such as:

init?(string: String) {}
init(fileURLWithPath path: String)
...

You can use any of them to initialize the contentURL instance.

open var contentURL: URL = URL(string: "") {/**/}
open var contentURL: URL = URL(fileURLWithPath: "") {/**/}

What is Initializer?

Upvotes: 1

Related Questions