Skip to content

Commit 653c7e0

Browse files
committed
working lib
1 parent 9d0c382 commit 653c7e0

11 files changed

+234
-21
lines changed

Default-Portrait~ipad.png

46.6 KB
Loading

XOSplash.xcodeproj/project.pbxproj

+35-9
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,31 @@
1515
083276D51579D1A500E68689 /* XOAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 083276D41579D1A500E68689 /* XOAppDelegate.m */; };
1616
083276D81579D1A500E68689 /* XOViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 083276D71579D1A500E68689 /* XOViewController.m */; };
1717
083276DB1579D1A500E68689 /* XOViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 083276D91579D1A500E68689 /* XOViewController.xib */; };
18+
083276E31579D2BF00E68689 /* splash.mp4 in Resources */ = {isa = PBXBuildFile; fileRef = 083276E21579D2BF00E68689 /* splash.mp4 */; };
19+
083276E51579D33900E68689 /* MediaPlayer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 083276E41579D33900E68689 /* MediaPlayer.framework */; };
20+
083276E81579D3CD00E68689 /* XOSplashVideoController.m in Sources */ = {isa = PBXBuildFile; fileRef = 083276E71579D3CD00E68689 /* XOSplashVideoController.m */; };
21+
083276F0157A550500E68689 /* Default-Portrait~ipad.png in Resources */ = {isa = PBXBuildFile; fileRef = 083276EF157A550500E68689 /* Default-Portrait~ipad.png */; };
1822
/* End PBXBuildFile section */
1923

2024
/* Begin PBXFileReference section */
2125
083276C01579D1A500E68689 /* XOSplash.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = XOSplash.app; sourceTree = BUILT_PRODUCTS_DIR; };
2226
083276C41579D1A500E68689 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
2327
083276C61579D1A500E68689 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
2428
083276C81579D1A500E68689 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
25-
083276CC1579D1A500E68689 /* XOSplash-Info.plist */ = {isa = PBXFileReference; path = "XOSplash-Info.plist"; sourceTree = "<group>"; };
29+
083276CC1579D1A500E68689 /* XOSplash-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "XOSplash-Info.plist"; sourceTree = "<group>"; };
2630
083276CE1579D1A500E68689 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
2731
083276D01579D1A500E68689 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
28-
083276D21579D1A500E68689 /* XOSplash-Prefix.pch */ = {isa = PBXFileReference; path = "XOSplash-Prefix.pch"; sourceTree = "<group>"; };
29-
083276D31579D1A500E68689 /* XOAppDelegate.h */ = {isa = PBXFileReference; path = XOAppDelegate.h; sourceTree = "<group>"; };
32+
083276D21579D1A500E68689 /* XOSplash-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "XOSplash-Prefix.pch"; sourceTree = "<group>"; };
33+
083276D31579D1A500E68689 /* XOAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XOAppDelegate.h; sourceTree = "<group>"; };
3034
083276D41579D1A500E68689 /* XOAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XOAppDelegate.m; sourceTree = "<group>"; };
31-
083276D61579D1A500E68689 /* XOViewController.h */ = {isa = PBXFileReference; path = XOViewController.h; sourceTree = "<group>"; };
35+
083276D61579D1A500E68689 /* XOViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XOViewController.h; sourceTree = "<group>"; };
3236
083276D71579D1A500E68689 /* XOViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XOViewController.m; sourceTree = "<group>"; };
3337
083276DA1579D1A500E68689 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/XOViewController.xib; sourceTree = "<group>"; };
38+
083276E21579D2BF00E68689 /* splash.mp4 */ = {isa = PBXFileReference; lastKnownFileType = file; name = splash.mp4; path = Resources/splash.mp4; sourceTree = "<group>"; };
39+
083276E41579D33900E68689 /* MediaPlayer.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MediaPlayer.framework; path = System/Library/Frameworks/MediaPlayer.framework; sourceTree = SDKROOT; };
40+
083276E61579D3CD00E68689 /* XOSplashVideoController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XOSplashVideoController.h; sourceTree = "<group>"; };
41+
083276E71579D3CD00E68689 /* XOSplashVideoController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XOSplashVideoController.m; sourceTree = "<group>"; };
42+
083276EF157A550500E68689 /* Default-Portrait~ipad.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-Portrait~ipad.png"; sourceTree = "<group>"; };
3443
/* End PBXFileReference section */
3544

3645
/* Begin PBXFrameworksBuildPhase section */
@@ -41,6 +50,7 @@
4150
083276C51579D1A500E68689 /* UIKit.framework in Frameworks */,
4251
083276C71579D1A500E68689 /* Foundation.framework in Frameworks */,
4352
083276C91579D1A500E68689 /* CoreGraphics.framework in Frameworks */,
53+
083276E51579D33900E68689 /* MediaPlayer.framework in Frameworks */,
4454
);
4555
runOnlyForDeploymentPostprocessing = 0;
4656
};
@@ -50,6 +60,7 @@
5060
083276B51579D1A500E68689 = {
5161
isa = PBXGroup;
5262
children = (
63+
083276EF157A550500E68689 /* Default-Portrait~ipad.png */,
5364
083276CA1579D1A500E68689 /* XOSplash */,
5465
083276C31579D1A500E68689 /* Frameworks */,
5566
083276C11579D1A500E68689 /* Products */,
@@ -67,37 +78,49 @@
6778
083276C31579D1A500E68689 /* Frameworks */ = {
6879
isa = PBXGroup;
6980
children = (
70-
083276C41579D1A500E68689 /* UIKit.framework */,
71-
083276C61579D1A500E68689 /* Foundation.framework */,
7281
083276C81579D1A500E68689 /* CoreGraphics.framework */,
82+
083276C61579D1A500E68689 /* Foundation.framework */,
83+
083276E41579D33900E68689 /* MediaPlayer.framework */,
84+
083276C41579D1A500E68689 /* UIKit.framework */,
7385
);
7486
name = Frameworks;
7587
sourceTree = "<group>";
7688
};
7789
083276CA1579D1A500E68689 /* XOSplash */ = {
7890
isa = PBXGroup;
7991
children = (
92+
083276E11579D22000E68689 /* Resources */,
93+
083276CB1579D1A500E68689 /* Supporting Files */,
8094
083276D31579D1A500E68689 /* XOAppDelegate.h */,
8195
083276D41579D1A500E68689 /* XOAppDelegate.m */,
96+
083276E61579D3CD00E68689 /* XOSplashVideoController.h */,
97+
083276E71579D3CD00E68689 /* XOSplashVideoController.m */,
8298
083276D61579D1A500E68689 /* XOViewController.h */,
8399
083276D71579D1A500E68689 /* XOViewController.m */,
84100
083276D91579D1A500E68689 /* XOViewController.xib */,
85-
083276CB1579D1A500E68689 /* Supporting Files */,
86101
);
87102
path = XOSplash;
88103
sourceTree = "<group>";
89104
};
90105
083276CB1579D1A500E68689 /* Supporting Files */ = {
91106
isa = PBXGroup;
92107
children = (
93-
083276CC1579D1A500E68689 /* XOSplash-Info.plist */,
94108
083276CD1579D1A500E68689 /* InfoPlist.strings */,
95109
083276D01579D1A500E68689 /* main.m */,
110+
083276CC1579D1A500E68689 /* XOSplash-Info.plist */,
96111
083276D21579D1A500E68689 /* XOSplash-Prefix.pch */,
97112
);
98113
name = "Supporting Files";
99114
sourceTree = "<group>";
100115
};
116+
083276E11579D22000E68689 /* Resources */ = {
117+
isa = PBXGroup;
118+
children = (
119+
083276E21579D2BF00E68689 /* splash.mp4 */,
120+
);
121+
name = Resources;
122+
sourceTree = "<group>";
123+
};
101124
/* End PBXGroup section */
102125

103126
/* Begin PBXNativeTarget section */
@@ -126,7 +149,7 @@
126149
attributes = {
127150
CLASSPREFIX = XO;
128151
LastUpgradeCheck = 0430;
129-
ORGANIZATIONNAME = Madefire;
152+
ORGANIZATIONNAME = RossMcFarland;
130153
};
131154
buildConfigurationList = 083276BA1579D1A500E68689 /* Build configuration list for PBXProject "XOSplash" */;
132155
compatibilityVersion = "Xcode 3.2";
@@ -152,6 +175,8 @@
152175
files = (
153176
083276CF1579D1A500E68689 /* InfoPlist.strings in Resources */,
154177
083276DB1579D1A500E68689 /* XOViewController.xib in Resources */,
178+
083276E31579D2BF00E68689 /* splash.mp4 in Resources */,
179+
083276F0157A550500E68689 /* Default-Portrait~ipad.png in Resources */,
155180
);
156181
runOnlyForDeploymentPostprocessing = 0;
157182
};
@@ -165,6 +190,7 @@
165190
083276D11579D1A500E68689 /* main.m in Sources */,
166191
083276D51579D1A500E68689 /* XOAppDelegate.m in Sources */,
167192
083276D81579D1A500E68689 /* XOViewController.m in Sources */,
193+
083276E81579D3CD00E68689 /* XOSplashVideoController.m in Sources */,
168194
);
169195
runOnlyForDeploymentPostprocessing = 0;
170196
};

XOSplash/Resources/splash.mp4

44.6 KB
Binary file not shown.

XOSplash/XOAppDelegate.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
// XOSplash
44
//
55
// Created by Ross McFarland on 6/1/12.
6-
// Copyright (c) 2012 Madefire. All rights reserved.
6+
// Copyright (c) 2012 Ross McFarland. All rights reserved.
77
//
88

99
#import <UIKit/UIKit.h>
10+
#import "XOSplashVideoController.h"
1011

1112
@class XOViewController;
1213

13-
@interface XOAppDelegate : UIResponder <UIApplicationDelegate>
14+
@interface XOAppDelegate : UIResponder <UIApplicationDelegate, XOSplashVideoDelegate>
1415

1516
@property (strong, nonatomic) UIWindow *window;
1617

XOSplash/XOAppDelegate.m

+26-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
// XOSplash
44
//
55
// Created by Ross McFarland on 6/1/12.
6-
// Copyright (c) 2012 Madefire. All rights reserved.
6+
// Copyright (c) 2012 Ross McFarland. All rights reserved.
77
//
88

99
#import "XOAppDelegate.h"
1010

1111
#import "XOViewController.h"
12+
#import "XOSplashVideoController.h"
1213

1314
@implementation XOAppDelegate
1415

@@ -18,13 +19,34 @@ @implementation XOAppDelegate
1819
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
1920
{
2021
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
21-
// Override point for customization after application launch.
22-
self.viewController = [[XOViewController alloc] initWithNibName:@"XOViewController" bundle:nil];
23-
self.window.rootViewController = self.viewController;
22+
23+
// our video
24+
NSURL *url = [[NSBundle mainBundle] URLForResource:@"splash" withExtension:@"mp4"];
25+
// our splash controller
26+
XOSplashVideoController *splashVideoController =
27+
[[XOSplashVideoController alloc] initWithVideoURL:url
28+
imageName:@"Default-Portrait~ipad.png"
29+
delegate:self];
30+
// we'll start out with the spash view controller in the window
31+
self.window.rootViewController = splashVideoController;
32+
2433
[self.window makeKeyAndVisible];
2534
return YES;
2635
}
2736

37+
- (void)splashVideoLoaded:(XOSplashVideoController *)splashVideo
38+
{
39+
// load up our real view controller, but don't put it in to the window until the video is done
40+
// if there's anything expensive to do it should happen in the background now
41+
self.viewController = [[XOViewController alloc] initWithNibName:@"XOViewController" bundle:nil];
42+
}
43+
44+
- (void)splashVideoComplete:(XOSplashVideoController *)splashVideo
45+
{
46+
// swap out the splash controller for our app's
47+
self.window.rootViewController = self.viewController;
48+
}
49+
2850
- (void)applicationWillResignActive:(UIApplication *)application
2951
{
3052
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.

XOSplash/XOSplash-Info.plist

+10-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@
88
<string>${PRODUCT_NAME}</string>
99
<key>CFBundleExecutable</key>
1010
<string>${EXECUTABLE_NAME}</string>
11+
<key>CFBundleIcons</key>
12+
<dict>
13+
<key>CFBundlePrimaryIcon</key>
14+
<dict>
15+
<key>CFBundleIconFiles</key>
16+
<array>
17+
<string>Default-Portrait~ipad.png</string>
18+
</array>
19+
</dict>
20+
</dict>
1121
<key>CFBundleIdentifier</key>
1222
<string>com.xormedia.${PRODUCT_NAME:rfc1034identifier}</string>
1323
<key>CFBundleInfoDictionaryVersion</key>
@@ -31,9 +41,6 @@
3141
<key>UISupportedInterfaceOrientations~ipad</key>
3242
<array>
3343
<string>UIInterfaceOrientationPortrait</string>
34-
<string>UIInterfaceOrientationPortraitUpsideDown</string>
35-
<string>UIInterfaceOrientationLandscapeLeft</string>
36-
<string>UIInterfaceOrientationLandscapeRight</string>
3744
</array>
3845
</dict>
3946
</plist>

XOSplash/XOSplashVideoController.h

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//
2+
// XOSplashVideoPlayer.h
3+
// XOSplash
4+
//
5+
// Created by Ross McFarland on 6/1/12.
6+
// Copyright (c) 2012 Ross McFarland. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
@class XOSplashVideoController;
12+
13+
@protocol XOSplashVideoDelegate <NSObject>
14+
15+
@required
16+
17+
/** Called when the splash video has finished playing, the point at
18+
* which the video controller should be swapped out for the
19+
* application's own (window.rootViewController) */
20+
- (void)splashVideoComplete:(XOSplashVideoController *)splashVideo;
21+
22+
@optional
23+
24+
/** Called when the splash video has completed loading and is about
25+
* to play. Applications should avoid doing any "work" before this
26+
* call so that the splash image will switch to the splash video as
27+
* quickly as possible. Once this call is made the application should
28+
* begin doing any heavy lifting (likely in a background thread)
29+
* while the video plays. In the ideal case the work would be done
30+
* by the time the complete call is made. */
31+
- (void)splashVideoLoaded:(XOSplashVideoController *)splashVideo;
32+
33+
@end
34+
35+
@interface XOSplashVideoController : UIViewController
36+
37+
@property (nonatomic, strong) NSObject<XOSplashVideoDelegate> * delegate;
38+
39+
/** Create a splash player, normally called in
40+
* application:didLoadWithOptions and assigned to
41+
* window.rootViewController. The video url and image name should
42+
* be appropriate for the current device and orientation. The video
43+
* needs to match the screen's resolution and the image should
44+
* be one of the ones configured in the target summary, the
45+
* one that matches the current device and orientation. */
46+
- (id)initWithVideoURL:(NSURL *)url
47+
imageName:(NSString *)imageName
48+
delegate:(NSObject<XOSplashVideoDelegate> *)delegate;
49+
50+
@end

XOSplash/XOSplashVideoController.m

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
//
2+
// XOSplashVideoPlayer.m
3+
// XOSplash
4+
//
5+
// Created by Ross McFarland on 6/1/12.
6+
// Copyright (c) 2012 Ross McFarland. All rights reserved.
7+
//
8+
9+
#import "XOSplashVideoController.h"
10+
#import <MediaPlayer/MediaPlayer.h>
11+
12+
@implementation XOSplashVideoController {
13+
MPMoviePlayerController *_player;
14+
UIImageView *_backgroundImageView;
15+
}
16+
17+
@synthesize delegate = _delegate;
18+
19+
- (id)initWithVideoURL:(NSURL *)url
20+
imageName:(NSString *)imageName
21+
delegate:(NSObject<XOSplashVideoDelegate> *)delegate;
22+
{
23+
self = [super init];
24+
if (self) {
25+
_delegate = delegate;
26+
27+
CGRect frame = [[UIScreen mainScreen] bounds];
28+
UIWindow *window = [UIApplication sharedApplication].delegate.window;
29+
30+
// put a background image in the window, so that it'll show as soon as the splash
31+
// goes away, this fixes most of the black flash
32+
UIImage *image = [UIImage imageNamed:imageName];
33+
_backgroundImageView = [[UIImageView alloc] initWithImage:image];
34+
CGRect backgroundFrame = frame;
35+
// shift the background frame down to allow for the status bar (which shows during the splash image)
36+
backgroundFrame.origin.y += [[UIApplication sharedApplication] statusBarFrame].size.height;
37+
backgroundFrame.size.height -= [[UIApplication sharedApplication] statusBarFrame].size.height;
38+
_backgroundImageView.frame = backgroundFrame;
39+
[window addSubview:_backgroundImageView];
40+
41+
_player = [[MPMoviePlayerController alloc] initWithContentURL:url];
42+
// video doesn't need to be shifted down
43+
_player.view.frame = frame;
44+
_player.useApplicationAudioSession = NO;
45+
_player.controlStyle = MPMovieControlStyleNone;
46+
_player.scalingMode = MPMovieScalingModeNone;
47+
// we're going to install it once it's loaded and play it then
48+
_player.shouldAutoplay = NO;
49+
// there's still a little bit of black flash left when the player is inserted
50+
// as it starts to play, adding the splash image to the background of the player
51+
// will get rid of it
52+
UIImageView *playerBackground = [[UIImageView alloc] initWithImage:image];
53+
playerBackground.frame = backgroundFrame;
54+
[_player.backgroundView addSubview:playerBackground];
55+
56+
// tell us when the video has loaded
57+
[[NSNotificationCenter defaultCenter] addObserver:self
58+
selector:@selector(splashLoadDidChange:)
59+
name:MPMoviePlayerLoadStateDidChangeNotification
60+
object:_player];
61+
62+
// tell us when the video has finished playing
63+
[[NSNotificationCenter defaultCenter] addObserver:self
64+
selector:@selector(splashDidFinished:)
65+
name:MPMoviePlayerPlaybackDidFinishNotification
66+
object:_player];
67+
}
68+
return self;
69+
}
70+
71+
- (void)splashLoadDidChange:(NSNotification *)notification
72+
{
73+
// we don't need this again
74+
[[NSNotificationCenter defaultCenter] removeObserver:self
75+
name:MPMoviePlayerLoadStateDidChangeNotification
76+
object:_player];
77+
78+
// the video has loaded so we can safely add the player to the window now
79+
UIWindow *window = [UIApplication sharedApplication].delegate.window;
80+
[window addSubview:_player.view];
81+
// and play it
82+
[_player play];
83+
84+
// take the background image out, we're done with it
85+
[_backgroundImageView removeFromSuperview];
86+
_backgroundImageView = nil;
87+
88+
// tell the delegate that the video has loaded
89+
[_delegate splashVideoLoaded:self];
90+
}
91+
92+
- (void)splashDidFinished:(NSNotification *)notification
93+
{
94+
// we don't need this again
95+
[[NSNotificationCenter defaultCenter] removeObserver:self
96+
name:MPMoviePlayerPlaybackDidFinishNotification
97+
object:_player];
98+
99+
// tell our delegate that we're done playing
100+
[_delegate splashVideoLoaded:self];
101+
102+
// take our player out of the window, we're done with it
103+
[_player.view removeFromSuperview];
104+
_player = nil;
105+
}
106+
107+
@end

XOSplash/XOViewController.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// XOSplash
44
//
55
// Created by Ross McFarland on 6/1/12.
6-
// Copyright (c) 2012 Madefire. All rights reserved.
6+
// Copyright (c) 2012 Ross McFarland. All rights reserved.
77
//
88

99
#import <UIKit/UIKit.h>

0 commit comments

Comments
 (0)