shaka-project / shaka-player-embedded

Shaka Player in a C++ Framework
Apache License 2.0
236 stars 63 forks source link

Video doesn't render if ShakaPlayerView is initialised with .zero frame #124

Closed jgongo closed 4 years ago

jgongo commented 4 years ago

I've been struggling with this for ages until I found the culprit. I wasn't getting any video rendered and I was literally pulling my hair out. I'm creating this issue in case anybody else comes upon it.

After doing lots of tests I finally found out that if you create the ShakaPlayerView this way:

let playerView = ShakaPlayerView(frame: .zero)

instead of this way

let playerView = ShakaPlayerView()

no video gets rendered in the view.

This view was integrated inside a playback view, and the code was properly setting auto layout constraints:

[playerView, ...].forEach {
    $0.translatesAutoresizingMaskIntoConstraints = false
}

NSLayoutConstraint.activate([
    playerView.leadingAnchor.constraint(equalTo: leadingAnchor),
    playerView.topAnchor.constraint(equalTo: topAnchor),
    playerView.trailingAnchor.constraint(equalTo: trailingAnchor),
    playerView.bottomAnchor.constraint(equalTo: bottomAnchor)
])

I even tried to debug the app with the Xcode's view hierarchy debugger, thinking that I wouldn't have properly setup the views, and the view was being properly laid out, as you can see in the attached screenshot: ShakaPlayerView

If the view is created without any parameter, later changes in layout seem to work properly (for example, rotating the device causes the video to rotate and adapt to the screen), so I guess somehow auto layout is handled properly except for this case, where the view is explicitly assigned a .zero frame in the beginning.

jgongo commented 4 years ago

Oh, no, I found the reason: ShakaPlayerView defines init() and init(player:), but it doesn't override the initialisers inherited from UIView 😭