I'm using an Objective-C project for reference for a very similar Swift app. Basically, videos are uploaded to Firebase and the download URL is saved to a "Post" object and played in a UITableViewCell upon retrieval. In the Objective-C project (also using Firebase) it works perfectly but I'm having some trouble in Swift.
Objective-C Code, inside cell, like I said, works perfectly.
- (void)playVideoWithURL:(NSURL *)url {
self.videoPlayer = [[AVPlayer alloc]initWithURL:url];
AVPlayerLayer *layer = [AVPlayerLayer playerLayerWithPlayer:self.videoPlayer];
layer.frame = self.videoView.bounds;
[layer setVideoGravity:AVLayerVideoGravityResizeAspect];
[self.videoView.layer addSublayer:layer];
[self.videoPlayer play];
}
Swift Code, also inside cell, doesn't throw any errors or crash, compiler says URL exists as well as the player and layer (whose frame is not CGRectZero, checked that too).
@IBOutlet var usernameLabel: UILabel!
@IBOutlet var captionLabel: UILabel!
@IBOutlet var avPlayerView: UIView!
var videoPlayer : AVPlayer!
func playVideoWithURL(url: NSURL) {
self.videoPlayer = AVPlayer(URL: url)
let layer = AVPlayerLayer(player: self.videoPlayer)
layer.frame = avPlayerView.bounds
layer.videoGravity = AVLayerVideoGravityResizeAspect
avPlayerView.layer.addSublayer(layer)
videoPlayer.play()
}
To keep it simple I won't post any Firebase code just yet since it all works in the Objective-C project and the download urls are successfully retrieved in the Swift one as well, leading me to believe it has nothing to do with the issue.
Any ideas? This is driving me crazy. Thank you!
UPDATE:
AVPlayer is not actually the issue, since it works with a test video. The issue is with Firebase, currently investigating further.