2 // MediaViewController.m
5 // Created by Mike Mayo on 1/8/11.
6 // Copyright 2011 __MyCompanyName__. All rights reserved.
9 #import "MediaViewController.h"
11 #import "StorageObject.h"
14 @implementation MediaViewController
16 @synthesize object, container;
21 self.navigationItem.title = object.name;
23 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
24 NSString *documentsDirectory = [paths objectAtIndex:0];
25 NSString *shortPath = [NSString stringWithFormat:@"/%@/%@", self.container.name, self.object.fullPath];
26 NSString *filePath = [documentsDirectory stringByAppendingString:shortPath];
27 NSURL *url = [NSURL fileURLWithPath:filePath];
29 player = [[MPMoviePlayerController alloc] initWithContentURL:url];
30 [[player view] setFrame:[self.view bounds]]; // frame must match parent view
32 // private API, not App Store safe
33 // if ([player respondsToSelector:@selector(setAllowsWirelessPlayback:)]) {
34 // [player performSelector:@selector(setAllowsWirelessPlayback:) withObject:[NSNumber numberWithBool:YES]];
37 // public way that's App Store safe, works in iOS 4.3+
38 if ([player respondsToSelector:@selector(setAllowsAirPlay:)]) {
39 [player performSelector:@selector(setAllowsAirPlay:) withObject:[NSNumber numberWithBool:YES]];
42 [self.view addSubview:[player view]];
43 //player.fullscreen = YES;
44 //player.controlStyle = MPMovieControlStyleFullscreen;
46 observer = [[NSNotificationCenter defaultCenter] addObserverForName:MPMoviePlayerPlaybackDidFinishNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification* notification)
48 player.initialPlaybackTime = -1;
50 //[self.navigationController popViewControllerAnimated:NO];
51 [[NSNotificationCenter defaultCenter] removeObserver:observer];
54 self.view = player.view;
59 - (void)viewWillDisappear:(BOOL)animated {
63 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {