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.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
igoriols committed May 9, 2017
2 parents 1a461fa + 469a8be commit f18bb65
Show file tree
Hide file tree
Showing 20 changed files with 211 additions and 77 deletions.
2 changes: 1 addition & 1 deletion 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.1"
s.version = "0.6.2"
s.summary = "An extensible media player for iOS"
s.homepage = "http://clappr.io"
s.license = 'MIT'
Expand Down
3 changes: 2 additions & 1 deletion Clappr/Classes/Base/BaseObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ open class BaseObject: NSObject, EventProtocol {

open func off(_ listenId: String) {
guard let event = events[listenId] else {
Logger.logError("could not find any event with given event listenId", scope: logIdentifier())
Logger.logError("could not find any event with given event listenId: \(listenId)", scope: logIdentifier())
return
}

Expand Down Expand Up @@ -117,6 +117,7 @@ open class BaseObject: NSObject, EventProtocol {
}

deinit {
Logger.logDebug("deinit", scope: NSStringFromClass(type(of: self)))
self.stopListening()
}
}
28 changes: 21 additions & 7 deletions Clappr/Classes/Base/Container.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,6 @@ open class Container: UIBaseObject {
plugin.render()
}

open func destroy() {
stopListening()
playback?.destroy()

removeFromSuperview()
}

fileprivate func loadPlugins() {
for type in loader.containerPlugins {
if let plugin = type.init(context: self) as? UIContainerPlugin {
Expand All @@ -107,4 +100,25 @@ open class Container: UIBaseObject {
open func hasPlugin(_ pluginClass: AnyClass) -> Bool {
return plugins.filter({ $0.isKind(of: pluginClass) }).count > 0
}

open func destroy() {
Logger.logDebug("destroying", scope: "Container")

trigger(InternalEvent.willDestroy.rawValue)

Logger.logDebug("destroying listeners", scope: "Container")
stopListening()

Logger.logDebug("destroying playback", scope: "Container")
playback?.destroy()

Logger.logDebug("destroying plugins", scope: "Container")
plugins.forEach { plugin in plugin.destroy() }
plugins.removeAll()

removeFromSuperview()

trigger(InternalEvent.didDestroy.rawValue)
Logger.logDebug("destroyed", scope: "Container")
}
}
44 changes: 37 additions & 7 deletions Clappr/Classes/Base/Core.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
open class Core: UIBaseObject, UIGestureRecognizerDelegate {
fileprivate(set) open var options: Options
fileprivate(set) open var containers: [Container] = []
fileprivate(set) open var mediaControl: MediaControl!
fileprivate(set) open var mediaControl: MediaControl?
fileprivate(set) open var plugins: [UICorePlugin] = []

open var parentController: UIViewController?
open var parentView: UIView?

fileprivate lazy var fullscreenController = FullscreenController(nibName: nil, bundle: nil)

open var activeContainer: Container?
open weak var activeContainer: Container?

open var activePlayback: Playback? {
return activeContainer?.playback
Expand Down Expand Up @@ -42,7 +42,7 @@ open class Core: UIBaseObject, UIGestureRecognizerDelegate {

if let container = containers.first {
setActiveContainer(container)
mediaControl.setup(container)
mediaControl?.setup(container)
}
}

Expand Down Expand Up @@ -83,13 +83,17 @@ open class Core: UIBaseObject, UIGestureRecognizerDelegate {
}

fileprivate func bindEventListeners() {
guard let mediaControl = self.mediaControl else {
return
}

listenTo(mediaControl, eventName: Event.requestFullscreen.rawValue) { [weak self] (userInfo: EventUserInfo) in self?.enterFullscreen(userInfo) }
listenTo(mediaControl, eventName: Event.exitFullscreen.rawValue) { [weak self] (userInfo: EventUserInfo) in self?.exitFullscreen(userInfo) }
}

fileprivate func enterFullscreen(_: EventUserInfo) {
trigger(InternalEvent.willEnterFullscreen.rawValue)
mediaControl.fullscreen = true
mediaControl?.fullscreen = true
fullscreenController.view.backgroundColor = UIColor.black
fullscreenController.modalPresentationStyle = .overFullScreen
parentController?.present(fullscreenController, animated: false, completion: nil)
Expand All @@ -105,7 +109,7 @@ open class Core: UIBaseObject, UIGestureRecognizerDelegate {
}

fileprivate func renderInContainerView() {
mediaControl.fullscreen = false
mediaControl?.fullscreen = false
parentView?.addSubviewMatchingConstraints(self)
}

Expand All @@ -115,8 +119,10 @@ open class Core: UIBaseObject, UIGestureRecognizerDelegate {
plugins.forEach(installPlugin)
containers.forEach(renderContainer)

addSubviewMatchingConstraints(mediaControl)
mediaControl.render()
if let mediaControl = self.mediaControl {
addSubviewMatchingConstraints(mediaControl)
mediaControl.render()
}
}

fileprivate func addToContainer() {
Expand Down Expand Up @@ -154,4 +160,28 @@ open class Core: UIBaseObject, UIGestureRecognizerDelegate {
guard fullscreen != isFullscreen else { return }
fullscreen ? enterFullscreen(nil) : exitFullscreen([:])
}

open func destroy() {
Logger.logDebug("destroying", scope: "Core")

trigger(InternalEvent.willDestroy.rawValue)

Logger.logDebug("destroying listeners", scope: "Core")
stopListening()

Logger.logDebug("destroying containers", scope: "Core")
containers.forEach { container in container.destroy() }
containers.removeAll()

Logger.logDebug("destroying plugins", scope: "Core")
plugins.forEach { plugin in plugin.destroy() }
plugins.removeAll()

Logger.logDebug("destroying mediaControl", scope: "Core")
mediaControl?.destroy()

trigger(InternalEvent.didDestroy.rawValue)

Logger.logDebug("destroyed", scope: "Core")
}
}
37 changes: 21 additions & 16 deletions Clappr/Classes/Base/MediaControl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ open class MediaControl: UIBaseObject {

@IBOutlet open weak var airPlayVolumeView: MPVolumeView?

internal(set) open var container: Container!
internal(set) open weak var container: Container?
internal(set) open var controlsHidden = false

open var bufferPercentage: CGFloat = 0.0
Expand Down Expand Up @@ -72,11 +72,11 @@ open class MediaControl: UIBaseObject {
}

open var fullscreenDisabled: Bool {
return container.options[kFullscreenDisabled] as? Bool ?? false
return container?.options[kFullscreenDisabled] as? Bool ?? false
}

fileprivate var duration: CGFloat {
return CGFloat(container.playback?.duration ?? 0.0)
return CGFloat(container?.playback?.duration ?? 0.0)
}

public required init?(coder aDecoder: NSCoder) {
Expand Down Expand Up @@ -162,23 +162,25 @@ open class MediaControl: UIBaseObject {
}

private func isPlaybackPlaying() -> Bool {
return container.playback?.isPlaying ?? false
return container?.playback?.isPlaying ?? false
}

private func setupBindings() {
bindEventListeners()

container.on(InternalEvent.didChangePlayback.rawValue) { [weak self] _ in
container?.on(InternalEvent.didChangePlayback.rawValue) { [weak self] _ in
self?.stopListening()
self?.bindEventListeners()
}
}

open func bindEventListeners() {
listenTo(container, eventName: Event.disableMediaControl.rawValue) { [weak self] _ in self?.disable() }
listenTo(container, eventName: Event.enableMediaControl.rawValue) { [weak self] _ in self?.enable() }
if let container = self.container {
listenTo(container, eventName: Event.disableMediaControl.rawValue) { [weak self] _ in self?.disable() }
listenTo(container, eventName: Event.enableMediaControl.rawValue) { [weak self] _ in self?.enable() }
}

if let playback = container.playback {
if let playback = container?.playback {
listenTo(playback, eventName: Event.playing.rawValue) { [weak self] _ in self?.triggerPlay() }
listenTo(playback, eventName: Event.didPause.rawValue) { [weak self] _ in self?.triggerPause() }
listenTo(playback, eventName: Event.stalled.rawValue) { [weak self] _ in self?.playbackStalled() }
Expand Down Expand Up @@ -253,7 +255,7 @@ open class MediaControl: UIBaseObject {
}

open func playbackReady() {
livePlayback = container.playback?.playbackType == .live
livePlayback = container?.playback?.playbackType == .live
livePlayback ? setupForLive() : setupForVOD()
updateBars()
updateScrubberPosition()
Expand All @@ -267,7 +269,7 @@ open class MediaControl: UIBaseObject {

open func setupForVOD() {
progressBarView?.backgroundColor = vodProgressBarColor
durationLabel?.text = DateFormatter.formatSeconds(container.playback?.duration ?? 0.0)
durationLabel?.text = DateFormatter.formatSeconds(container?.playback?.duration ?? 0.0)
}

open func hide() {
Expand Down Expand Up @@ -334,19 +336,19 @@ open class MediaControl: UIBaseObject {

fileprivate func pause() {
playbackControlState = .paused
container.playback?.pause()
container?.playback?.pause()
trigger(Event.didPause.rawValue)
}

fileprivate func play() {
playbackControlState = .playing
container.playback?.play()
container?.playback?.play()
trigger(Event.playing.rawValue)
}

fileprivate func stop() {
playbackControlState = .stopped
container.playback?.stop()
container?.playback?.stop()
trigger(Event.didStop.rawValue)
}

Expand All @@ -360,7 +362,7 @@ open class MediaControl: UIBaseObject {
hideControlsTimer?.invalidate()
if isPlaybackPlaying() {
hideAnimated()
} else if let playback = container.playback {
} else if let playback = container?.playback {
listenToOnce(playback, eventName: Event.playing.rawValue) { [weak self] _ in self?.hideAnimated() }
}
}
Expand All @@ -376,7 +378,7 @@ open class MediaControl: UIBaseObject {
isSeeking = true
hideControlsTimer?.invalidate()
case .ended:
container.playback?.seek(secondsRelativeToPoint(touchPoint))
container?.playback?.seek(secondsRelativeToPoint(touchPoint))
isSeeking = false
scheduleTimerToHideControls()
default: break
Expand All @@ -394,8 +396,11 @@ open class MediaControl: UIBaseObject {
return 0
}

deinit {
open func destroy() {
Logger.logDebug("destroying", scope: "MediaCotrol")
Logger.logDebug("destroying listeners", scope: "MediaCotrol")
stopListening()
NotificationCenter.default.removeObserver(self)
Logger.logDebug("destroyed", scope: "MediaCotrol")
}
}
14 changes: 9 additions & 5 deletions Clappr/Classes/Base/Playback.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,6 @@ open class Playback: UIBaseObject, Plugin {
return false
}

open func destroy() {
removeFromSuperview()
stopListening()
}

open override func render() {
once(Event.ready.rawValue) { [unowned self] _ in
if self.startAt != 0.0 {
Expand Down Expand Up @@ -123,4 +118,13 @@ open class Playback: UIBaseObject, Plugin {
open func pause() {}
open func stop() {}
open func seek(_: TimeInterval) {}

open func destroy() {
Logger.logDebug("destroying", scope: "Playback")
Logger.logDebug("destroying ui elements", scope: "Playback")
removeFromSuperview()
Logger.logDebug("destroying listeners", scope: "Playback")
stopListening()
Logger.logDebug("destroyed", scope: "Playback")
}
}
6 changes: 5 additions & 1 deletion Clappr/Classes/Base/Player.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,11 @@ open class Player: BaseObject {
trigger(event.rawValue, userInfo: userInfo)
}

deinit {
open func destroy() {
Logger.logDebug("destroying", scope: "Player")
stopListening()
Logger.logDebug("destroying core", scope: "Player")
self.core?.destroy()
Logger.logDebug("destroyed", scope: "Player")
}
}
6 changes: 5 additions & 1 deletion Clappr/Classes/Base/UIBaseObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ open class UIBaseObject: UIView, EventProtocol {
Logger.logDebug("[\(eventName)] triggered", scope: logIdentifier())
}

open func trigger(_ eventName: String, userInfo: [AnyHashable: Any]?) {
open func trigger(_ eventName: String, userInfo: EventUserInfo) {
baseObject.trigger(eventName, userInfo: userInfo)
Logger.logDebug("[\(eventName)] triggered with \(String(describing: userInfo))", scope: logIdentifier())
}
Expand Down Expand Up @@ -57,6 +57,10 @@ open class UIBaseObject: UIView, EventProtocol {
}

open func render() {}

deinit {
Logger.logDebug("deinit", scope: NSStringFromClass(type(of: self)))
}
}

public extension UIBaseObject {
Expand Down
3 changes: 3 additions & 0 deletions Clappr/Classes/Enum/Event.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ public enum Event: String {
case airPlayStatusUpdate
case requestFullscreen
case exitFullscreen
case requestPosterUpdate
case willUpdatePoster
case didUpdatePoster
}
2 changes: 2 additions & 0 deletions Clappr/Classes/Enum/InternalEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ public enum InternalEvent: String {
case willLoadSource
case didLoadSource
case didNotLoadSource
case willDestroy
case didDestroy
}
Loading

0 comments on commit f18bb65

Please sign in to comment.