Created
July 14, 2015 09:06
-
-
Save sonsongithub/ec1962ecd1530e3c2869 to your computer and use it in GitHub Desktop.
Simple movie view using AVKit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import AVFoundation | |
import AVKit | |
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view, typically from a nib. | |
let item = AVPlayerItem(URL: NSURL(string: "http://i.imgur.com/4WHLcYw.mp4")!) | |
let con:AVPlayerViewController = AVPlayerViewController() | |
NSNotificationCenter.defaultCenter().addObserver(self, selector: "didPlayToEnd:", name: AVPlayerItemDidPlayToEndTimeNotification, object: item) | |
let player = AVPlayer(playerItem: item) | |
player.actionAtItemEnd = .None | |
con.player = player | |
con.view.frame = CGRect(x: 0, y: 0, width: 320, height: 240) | |
self.view.addSubview(con.view) | |
con.player?.play() | |
con.showsPlaybackControls = false | |
} | |
func didPlayToEnd(notification:NSNotification) { | |
if let item = notification.object as? AVPlayerItem { | |
item.seekToTime(kCMTimeZero) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment