This file contains hidden or 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
| NSNotificationCenter.defaultCenter().addObserver(self, selector: "playerItemDidReachEnd:", name: AVPlayerItemDidPlayToEndTimeNotification, object: self.playerItem) |
This file contains hidden or 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 | |
| class AVPlayerView : UIView { | |
| // UIViewのサブクラスを作りlayerClassメソッドをオーバーライドしてAVPlayerLayerに差し替える | |
| override class func layerClass() -> AnyClass { | |
| return AVPlayerLayer.self | |
| } | |
This file contains hidden or 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
| // サンプル動画のパスを取得 | |
| let bundle = NSBundle.mainBundle() | |
| let url: NSURL = NSBundle.mainBundle().URLForResource("sample", withExtension: "mp4")! | |
| // 動画のパスを指定してplayerItemを生成 | |
| self.playerItem = AVPlayerItem(URL: url) | |
| // 上で生成したplayerItemを指定してplayerを生成 | |
| self.videoPlayer = AVPlayer(playerItem: self.playerItem) | |
This file contains hidden or 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
| self.videoTimeObserver = self.videoPlayer!.addPeriodicTimeObserverForInterval(CMTimeMake(150, 600), | |
| queue: dispatch_get_main_queue(), | |
| usingBlock: {[unowned self](CMTime) in | |
| self.syncSeekber() | |
| self.updateTimeLabel() | |
| }) |
This file contains hidden or 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
| extension CMTime { | |
| var isValid:Bool { | |
| return (flags & .Valid) != nil | |
| } | |
| } |
This file contains hidden or 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
| override class func layerClass() -> AnyClass { | |
| return AVPlayerLayer.self | |
| } |
This file contains hidden or 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
| + (Class)layerClass | |
| { | |
| return [AVPlayerLayer class]; | |
| } |
This file contains hidden or 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
| CGContextRef squareContext = UIGraphicsGetCurrentContext(); | |
| CGContextClearRect(squareContext, cropRect); |
This file contains hidden or 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
| CGImageRef srcImageRef = self.imageView.image.CGImage; | |
| CGImageRef croppedImageRef = CGImageCreateWithImageInRect(srcImageRef, [切り取る枠のCGRectを指定]); | |
| UIImage *croppedImage = [UIImage imageWithCGImage:croppedImageRef]; |
This file contains hidden or 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
| - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; | |
| - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event; | |
| - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event; |
NewerOlder