I was woking on a small app project, and I made a video to put into the storyboard. My only problem, however, is that I don't know how to add the video to the storyboard. The ImageView doesn't accept the filetype (.mov). Online, I have only found a tutorial for Xcode 4, and nothing else. I need the video and not a GIF file because I don't want the GIF to loop forever. I'm using Swift.
Thanks!
I would recommend you to add the MediaPlayer.framework under the build phase option
Build phase -> link binary with library -> use the add button and type mediaplayer and add the MediaPlayer.framework. Once done add the following code:
import UIKit
import MediaPlayer
class ViewController: UIViewController {
var moviePlayer: MPMoviePlayerController!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let path = NSBundle.mainBundle().pathForResource("sample", ofType:"mp4")
let url = NSURL.fileURLWithPath(path!)
self.moviePlayer = MPMoviePlayerController(contentURL: url)
if let player = self.moviePlayer {
player.view.frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: self.view.frame.size.height)
player.view.sizeToFit()
player.scalingMode = MPMovieScalingMode.Fill
player.fullscreen = true
player.controlStyle = MPMovieControlStyle.None
player.movieSourceType = MPMovieSourceType.File
player.repeatMode = MPMovieRepeatMode.One
player.play()
self.view.addSubview(player.view)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With