Skip to content

Commit

Permalink
Remove overly complicated background video measurement management for…
Browse files Browse the repository at this point in the history
… comScore (#649)
  • Loading branch information
defagos authored Nov 24, 2023
1 parent 2118483 commit 0d7f659
Show file tree
Hide file tree
Showing 12 changed files with 17 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .swiftpm/xcode/xcshareddata/xcschemes/Analytics.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion .swiftpm/xcode/xcshareddata/xcschemes/Circumspect.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion .swiftpm/xcode/xcshareddata/xcschemes/Core.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
2 changes: 1 addition & 1 deletion .swiftpm/xcode/xcshareddata/xcschemes/Player.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
LastUpgradeVersion = "1510"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
5 changes: 4 additions & 1 deletion Demo/Pillarbox-demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@
attributes = {
BuildIndependentTargetsInParallel = 1;
LastSwiftUpdateCheck = 1400;
LastUpgradeCheck = 1500;
LastUpgradeCheck = 1510;
TargetAttributes = {
6F05B8D42887E934005D75E3 = {
CreatedOnToolsVersion = 14.0;
Expand Down Expand Up @@ -630,6 +630,7 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
Expand Down Expand Up @@ -691,6 +692,7 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
Expand Down Expand Up @@ -803,6 +805,7 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
58 changes: 0 additions & 58 deletions Sources/Analytics/ComScore/ComScoreTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,15 @@ import UIKit
public final class ComScoreTracker: PlayerItemTracker {
private var streamingAnalytics = ComScoreStreamingAnalytics()
private var metadata: [String: String] = [:]
private var properties: PlayerProperties?
private weak var player: Player?

private var applicationState: ApplicationState = .foreground {
didSet {
guard let properties else { return }
updateProperties(with: properties)
}
}

public init(configuration: Void) {}

public func enable(for player: Player) {
self.player = player
streamingAnalytics.createPlaybackSession()
streamingAnalytics.setMediaPlayerName("Pillarbox")
streamingAnalytics.setMediaPlayerVersion(Player.version)
registerApplicationStateNotifications()
}

public func updateMetadata(with metadata: [String: String]) {
Expand All @@ -50,22 +41,11 @@ public final class ComScoreTracker: PlayerItemTracker {
}

public func updateProperties(with properties: PlayerProperties) {
self.properties = properties
notify(with: properties)
}

// swiftlint:disable:next cyclomatic_complexity
private func notify(with properties: PlayerProperties) {
guard !metadata.isEmpty, let player else { return }

AnalyticsListener.capture(streamingAnalytics.configuration())
streamingAnalytics.setProperties(for: properties, time: player.time, streamType: properties.streamType)

guard applicationState == .foreground else {
streamingAnalytics.notifyEvent(for: .paused, at: properties.rate)
return
}

switch (properties.isSeeking, properties.isBuffering) {
case (true, true):
streamingAnalytics.notifySeekStart()
Expand All @@ -82,45 +62,7 @@ public final class ComScoreTracker: PlayerItemTracker {
}

public func disable() {
unregisterApplicationStateNotifications()
streamingAnalytics = ComScoreStreamingAnalytics()
player = nil
}
}

private extension ComScoreTracker {
enum ApplicationState {
case foreground
case background
}

func registerApplicationStateNotifications() {
NotificationCenter.default.addObserver(
self,
selector: #selector(didEnterBackground(_:)),
name: UIApplication.didEnterBackgroundNotification,
object: nil
)
NotificationCenter.default.addObserver(
self,
selector: #selector(didBecomeActive(_:)),
name: UIApplication.didBecomeActiveNotification,
object: nil
)
}

func unregisterApplicationStateNotifications() {
NotificationCenter.default.removeObserver(self, name: UIApplication.didEnterBackgroundNotification, object: nil)
NotificationCenter.default.removeObserver(self, name: UIApplication.didBecomeActiveNotification, object: nil)
}

@objc
private func didEnterBackground(_ notification: Notification) {
applicationState = .background
}

@objc
private func didBecomeActive(_ notification: Notification) {
applicationState = .foreground
}
}
4 changes: 4 additions & 0 deletions docs/GETTING_STARTED.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ When `SystemVideoView` is presented inline, though, its close button is replaced

Switching between a `VideoView` and a `SystemVideoView` for the content currently being played in Picture in Picture is not supported and leads to undefined behavior.

## Background video playback

`Player` can be enabled for background video playback using `audiovisualBackgroundPlaybackPolicy`. For SRG SSR content, though, your application must not implement background video playback to avoid issues with comScore measurements. Please implement proper Picture in Picture support instead.

## Have fun

This is only a glimpse of what can be achieved with Pillarbox. Though the feature set is still limited you should already be able to implement pretty interesting playback experiences. Please have a look at the documentation (which can be built with Xcode _Product_ > _Build Documentation_) and check the demo and its various examples to better understand what is possible.

0 comments on commit 0d7f659

Please sign in to comment.