From 69bbdce4d8f4999bc372c50f594a8fa8d7ecfba9 Mon Sep 17 00:00:00 2001 From: ThibaultBee <37510686+ThibaultBee@users.noreply.github.com> Date: Wed, 24 Jul 2024 16:54:49 +0200 Subject: [PATCH] feat(player): use new analytics endpoint --- ApiVideoPlayer.podspec | 2 +- ApiVideoPlayer.xcodeproj/project.pbxproj | 2 +- Package.swift | 2 +- .../Player/ApiVideoPlayerController.swift | 56 +------------------ 4 files changed, 5 insertions(+), 57 deletions(-) diff --git a/ApiVideoPlayer.podspec b/ApiVideoPlayer.podspec index b2d4bc07..d5a6b695 100644 --- a/ApiVideoPlayer.podspec +++ b/ApiVideoPlayer.podspec @@ -14,5 +14,5 @@ Pod::Spec.new do |s| s.source_files = 'Sources/**/*.{swift, plist}' s.resources = 'Sources/**/*.{storyboard,xib,xcassets,json,png}' - s.dependency "ApiVideoPlayerAnalytics", "1.1.1" + s.dependency "ApiVideoPlayerAnalytics", "2.0.0" end diff --git a/ApiVideoPlayer.xcodeproj/project.pbxproj b/ApiVideoPlayer.xcodeproj/project.pbxproj index 92643127..b3552fe0 100644 --- a/ApiVideoPlayer.xcodeproj/project.pbxproj +++ b/ApiVideoPlayer.xcodeproj/project.pbxproj @@ -1237,7 +1237,7 @@ repositoryURL = "https://github.com/apivideo/api.video-swift-player-analytics"; requirement = { kind = exactVersion; - version = 1.1.1; + version = 2.0.0; }; }; /* End XCRemoteSwiftPackageReference section */ diff --git a/Package.swift b/Package.swift index 5509cfdf..900276a5 100644 --- a/Package.swift +++ b/Package.swift @@ -18,7 +18,7 @@ let package = Package( dependencies: [ // Dependencies declare other packages that this package depends on. // .package(url: /* package url */, from: "1.0.0"), - .package(url: "https://github.com/apivideo/api.video-swift-player-analytics", exact: "1.1.1"), + .package(url: "https://github.com/apivideo/api.video-swift-player-analytics", exact: "2.0.0"), .package(url: "https://github.com/apivideo/api.video-swift-client", exact: "1.2.1") ], targets: [ diff --git a/Sources/ApiVideoPlayer/Player/ApiVideoPlayerController.swift b/Sources/ApiVideoPlayer/Player/ApiVideoPlayerController.swift index e5ea0550..fa1d0e66 100644 --- a/Sources/ApiVideoPlayer/Player/ApiVideoPlayerController.swift +++ b/Sources/ApiVideoPlayer/Player/ApiVideoPlayerController.swift @@ -8,8 +8,7 @@ import MediaPlayer /// It is used internally of the ``ApiVideoPlayerView``. /// It could be used directly if you want to use the player with a fully custom UI. public class ApiVideoPlayerController: NSObject { - internal let player = AVPlayer(playerItem: nil) - private var analytics: PlayerAnalytics? + internal let player = ApiVideoAnalyticsAVPlayer(playerItem: nil) private var timeObserver: Any? private var isFirstPlay = true private var isSeeking = false @@ -163,9 +162,7 @@ public class ApiVideoPlayerController: NSObject { name: .AVPlayerItemDidPlayToEndTime, object: playerItem ) - if let urlAsset = playerItem.asset as? AVURLAsset { - self.setUpAnalytics(url: urlAsset.url.absoluteString) - } + } private func notifyError(error: Error) { @@ -209,15 +206,6 @@ public class ApiVideoPlayerController: NSObject { player.removeTimeObserver(observer) } - private func setUpAnalytics(url: String) { - do { - let option = try Options(mediaUrl: url) - self.analytics = PlayerAnalytics(options: option) - } catch { - print("Failed to initiate analytics for \(url)") - } - } - /// Get if the player is playing a live stream. /// - Returns: True if the player is playing a live stream public var isLive: Bool { @@ -253,16 +241,6 @@ public class ApiVideoPlayerController: NSObject { private func seekImpl(to time: CMTime, completion: @escaping (Bool) -> Void) { let from = self.currentTime self.player.seek(to: time, toleranceBefore: .zero, toleranceAfter: .zero) { completed in - self.analytics? - .seek( - from: Float(max(0, from.seconds)), - to: Float(max(0, time.seconds)) - ) { result in - switch result { - case .success: break - case let .failure(error): print("Failed to send seek event to analytics: \(error)") - } - } self.infoNowPlaying.updateCurrentTime(currentTime: time) completion(completed) } @@ -514,12 +492,6 @@ public class ApiVideoPlayerController: NSObject { self.replay() self.multicastDelegate.didLoop() } - self.analytics?.end { result in - switch result { - case .success: break - case let .failure(error): print("Failed to send end event to analytics: \(error)") - } - } self.multicastDelegate.didEnd() } @@ -578,12 +550,6 @@ public class ApiVideoPlayerController: NSObject { if self.autoplay { self.play() } - self.analytics?.ready { result in - switch result { - case .success: break - case let .failure(error): print("Failed to send ready event to analytics: \(error)") - } - } } } @@ -596,12 +562,6 @@ public class ApiVideoPlayerController: NSObject { return } - self.analytics?.pause { result in - switch result { - case .success: break - case let .failure(error): print("Failed to send pause event to analytics: \(error)") - } - } self.infoNowPlaying.pause(currentTime: self.currentTime) self.multicastDelegate.didPause() } @@ -623,19 +583,7 @@ public class ApiVideoPlayerController: NSObject { ) #endif - self.analytics?.play { result in - switch result { - case .success: break - case let .failure(error): print("Failed to send play event to analytics: \(error)") - } - } } else { - self.analytics?.resume { result in - switch result { - case .success: break - case let .failure(error): print("Failed to send resume event to analytics: \(error)") - } - } self.infoNowPlaying.play(currentTime: self.currentTime) } #if !os(macOS)