--
Emily
You received this message because you are subscribed to the Google Groups "Brighton iPhone Creators" group.
To post to this group, send email to brighton-iph...@googlegroups.com.
To unsubscribe from this group, send email to brighton-iphone-cr...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/brighton-iphone-creators?hl=en.
@implementation TEAnimationPlayerView
+ (Class)layerClass {
return [AVPlayerLayer class];
}
- (AVPlayer*)player {
return [(AVPlayerLayer *)[self layer] player];
}
- (void)setPlayer:(AVPlayer *)player {
[(AVPlayerLayer *)[self layer] setPlayer:player];
}
@end
Then I'm adding the video .mov and playing
- (void)loadAssetFromFile:sender {
NSURL *fileURL = [[NSBundle mainBundle]
URLForResource:@"Page1_V02" withExtension:@"mov"];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:fileURL options:nil];
NSString *tracksKey = @"tracks";
[asset loadValuesAsynchronouslyForKeys:[NSArray arrayWithObject:tracksKey] completionHandler:
^{
// 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];
for(AVAssetTrack *track in playerItem.asset.tracks)
{
if([track.mediaType isEqualToString:AVMediaTypeAudio])
{
NSLog(@"I need to switch this off %@", track.mediaType);
}
}
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:playerItem];
self.player = [AVPlayer playerWithPlayerItem:playerItem];
[playerView setPlayer:player];
}
else {
NSLog(@"The asset's tracks were not loaded:\n%@", [error localizedDescription]);
}
});
}];
}
Then initialise the player view and add it to my viewplayerView = [[TEAnimationPlayerView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
[self.view addSubview:playerView];
[self loadAssetFromFile:sender];
--