Skip to content

Commit e993121

Browse files
committed
Merge pull request #10 from toygar/fix/video-freeze-background-mode
Fixed freezing in the video background mode
2 parents 38203fd + acdf14f commit e993121

File tree

3 files changed

+19
-27
lines changed

3 files changed

+19
-27
lines changed

VideoSplash/AppDelegate.swift

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,28 @@ import UIKit
1212
class AppDelegate: UIResponder, UIApplicationDelegate {
1313

1414
var window: UIWindow?
15-
16-
17-
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
18-
// Override point for customization after application launch.
19-
let viewController = ViewController()
15+
let viewController = ViewController()
16+
17+
func application(application: UIApplication,
18+
didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
2019
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
2120
self.window!.rootViewController = viewController
2221
self.window!.backgroundColor = UIColor.whiteColor()
2322
self.window!.makeKeyAndVisible()
2423
return true
2524
}
2625

27-
func applicationWillResignActive(application: UIApplication) {
28-
// 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.
29-
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
30-
}
26+
func applicationWillResignActive(application: UIApplication) { }
3127

3228
func applicationDidEnterBackground(application: UIApplication) {
33-
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
34-
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
29+
viewController.pauseVideo()
3530
}
3631

3732
func applicationWillEnterForeground(application: UIApplication) {
38-
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
39-
}
40-
41-
func applicationDidBecomeActive(application: UIApplication) {
42-
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
43-
}
44-
45-
func applicationWillTerminate(application: UIApplication) {
46-
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
33+
viewController.playVideo()
4734
}
4835

36+
func applicationDidBecomeActive(application: UIApplication) { }
4937

38+
func applicationWillTerminate(application: UIApplication) { }
5039
}
51-

VideoSplash/Source/VideoSplashViewController.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,7 @@ public class VideoSplashViewController: UIViewController {
121121
}
122122

123123
// Override in subclass
124-
public func movieReadyToPlay(){
125-
print("test")
126-
}
124+
public func movieReadyToPlay() { }
127125

128126
override public func viewDidLoad() {
129127
super.viewDidLoad()
@@ -137,4 +135,13 @@ public class VideoSplashViewController: UIViewController {
137135
moviePlayer.player?.seekToTime(kCMTimeZero)
138136
moviePlayer.player?.play()
139137
}
138+
139+
func playVideo() {
140+
moviePlayer.player?.play()
141+
}
142+
143+
func pauseVideo() {
144+
moviePlayer.player?.pause()
145+
}
146+
140147
}

VideoSplash/ViewController.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class ViewController: VideoSplashViewController {
2323
self.backgroundColor = UIColor.blackColor()
2424
self.contentURL = url
2525

26-
2726
// Sample UI
2827
var sampleButton = UIButton(frame: CGRect(x: 15.0, y: 500.0, width: 140.0, height: 42.0))
2928
sampleButton.setImage(UIImage(named: "btnSignin"), forState: .Normal)
@@ -48,6 +47,4 @@ class ViewController: VideoSplashViewController {
4847
override func prefersStatusBarHidden() -> Bool {
4948
return true
5049
}
51-
5250
}
53-

0 commit comments

Comments
 (0)