Skip to content

Commit 785a2ef

Browse files
committed
feat(player): use new analytics endpoint
1 parent dca0eae commit 785a2ef

File tree

5 files changed

+49
-59
lines changed

5 files changed

+49
-59
lines changed

ApiVideoPlayer.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ Pod::Spec.new do |s|
1414
s.source_files = 'Sources/**/*.{swift, plist}'
1515
s.resources = 'Sources/**/*.{storyboard,xib,xcassets,json,png}'
1616

17-
s.dependency "ApiVideoPlayerAnalytics", "1.1.1"
17+
s.dependency "ApiVideoPlayerAnalytics", "2.0.0"
1818
end

ApiVideoPlayer.xcodeproj/project.pbxproj

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@
6565
21F14AE02C50E77A00B61588 /* ApiVideoPlayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21F14ABD2C50E77A00B61588 /* ApiVideoPlayer.swift */; };
6666
21F14AE12C50E77A00B61588 /* SwiftUIPlayerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21F14ABE2C50E77A00B61588 /* SwiftUIPlayerViewController.swift */; };
6767
21F14AE42C50E7E500B61588 /* Media.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 21F14AE22C50E7E400B61588 /* Media.xcassets */; };
68+
21F2E1042C52981000E833C2 /* ApiVideoPlayer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 21BD67A82C51467B0039DEB6 /* ApiVideoPlayer.framework */; };
69+
21F2E1052C52981000E833C2 /* ApiVideoPlayer.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 21BD67A82C51467B0039DEB6 /* ApiVideoPlayer.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
70+
21F2E1082C52981800E833C2 /* ApiVideoPlayer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 21BD67A82C51467B0039DEB6 /* ApiVideoPlayer.framework */; };
71+
21F2E1092C52981800E833C2 /* ApiVideoPlayer.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 21BD67A82C51467B0039DEB6 /* ApiVideoPlayer.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
6872
/* End PBXBuildFile section */
6973

7074
/* Begin PBXContainerItemProxy section */
@@ -89,6 +93,20 @@
8993
remoteGlobalIDString = 21F149552C50DF0E00B61588;
9094
remoteInfo = ApiVidePlayer;
9195
};
96+
21F2E1062C52981000E833C2 /* PBXContainerItemProxy */ = {
97+
isa = PBXContainerItemProxy;
98+
containerPortal = 21F1494D2C50DF0E00B61588 /* Project object */;
99+
proxyType = 1;
100+
remoteGlobalIDString = 21F149552C50DF0E00B61588;
101+
remoteInfo = ApiVideoPlayer;
102+
};
103+
21F2E10A2C52981800E833C2 /* PBXContainerItemProxy */ = {
104+
isa = PBXContainerItemProxy;
105+
containerPortal = 21F1494D2C50DF0E00B61588 /* Project object */;
106+
proxyType = 1;
107+
remoteGlobalIDString = 21F149552C50DF0E00B61588;
108+
remoteInfo = ApiVideoPlayer;
109+
};
92110
/* End PBXContainerItemProxy section */
93111

94112
/* Begin PBXCopyFilesBuildPhase section */
@@ -98,6 +116,7 @@
98116
dstPath = "";
99117
dstSubfolderSpec = 10;
100118
files = (
119+
21F2E1052C52981000E833C2 /* ApiVideoPlayer.framework in Embed Frameworks */,
101120
);
102121
name = "Embed Frameworks";
103122
runOnlyForDeploymentPostprocessing = 0;
@@ -108,6 +127,7 @@
108127
dstPath = "";
109128
dstSubfolderSpec = 10;
110129
files = (
130+
21F2E1092C52981800E833C2 /* ApiVideoPlayer.framework in Embed Frameworks */,
111131
);
112132
name = "Embed Frameworks";
113133
runOnlyForDeploymentPostprocessing = 0;
@@ -217,13 +237,15 @@
217237
isa = PBXFrameworksBuildPhase;
218238
buildActionMask = 2147483647;
219239
files = (
240+
21F2E1042C52981000E833C2 /* ApiVideoPlayer.framework in Frameworks */,
220241
);
221242
runOnlyForDeploymentPostprocessing = 0;
222243
};
223244
21F14A712C50E22200B61588 /* Frameworks */ = {
224245
isa = PBXFrameworksBuildPhase;
225246
buildActionMask = 2147483647;
226247
files = (
248+
21F2E1082C52981800E833C2 /* ApiVideoPlayer.framework in Frameworks */,
227249
);
228250
runOnlyForDeploymentPostprocessing = 0;
229251
};
@@ -285,6 +307,7 @@
285307
21BD67A82C51467B0039DEB6 /* ApiVideoPlayer.framework */,
286308
21BD67A92C51467B0039DEB6 /* Example iOS.app */,
287309
21BD67AA2C51467B0039DEB6 /* Example iOSSwiftUI.app */,
310+
21F2E1032C52981000E833C2 /* Frameworks */,
288311
);
289312
sourceTree = "<group>";
290313
};
@@ -499,6 +522,13 @@
499522
path = Resources;
500523
sourceTree = "<group>";
501524
};
525+
21F2E1032C52981000E833C2 /* Frameworks */ = {
526+
isa = PBXGroup;
527+
children = (
528+
);
529+
name = Frameworks;
530+
sourceTree = "<group>";
531+
};
502532
/* End PBXGroup section */
503533

504534
/* Begin PBXHeadersBuildPhase section */
@@ -567,6 +597,7 @@
567597
);
568598
dependencies = (
569599
21B395602C50EE0300451CF1 /* PBXTargetDependency */,
600+
21F2E1072C52981000E833C2 /* PBXTargetDependency */,
570601
);
571602
name = "Example iOS";
572603
productName = iOSExampleUIKit;
@@ -586,6 +617,7 @@
586617
);
587618
dependencies = (
588619
21B395652C50FA7B00451CF1 /* PBXTargetDependency */,
620+
21F2E10B2C52981800E833C2 /* PBXTargetDependency */,
589621
);
590622
name = "Example iOSSwiftUI";
591623
productName = iOSExampleSwiftUI;
@@ -776,6 +808,16 @@
776808
target = 21F149552C50DF0E00B61588 /* ApiVideoPlayer */;
777809
targetProxy = 21F149622C50DF0F00B61588 /* PBXContainerItemProxy */;
778810
};
811+
21F2E1072C52981000E833C2 /* PBXTargetDependency */ = {
812+
isa = PBXTargetDependency;
813+
target = 21F149552C50DF0E00B61588 /* ApiVideoPlayer */;
814+
targetProxy = 21F2E1062C52981000E833C2 /* PBXContainerItemProxy */;
815+
};
816+
21F2E10B2C52981800E833C2 /* PBXTargetDependency */ = {
817+
isa = PBXTargetDependency;
818+
target = 21F149552C50DF0E00B61588 /* ApiVideoPlayer */;
819+
targetProxy = 21F2E10A2C52981800E833C2 /* PBXContainerItemProxy */;
820+
};
779821
/* End PBXTargetDependency section */
780822

781823
/* Begin PBXVariantGroup section */
@@ -1237,7 +1279,7 @@
12371279
repositoryURL = "https://github.com/apivideo/api.video-swift-player-analytics";
12381280
requirement = {
12391281
kind = exactVersion;
1240-
version = 1.1.1;
1282+
version = 2.0.0;
12411283
};
12421284
};
12431285
/* End XCRemoteSwiftPackageReference section */

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ let package = Package(
1818
dependencies: [
1919
// Dependencies declare other packages that this package depends on.
2020
// .package(url: /* package url */, from: "1.0.0"),
21-
.package(url: "https://github.com/apivideo/api.video-swift-player-analytics", exact: "1.1.1"),
21+
.package(url: "https://github.com/apivideo/api.video-swift-player-analytics", exact: "2.0.0"),
2222
.package(url: "https://github.com/apivideo/api.video-swift-client", exact: "1.2.1")
2323
],
2424
targets: [

Sources/ApiVideoPlayer/Player/ApiVideoPlayerController.swift

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import MediaPlayer
88
/// It is used internally of the ``ApiVideoPlayerView``.
99
/// It could be used directly if you want to use the player with a fully custom UI.
1010
public class ApiVideoPlayerController: NSObject {
11-
internal let player = AVPlayer(playerItem: nil)
12-
private var analytics: PlayerAnalytics?
11+
internal let player = ApiVideoAnalyticsAVPlayer(playerItem: nil)
1312
private var timeObserver: Any?
1413
private var isFirstPlay = true
1514
private var isSeeking = false
@@ -163,9 +162,7 @@ public class ApiVideoPlayerController: NSObject {
163162
name: .AVPlayerItemDidPlayToEndTime,
164163
object: playerItem
165164
)
166-
if let urlAsset = playerItem.asset as? AVURLAsset {
167-
self.setUpAnalytics(url: urlAsset.url.absoluteString)
168-
}
165+
169166
}
170167

171168
private func notifyError(error: Error) {
@@ -209,15 +206,6 @@ public class ApiVideoPlayerController: NSObject {
209206
player.removeTimeObserver(observer)
210207
}
211208

212-
private func setUpAnalytics(url: String) {
213-
do {
214-
let option = try Options(mediaUrl: url)
215-
self.analytics = PlayerAnalytics(options: option)
216-
} catch {
217-
print("Failed to initiate analytics for \(url)")
218-
}
219-
}
220-
221209
/// Get if the player is playing a live stream.
222210
/// - Returns: True if the player is playing a live stream
223211
public var isLive: Bool {
@@ -253,16 +241,6 @@ public class ApiVideoPlayerController: NSObject {
253241
private func seekImpl(to time: CMTime, completion: @escaping (Bool) -> Void) {
254242
let from = self.currentTime
255243
self.player.seek(to: time, toleranceBefore: .zero, toleranceAfter: .zero) { completed in
256-
self.analytics?
257-
.seek(
258-
from: Float(max(0, from.seconds)),
259-
to: Float(max(0, time.seconds))
260-
) { result in
261-
switch result {
262-
case .success: break
263-
case let .failure(error): print("Failed to send seek event to analytics: \(error)")
264-
}
265-
}
266244
self.infoNowPlaying.updateCurrentTime(currentTime: time)
267245
completion(completed)
268246
}
@@ -514,12 +492,6 @@ public class ApiVideoPlayerController: NSObject {
514492
self.replay()
515493
self.multicastDelegate.didLoop()
516494
}
517-
self.analytics?.end { result in
518-
switch result {
519-
case .success: break
520-
case let .failure(error): print("Failed to send end event to analytics: \(error)")
521-
}
522-
}
523495
self.multicastDelegate.didEnd()
524496
}
525497

@@ -578,12 +550,6 @@ public class ApiVideoPlayerController: NSObject {
578550
if self.autoplay {
579551
self.play()
580552
}
581-
self.analytics?.ready { result in
582-
switch result {
583-
case .success: break
584-
case let .failure(error): print("Failed to send ready event to analytics: \(error)")
585-
}
586-
}
587553
}
588554
}
589555

@@ -596,12 +562,6 @@ public class ApiVideoPlayerController: NSObject {
596562
return
597563
}
598564

599-
self.analytics?.pause { result in
600-
switch result {
601-
case .success: break
602-
case let .failure(error): print("Failed to send pause event to analytics: \(error)")
603-
}
604-
}
605565
self.infoNowPlaying.pause(currentTime: self.currentTime)
606566
self.multicastDelegate.didPause()
607567
}
@@ -623,19 +583,7 @@ public class ApiVideoPlayerController: NSObject {
623583
)
624584

625585
#endif
626-
self.analytics?.play { result in
627-
switch result {
628-
case .success: break
629-
case let .failure(error): print("Failed to send play event to analytics: \(error)")
630-
}
631-
}
632586
} else {
633-
self.analytics?.resume { result in
634-
switch result {
635-
case .success: break
636-
case let .failure(error): print("Failed to send resume event to analytics: \(error)")
637-
}
638-
}
639587
self.infoNowPlaying.play(currentTime: self.currentTime)
640588
}
641589
#if !os(macOS)

0 commit comments

Comments
 (0)