Skip to content
This repository has been archived by the owner on Jan 16, 2023. It is now read-only.

Commit

Permalink
Merge branch 'release/0.6.9'
Browse files Browse the repository at this point in the history
  • Loading branch information
CristianDRM committed Oct 6, 2017
2 parents d90097d + 07f582d commit a36923d
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 143 deletions.
5 changes: 3 additions & 2 deletions Clappr.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Clappr"
s.version = "0.6.8"
s.version = "0.6.9"
s.summary = "An extensible media player for iOS"
s.homepage = "http://clappr.io"
s.license = 'MIT'
Expand All @@ -11,7 +11,8 @@ Pod::Spec.new do |s|
"Bruno Torres" => "[email protected]",
"Fernando Pinho" => "[email protected]",
"Uéliton Freitas" => "[email protected]",
"Augusto Boranga" => "[email protected]"
"Augusto Boranga" => "[email protected]",
"Cristian Madrid" => "[email protected]",
}

s.source = { :git => "https://github.com/clappr/clappr-ios.git", :tag => s.version.to_s }
Expand Down
8 changes: 1 addition & 7 deletions Clappr/Classes/Base/Core.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ open class Core: UIBaseObject, UIGestureRecognizerDelegate {
private (set) lazy var fullscreenController = FullscreenController(nibName: nil, bundle: nil)

lazy var fullscreenHandler: FullscreenStateHandler = {
let handler: FullscreenStateHandler = self.optionsUnboxer.fullscreenControledByApp ? FullscreenByApp() : FullscreenByPlayer(core: self)
return handler
return self.optionsUnboxer.fullscreenControledByApp ? FullscreenByApp(core: self) : FullscreenByPlayer(core: self) as FullscreenStateHandler
}()

lazy var optionsUnboxer: OptionsUnboxer = OptionsUnboxer(options: self.options)
Expand Down Expand Up @@ -147,11 +146,6 @@ open class Core: UIBaseObject, UIGestureRecognizerDelegate {

open func setFullscreen(_ fullscreen: Bool) {
mediaControl?.fullscreen = fullscreen
if fullscreen {
fullscreenHandler.enterInFullscreen()
} else {
fullscreenHandler.exitFullscreen()
}
}

open func destroy() {
Expand Down
46 changes: 22 additions & 24 deletions Clappr/Classes/Base/FullScreenStateHandler.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
protocol FullscreenStateHandler {

init()
var core: Core { get }
var isOnFullscreen: Bool { get }

init(core: Core)

func enterInFullscreen(_: EventUserInfo)
func enterInFullscreen()
Expand All @@ -18,53 +21,48 @@ extension FullscreenStateHandler {
func exitFullscreen() {
exitFullscreen([:])
}

var isOnFullscreen: Bool {
return core.mediaControl?.fullscreen ?? false
}
}

class FullscreenByApp: BaseObject, FullscreenStateHandler {
struct FullscreenByApp: FullscreenStateHandler {

required override init() {
super.init()
}
var core: Core

func enterInFullscreen(_: EventUserInfo = [:]) {
trigger(Event.requestFullscreen.rawValue)
guard !isOnFullscreen else { return }
core.trigger(InternalEvent.userRequestEnterInFullscreen.rawValue)
}

func exitFullscreen(_: EventUserInfo = [:]) {
trigger(Event.exitFullscreen.rawValue)
guard isOnFullscreen else { return }
core.trigger(InternalEvent.userRequestExitFullscreen.rawValue)
}
}

class FullscreenByPlayer: BaseObject, FullscreenStateHandler {
struct FullscreenByPlayer: FullscreenStateHandler {

weak var core: Core?

required override init() {
super.init()
}

convenience init(core: Core) {
self.init()
self.core = core
}
var core: Core

func enterInFullscreen(_: EventUserInfo = [:]) {
guard let core = core else { return }
trigger(InternalEvent.willEnterFullscreen.rawValue)
guard !isOnFullscreen else { return }
core.trigger(InternalEvent.willEnterFullscreen.rawValue)
core.mediaControl?.fullscreen = true
core.fullscreenController.view.backgroundColor = UIColor.black
core.fullscreenController.modalPresentationStyle = .overFullScreen
core.parentController?.present(core.fullscreenController, animated: false, completion: nil)
core.fullscreenController.view.addSubviewMatchingConstraints(core)
trigger(InternalEvent.didEnterFullscreen.rawValue)
core.trigger(InternalEvent.didEnterFullscreen.rawValue)
}

func exitFullscreen(_: EventUserInfo = [:]) {
guard let core = core else { return }
trigger(InternalEvent.willExitFullscreen.rawValue)
guard isOnFullscreen else { return }
core.trigger(InternalEvent.willExitFullscreen.rawValue)
core.mediaControl?.fullscreen = false
core.parentView?.addSubviewMatchingConstraints(core)
core.fullscreenController.dismiss(animated: false, completion: nil)
trigger(InternalEvent.didExitFullscreen.rawValue)
core.trigger(InternalEvent.didExitFullscreen.rawValue)
}
}
5 changes: 3 additions & 2 deletions Clappr/Classes/Base/Player.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ open class Player: BaseObject {
Event.playing.rawValue, Event.didComplete.rawValue,
Event.didPause.rawValue, Event.stalled.rawValue,
Event.didStop.rawValue, Event.bufferUpdate.rawValue,
Event.requestFullscreen.rawValue, Event.exitFullscreen.rawValue,
Event.positionUpdate.rawValue, Event.willPlay.rawValue,
Event.willPause.rawValue, Event.willStop.rawValue,
Event.airPlayStatusUpdate.rawValue, Event.seek.rawValue])
Expand All @@ -94,10 +95,10 @@ open class Player: BaseObject {
self.core?.on(InternalEvent.didChangeActivePlayback.rawValue) { [weak self] _ in self?.bindPlaybackEvents() }
self.core?.on(InternalEvent.didEnterFullscreen.rawValue) { [weak self] (info: EventUserInfo) in self?.forward(.requestFullscreen, userInfo: info) }
self.core?.on(InternalEvent.didExitFullscreen.rawValue) { [weak self] (info: EventUserInfo) in self?.forward(.exitFullscreen, userInfo: info) }
self.core?.on(InternalEvent.userRequestEnterInFullscreen.rawValue) { [weak self] (info: EventUserInfo) in self?.forward(.requestFullscreen, userInfo: info) }
self.core?.on(InternalEvent.userRequestExitFullscreen.rawValue) { [weak self] (info: EventUserInfo) in self?.forward(.exitFullscreen, userInfo: info) }

bindPlaybackEvents()

self.core?.render()
}

open func attachTo(_ view: UIView, controller: UIViewController) {
Expand Down
2 changes: 2 additions & 0 deletions Clappr/Classes/Enum/InternalEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ public enum InternalEvent: String {
case didNotLoadSource
case willDestroy
case didDestroy
case userRequestEnterInFullscreen
case userRequestExitFullscreen
}
2 changes: 1 addition & 1 deletion Clappr/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.6.8</string>
<string>0.6.9</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
37 changes: 18 additions & 19 deletions Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,17 @@ class ViewController: UIViewController {
var player: Player!
var options: Options = [:]

var fullscreenByApp: Bool {
return options[kFullscreenByApp] as? Bool ?? false
}

override func viewDidLoad() {
super.viewDidLoad()
player = Player(options: options)

listenToPlayerEvents()

player.attachTo(playerContainer, controller: self)
NotificationCenter.default.addObserver(self, selector: #selector(ViewController.rotated), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
}

deinit {
NotificationCenter.default.removeObserver(self)
}

func rotated() {
if UIDevice.current.orientation.isLandscape {
player.setFullscreen(true)
} else {
player.setFullscreen(true)
}
}

func listenToPlayerEvents() {
Expand All @@ -42,18 +33,20 @@ class ViewController: UIViewController {

player.on(Event.error) { userInfo in print("on Error: \(String(describing: userInfo))") }

player.on(Event.requestFullscreen) { _ in print("on Enter Fullscreen") }

player.on(Event.exitFullscreen) { _ in print("on Exit Fullscreen") }

player.on(Event.stalled) { _ in print("on Stalled") }

player.on(Event.requestFullscreen) { _ in
self.player.setFullscreen(true)
Logger.logInfo("Entrar em modo fullscreen")
if self.fullscreenByApp {
self.player.setFullscreen(true)
}
}

player.on(Event.exitFullscreen) { _ in
self.player.setFullscreen(false)
Logger.logInfo("Sair do modo fullscreen")
if self.fullscreenByApp {
self.player.setFullscreen(false)
}
}
}

Expand All @@ -68,4 +61,10 @@ class ViewController: UIViewController {
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation { // swiftlint:disable:this variable_name
return UIInterfaceOrientation.portrait
}

func showAlert(with title: String, message: String) {
let alertViewController = UIAlertController(title: title, message: message, preferredStyle: .alert)
alertViewController.addAction(UIAlertAction(title: "ok", style: UIAlertActionStyle.default, handler: nil))
self.navigationController?.present(alertViewController, animated: true, completion: nil)
}
}
38 changes: 14 additions & 24 deletions Tests/CoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,13 @@ class CoreTests: QuickSpec {
let options: Options = [kFullscreen: true]
let core = Core(options: options)
core.parentView = UIView()

self.expectation(forNotification: InternalEvent.didEnterFullscreen.rawValue, object: core.fullscreenHandler) { notification in
return true
}

self.expectation(forNotification: InternalEvent.willEnterFullscreen.rawValue, object: core.fullscreenHandler) { notification in
return true
var callbackWasCall = false
core.on(InternalEvent.didEnterFullscreen.rawValue) { _ in
callbackWasCall = true
}

core.render()
self.waitForExpectations(timeout: 2, handler: nil)
expect(callbackWasCall).toEventually(beTrue())

expect(core.parentView?.subviews.contains(core)).to(beFalse())
expect(core.fullscreenController.view.subviews.contains(core)).to(beTrue())
expect(core.mediaControl?.fullscreen).to(beTrue())
Expand All @@ -70,23 +66,17 @@ class CoreTests: QuickSpec {
}

it("Should start as fullscreen video when `kFullscreen: true` and `kFullscreenByApp: false` was passed") {
let options: Options = [kFullscreen: true]
let core = Core(options: options)
core.parentView = UIView()

self.expectation(forNotification: InternalEvent.didEnterFullscreen.rawValue, object: core.fullscreenHandler) { notification in
return true
}

self.expectation(forNotification: InternalEvent.willEnterFullscreen.rawValue, object: core.fullscreenHandler) { notification in
return true
let player = Player(options: [kFullscreen: true] as Options)
var callbackWasCalled = false
player.on(.requestFullscreen) { _ in
callbackWasCalled = true
}
player.attachTo(UIView(), controller: UIViewController())
player.setFullscreen(true)
expect(callbackWasCalled).toEventually(beTrue())

core.render()
self.waitForExpectations(timeout: 2, handler: nil)
expect(core.parentView?.subviews.contains(core)).to(beFalse())
expect(core.fullscreenController.view.subviews.contains(core)).to(beTrue())
expect(core.mediaControl?.fullscreen).to(beTrue())
expect(player.core!.parentView?.subviews.contains(core)).to(beFalse())
expect(player.core!.mediaControl?.fullscreen).to(beTrue())
}

}
Expand Down
Loading

0 comments on commit a36923d

Please sign in to comment.