Skip to content

Commit 96c719e

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

File tree

3 files changed

+5
-57
lines changed

3 files changed

+5
-57
lines changed

ApiVideoPlayer.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,8 +1236,8 @@
12361236
isa = XCRemoteSwiftPackageReference;
12371237
repositoryURL = "https://github.com/apivideo/api.video-swift-player-analytics";
12381238
requirement = {
1239-
kind = exactVersion;
1240-
version = 1.1.1;
1239+
branch = "feature/new-analytics";
1240+
kind = branch;
12411241
};
12421242
};
12431243
/* End XCRemoteSwiftPackageReference section */

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", branch: "feature/new-analytics"),
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)