diff options
| author | Brian Jordan | 2012-03-27 20:54:10 -0400 |
|---|---|---|
| committer | Brian Jordan | 2012-03-27 20:54:10 -0400 |
| commit | 9ac7c867baf16a6cf1992956891e7a61503edb89 (patch) | |
| tree | 4106f42d62aebee25042a6df49bb89117a55059f | |
| parent | f1d5f1118a540bfc8ffe71be788fc355e75ad1a9 (diff) | |
| download | Video-Tuneup-9ac7c867baf16a6cf1992956891e7a61503edb89.tar.bz2 | |
video loading
| -rw-r--r-- | Video Tuneup.xcodeproj/project.pbxproj | 46 | ||||
| -rw-r--r-- | Video Tuneup/Classes/Views/PlayerView.h | 16 | ||||
| -rw-r--r-- | Video Tuneup/Classes/Views/PlayerView.m | 24 | ||||
| -rw-r--r-- | Video Tuneup/ViewController.h | 15 | ||||
| -rw-r--r-- | Video Tuneup/ViewController.m | 115 | ||||
| -rw-r--r-- | Video Tuneup/airplane.m4v | bin | 0 -> 2299207 bytes | |||
| -rw-r--r-- | Video Tuneup/en.lproj/ViewController_iPad.xib | 106 |
7 files changed, 311 insertions, 11 deletions
diff --git a/Video Tuneup.xcodeproj/project.pbxproj b/Video Tuneup.xcodeproj/project.pbxproj index 3538124..19d8695 100644 --- a/Video Tuneup.xcodeproj/project.pbxproj +++ b/Video Tuneup.xcodeproj/project.pbxproj @@ -21,6 +21,10 @@ D36CCD5915227D06003CCAFC /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D36CCD3715227D06003CCAFC /* Foundation.framework */; }; D36CCD6115227D06003CCAFC /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = D36CCD5F15227D06003CCAFC /* InfoPlist.strings */; }; D36CCD6415227D06003CCAFC /* Video_TuneupTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D36CCD6315227D06003CCAFC /* Video_TuneupTests.m */; }; + D36CCD6E15228700003CCAFC /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D36CCD6D15228700003CCAFC /* AVFoundation.framework */; }; + D36CCD7115228952003CCAFC /* airplane.m4v in Resources */ = {isa = PBXBuildFile; fileRef = D36CCD7015228952003CCAFC /* airplane.m4v */; }; + D36CCD7415228ACE003CCAFC /* PlayerView.m in Sources */ = {isa = PBXBuildFile; fileRef = D36CCD7315228ACE003CCAFC /* PlayerView.m */; }; + D36CCD781522920D003CCAFC /* CoreMedia.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D36CCD771522920D003CCAFC /* CoreMedia.framework */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -54,6 +58,11 @@ D36CCD6015227D06003CCAFC /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; }; D36CCD6215227D06003CCAFC /* Video_TuneupTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Video_TuneupTests.h; sourceTree = "<group>"; }; D36CCD6315227D06003CCAFC /* Video_TuneupTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Video_TuneupTests.m; sourceTree = "<group>"; }; + D36CCD6D15228700003CCAFC /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; }; + D36CCD7015228952003CCAFC /* airplane.m4v */ = {isa = PBXFileReference; lastKnownFileType = file; path = airplane.m4v; sourceTree = "<group>"; }; + D36CCD7215228ACE003CCAFC /* PlayerView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PlayerView.h; path = Classes/Views/PlayerView.h; sourceTree = "<group>"; }; + D36CCD7315228ACE003CCAFC /* PlayerView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = PlayerView.m; path = Classes/Views/PlayerView.m; sourceTree = "<group>"; }; + D36CCD771522920D003CCAFC /* CoreMedia.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreMedia.framework; path = System/Library/Frameworks/CoreMedia.framework; sourceTree = SDKROOT; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -61,6 +70,8 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + D36CCD781522920D003CCAFC /* CoreMedia.framework in Frameworks */, + D36CCD6E15228700003CCAFC /* AVFoundation.framework in Frameworks */, D36CCD3615227D06003CCAFC /* UIKit.framework in Frameworks */, D36CCD3815227D06003CCAFC /* Foundation.framework in Frameworks */, D36CCD3A15227D06003CCAFC /* CoreGraphics.framework in Frameworks */, @@ -83,6 +94,8 @@ D36CCD2615227D05003CCAFC = { isa = PBXGroup; children = ( + D36CCD771522920D003CCAFC /* CoreMedia.framework */, + D36CCD6D15228700003CCAFC /* AVFoundation.framework */, D36CCD3B15227D06003CCAFC /* Video Tuneup */, D36CCD5C15227D06003CCAFC /* Video TuneupTests */, D36CCD3415227D06003CCAFC /* Frameworks */, @@ -113,10 +126,11 @@ D36CCD3B15227D06003CCAFC /* Video Tuneup */ = { isa = PBXGroup; children = ( + D36CCD6F1522893F003CCAFC /* Resources */, D36CCD4415227D06003CCAFC /* AppDelegate.h */, D36CCD4515227D06003CCAFC /* AppDelegate.m */, - D36CCD4715227D06003CCAFC /* ViewController.h */, - D36CCD4815227D06003CCAFC /* ViewController.m */, + D36CCD7615228B04003CCAFC /* Controllers */, + D36CCD7515228ADC003CCAFC /* Views */, D36CCD4A15227D06003CCAFC /* ViewController_iPhone.xib */, D36CCD4D15227D06003CCAFC /* ViewController_iPad.xib */, D36CCD3C15227D06003CCAFC /* Supporting Files */, @@ -154,6 +168,32 @@ name = "Supporting Files"; sourceTree = "<group>"; }; + D36CCD6F1522893F003CCAFC /* Resources */ = { + isa = PBXGroup; + children = ( + D36CCD7015228952003CCAFC /* airplane.m4v */, + ); + name = Resources; + sourceTree = "<group>"; + }; + D36CCD7515228ADC003CCAFC /* Views */ = { + isa = PBXGroup; + children = ( + D36CCD7215228ACE003CCAFC /* PlayerView.h */, + D36CCD7315228ACE003CCAFC /* PlayerView.m */, + ); + name = Views; + sourceTree = "<group>"; + }; + D36CCD7615228B04003CCAFC /* Controllers */ = { + isa = PBXGroup; + children = ( + D36CCD4715227D06003CCAFC /* ViewController.h */, + D36CCD4815227D06003CCAFC /* ViewController.m */, + ); + name = Controllers; + sourceTree = "<group>"; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -227,6 +267,7 @@ D36CCD4015227D06003CCAFC /* InfoPlist.strings in Resources */, D36CCD4C15227D06003CCAFC /* ViewController_iPhone.xib in Resources */, D36CCD4F15227D06003CCAFC /* ViewController_iPad.xib in Resources */, + D36CCD7115228952003CCAFC /* airplane.m4v in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -264,6 +305,7 @@ D36CCD4215227D06003CCAFC /* main.m in Sources */, D36CCD4615227D06003CCAFC /* AppDelegate.m in Sources */, D36CCD4915227D06003CCAFC /* ViewController.m in Sources */, + D36CCD7415228ACE003CCAFC /* PlayerView.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Video Tuneup/Classes/Views/PlayerView.h b/Video Tuneup/Classes/Views/PlayerView.h new file mode 100644 index 0000000..61f34eb --- /dev/null +++ b/Video Tuneup/Classes/Views/PlayerView.h @@ -0,0 +1,16 @@ +// +// PlayerView.h +// Video Tuneup +// +// Created by Brian Jordan on 3/27/12. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#import <UIKit/UIKit.h> +#import <AVFoundation/AVFoundation.h> + +@interface PlayerView : UIView { +} + +@property (nonatomic, retain) AVPlayer *player; +@end diff --git a/Video Tuneup/Classes/Views/PlayerView.m b/Video Tuneup/Classes/Views/PlayerView.m new file mode 100644 index 0000000..b9d5c34 --- /dev/null +++ b/Video Tuneup/Classes/Views/PlayerView.m @@ -0,0 +1,24 @@ +// +// PlayerView.m +// Video Tuneup +// +// Created by Brian Jordan on 3/27/12. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#import "PlayerView.h" + +@implementation PlayerView + ++ (Class)layerClass { + return [AVPlayerLayer class]; +} + +- (AVPlayer*)player { + return [(AVPlayerLayer *)[self layer] player]; +} + +- (void)setPlayer:(AVPlayer *)player { + [(AVPlayerLayer *)[self layer] setPlayer:player]; +} +@end
\ No newline at end of file diff --git a/Video Tuneup/ViewController.h b/Video Tuneup/ViewController.h index 2bb4491..9a39837 100644 --- a/Video Tuneup/ViewController.h +++ b/Video Tuneup/ViewController.h @@ -7,7 +7,18 @@ // #import <UIKit/UIKit.h> +#import <AVFoundation/AVFoundation.h> -@interface ViewController : UIViewController +@class PlayerView; -@end +@interface ViewController : UIViewController { +} + +@property (nonatomic, retain) AVPlayer *player; +@property (retain) AVPlayerItem *playerItem; +@property (nonatomic, retain) IBOutlet PlayerView *playerView; +@property (nonatomic, retain) IBOutlet UIButton *playButton; +- (IBAction)loadAssetFromFile:sender; +- (IBAction)play:sender; +- (void)syncUI; +@end
\ No newline at end of file diff --git a/Video Tuneup/ViewController.m b/Video Tuneup/ViewController.m index 5625a9b..200553f 100644 --- a/Video Tuneup/ViewController.m +++ b/Video Tuneup/ViewController.m @@ -7,9 +7,99 @@ // #import "ViewController.h" +#import "PlayerView.h" + +// Define this constant for the key-value observation context. +static const NSString *ItemStatusContext; @implementation ViewController +@synthesize player, playerItem, playerView, playButton; + +#pragma mark - Video playback + +- (void)syncUI { + if ((player.currentItem != nil) && + ([player.currentItem status] == AVPlayerItemStatusReadyToPlay)) { + playButton.enabled = YES; + } + else { + playButton.enabled = NO; + } +} + +- (IBAction)loadAssetFromFile:sender { + + NSLog(@"Loading asset."); + + NSURL *fileURL = [[NSBundle mainBundle] + URLForResource:@"airplane" withExtension:@"m4v"]; + + AVURLAsset *asset = [AVURLAsset URLAssetWithURL:fileURL options:nil]; + + NSLog(@"Asset duration is %f", CMTimeGetSeconds([asset duration])); + + NSString *tracksKey = @"tracks"; + + [asset loadValuesAsynchronouslyForKeys:[NSArray arrayWithObject:tracksKey] completionHandler: + ^{ + NSLog(@"Handler block reached"); + // Completion handler block. + dispatch_async(dispatch_get_main_queue(), + ^{ + NSError *error = nil; + AVKeyValueStatus status = [asset statusOfValueForKey:tracksKey error:&error]; + + if (status == AVKeyValueStatusLoaded) { + self.playerItem = [AVPlayerItem playerItemWithAsset:asset]; + [playerItem addObserver:self forKeyPath:@"status" + options:0 context:&ItemStatusContext]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(playerItemDidReachEnd:) + name:AVPlayerItemDidPlayToEndTimeNotification + object:playerItem]; + self.player = [AVPlayer playerWithPlayerItem:playerItem]; + [playerView setPlayer:player]; + + // File has loaded into player + NSLog(@"File loaded!"); + NSLog(@"Asset duration is %f", CMTimeGetSeconds([asset duration])); + } + else { + // You should deal with the error appropriately. + NSLog(@"The asset's tracks were not loaded:\n%@", [error localizedDescription]); + } + }); + }]; +} + +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object + change:(NSDictionary *)change context:(void *)context { + + if (context == &ItemStatusContext) { + // Have to dispatch to main thread queue for UI operations + dispatch_async(dispatch_get_main_queue(), + ^{ + [self syncUI]; + }); + return; + } + [super observeValueForKeyPath:keyPath ofObject:object + change:change context:context]; + return; +} + +- (IBAction)play:sender { + [player play]; +} + +- (void)playerItemDidReachEnd:(NSNotification *)notification { + [player seekToTime:kCMTimeZero]; +} + + +#pragma mark - View controller boilerplate + - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; @@ -21,7 +111,32 @@ - (void)viewDidLoad { [super viewDidLoad]; + [self syncUI]; + + // Register with the notification center after creating the player item. + [[NSNotificationCenter defaultCenter] + addObserver:self + selector:@selector(playerItemDidReachEnd:) + name:AVPlayerItemDidPlayToEndTimeNotification + object:[player currentItem]]; + + // Do any additional setup after loading the view, typically from a nib. + // http://mobileorchard.com/easy-audio-playback-with-avaudioplayer/ + +// NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/airplane.m4v", [[NSBundle mainBundle] resourcePath]]]; + // http://developer.apple.com/library/ios/#DOCUMENTATION/AudioVideo/Conceptual/AVFoundationPG/Articles/02_Playback.html#//apple_ref/doc/uid/TP40010188-CH3-SW2 + + // Create an asset using AVURLAsset and load its tracks using loadValuesAsynchronouslyForKeys:completionHandler:. + // When the asset has loaded its tracks, create an instance of AVPlayerItem using the asset. + // Associate the item with an instance of AVPlayer. + // Wait until the item’s status indicates that it’s ready to play (typically you use key-value observing to receive a notification when the status changes). + + // Put video in supporting files + + // Get URL of video + + // Load video into player? } - (void)viewDidUnload diff --git a/Video Tuneup/airplane.m4v b/Video Tuneup/airplane.m4v Binary files differnew file mode 100644 index 0000000..eaea179 --- /dev/null +++ b/Video Tuneup/airplane.m4v diff --git a/Video Tuneup/en.lproj/ViewController_iPad.xib b/Video Tuneup/en.lproj/ViewController_iPad.xib index cd02abe..f7faef1 100644 --- a/Video Tuneup/en.lproj/ViewController_iPad.xib +++ b/Video Tuneup/en.lproj/ViewController_iPad.xib @@ -2,17 +2,18 @@ <archive type="com.apple.InterfaceBuilder3.CocoaTouch.iPad.XIB" version="8.00"> <data> <int key="IBDocument.SystemTarget">1280</int> - <string key="IBDocument.SystemVersion">11C25</string> - <string key="IBDocument.InterfaceBuilderVersion">1919</string> - <string key="IBDocument.AppKitVersion">1138.11</string> - <string key="IBDocument.HIToolboxVersion">566.00</string> + <string key="IBDocument.SystemVersion">11C74</string> + <string key="IBDocument.InterfaceBuilderVersion">1938</string> + <string key="IBDocument.AppKitVersion">1138.23</string> + <string key="IBDocument.HIToolboxVersion">567.00</string> <object class="NSMutableDictionary" key="IBDocument.PluginVersions"> <string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string> - <string key="NS.object.0">916</string> + <string key="NS.object.0">933</string> </object> <array key="IBDocument.IntegratedClassDependencies"> <string>IBProxyObject</string> <string>IBUIView</string> + <string>IBUIButton</string> </array> <array key="IBDocument.PluginDependencies"> <string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string> @@ -33,6 +34,43 @@ <object class="IBUIView" id="766721923"> <reference key="NSNextResponder"/> <int key="NSvFlags">274</int> + <array class="NSMutableArray" key="NSSubviews"> + <object class="IBUIButton" id="146808167"> + <reference key="NSNextResponder" ref="766721923"/> + <int key="NSvFlags">319</int> + <string key="NSFrame">{{172, 191}, {403, 84}}</string> + <reference key="NSSuperview" ref="766721923"/> + <reference key="NSWindow"/> + <string key="NSReuseIdentifierKey">_NS:241</string> + <bool key="IBUIOpaque">NO</bool> + <string key="targetRuntimeIdentifier">IBIPadFramework</string> + <int key="IBUIContentHorizontalAlignment">0</int> + <int key="IBUIContentVerticalAlignment">0</int> + <int key="IBUIButtonType">1</int> + <string key="IBUINormalTitle">Open Movie</string> + <object class="NSColor" key="IBUIHighlightedTitleColor"> + <int key="NSColorSpace">3</int> + <bytes key="NSWhite">MQA</bytes> + </object> + <object class="NSColor" key="IBUINormalTitleColor"> + <int key="NSColorSpace">1</int> + <bytes key="NSRGB">MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA</bytes> + </object> + <object class="NSColor" key="IBUINormalTitleShadowColor"> + <int key="NSColorSpace">3</int> + <bytes key="NSWhite">MC41AA</bytes> + </object> + <object class="IBUIFontDescription" key="IBUIFontDescription"> + <int key="type">2</int> + <double key="pointSize">15</double> + </object> + <object class="NSFont" key="IBUIFont"> + <string key="NSName">Helvetica-Bold</string> + <double key="NSSize">15</double> + <int key="NSfFlags">16</int> + </object> + </object> + </array> <string key="NSFrame">{{0, 20}, {768, 1004}}</string> <reference key="NSSuperview"/> <reference key="NSWindow"/> @@ -59,6 +97,15 @@ </object> <int key="connectionID">3</int> </object> + <object class="IBConnectionRecord"> + <object class="IBCocoaTouchEventConnection" key="connection"> + <string key="label">loadAssetFromFile:</string> + <reference key="source" ref="146808167"/> + <reference key="destination" ref="841351856"/> + <int key="IBEventType">3</int> + </object> + <int key="connectionID">5</int> + </object> </array> <object class="IBMutableOrderedSet" key="objectRecords"> <array key="orderedObjects"> @@ -82,8 +129,16 @@ <object class="IBObjectRecord"> <int key="objectID">2</int> <reference key="object" ref="766721923"/> + <array class="NSMutableArray" key="children"> + <reference ref="146808167"/> + </array> <reference key="parent" ref="0"/> </object> + <object class="IBObjectRecord"> + <int key="objectID">4</int> + <reference key="object" ref="146808167"/> + <reference key="parent" ref="766721923"/> + </object> </array> </object> <dictionary class="NSMutableDictionary" key="flattenedProperties"> @@ -92,18 +147,55 @@ <string key="-2.CustomClassName">UIResponder</string> <string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string> <string key="2.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string> + <string key="4.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string> </dictionary> <dictionary class="NSMutableDictionary" key="unlocalizedProperties"/> <nil key="activeLocalization"/> <dictionary class="NSMutableDictionary" key="localizations"/> <nil key="sourceID"/> - <int key="maxID">3</int> + <int key="maxID">5</int> </object> <object class="IBClassDescriber" key="IBDocument.Classes"> <array class="NSMutableArray" key="referencedPartialClassDescriptions"> <object class="IBPartialClassDescription"> + <string key="className">PlayerView</string> + <string key="superclassName">UIView</string> + <object class="IBClassDescriptionSource" key="sourceIdentifier"> + <string key="majorKey">IBProjectSource</string> + <string key="minorKey">./Classes/PlayerView.h</string> + </object> + </object> + <object class="IBPartialClassDescription"> <string key="className">ViewController</string> <string key="superclassName">UIViewController</string> + <dictionary class="NSMutableDictionary" key="actions"> + <string key="loadAssetFromFile:">id</string> + <string key="play:">id</string> + </dictionary> + <dictionary class="NSMutableDictionary" key="actionInfosByName"> + <object class="IBActionInfo" key="loadAssetFromFile:"> + <string key="name">loadAssetFromFile:</string> + <string key="candidateClassName">id</string> + </object> + <object class="IBActionInfo" key="play:"> + <string key="name">play:</string> + <string key="candidateClassName">id</string> + </object> + </dictionary> + <dictionary class="NSMutableDictionary" key="outlets"> + <string key="playButton">UIButton</string> + <string key="playerView">PlayerView</string> + </dictionary> + <dictionary class="NSMutableDictionary" key="toOneOutletInfosByName"> + <object class="IBToOneOutletInfo" key="playButton"> + <string key="name">playButton</string> + <string key="candidateClassName">UIButton</string> + </object> + <object class="IBToOneOutletInfo" key="playerView"> + <string key="name">playerView</string> + <string key="candidateClassName">PlayerView</string> + </object> + </dictionary> <object class="IBClassDescriptionSource" key="sourceIdentifier"> <string key="majorKey">IBProjectSource</string> <string key="minorKey">./Classes/ViewController.h</string> @@ -115,6 +207,6 @@ <string key="IBDocument.TargetRuntimeIdentifier">IBIPadFramework</string> <bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool> <int key="IBDocument.defaultPropertyAccessControl">3</int> - <string key="IBCocoaTouchPluginVersion">916</string> + <string key="IBCocoaTouchPluginVersion">933</string> </data> </archive> |
