vladasha vladasha - 1 year ago 206
iOS Question

Dismiss video when it is finished playing Swift

I am using the MPMoviePlayerController to play a video. I want to dismiss the video when it has finished playing. Here is my code:

import UIKit
import MediaPlayer

class programViewController: UIViewController {

var moviePlayer : MPMoviePlayerController?

override func viewDidLoad() {
// Do any additional setup after loading the view.
playVideo("video", type: "mov")

func playVideo(navn:String, type:String) {
let path = NSBundle.mainBundle().pathForResource(navn, ofType: type)
let url = NSURL.fileURLWithPath(path!)
moviePlayer = MPMoviePlayerController(contentURL: url)
if let player = moviePlayer {
player.view.frame = self.view.bounds
player.scalingMode = .AspectFit
player.shouldAutoplay = true
player.fullscreen = false

Answer Source

It is possible just to delete the view from subviews, and because the last made subview is the movie player view you can delete it just by using this code: