Our application allows users to record video, after which the application adds subtitles and exports the edited video.
The goal is to play the video right away, but AVPlayer appears only after the video is completed (and only audio is played, which is a separate issue).
Here's what's happening now: we are showing a preview so that the user can see what he is recording in real time. After the user has completed the recording, we want to play the video for viewing. Unfortunately, the video does not appear, and only sound is played. An image showing a frame of a video appears when sound is being played.
Why is this happening?
func exportDidFinish(exporter: AVAssetExportSession) { println("Finished exporting video") // Save video to photo album let assetLibrary = ALAssetsLibrary() assetLibrary.writeVideoAtPathToSavedPhotosAlbum(exporter.outputURL, completionBlock: {(url: NSURL!, error: NSError!) in println("Saved video to album \(exporter.outputURL)") self.playPreview(exporter.outputURL) if (error != nil) { println("Error saving video") } }) } func playPreview(videoUrl: NSURL) { let asset = AVAsset.assetWithURL(videoUrl) as? AVAsset let playerItem = AVPlayerItem(asset: asset) player = AVPlayer(playerItem: playerItem) let playerLayer = AVPlayerLayer(player: player) playerLayer.frame = view.frame view.layer.addSublayer(playerLayer) player.play() }
source share