From 5bcb097d51f6c01752aa0676685170e54c840487 Mon Sep 17 00:00:00 2001 From: Romain Petit Date: Thu, 23 Mar 2023 15:50:39 +0100 Subject: [PATCH 1/5] chore() delete unused 'getVideUrl' method --- .../ApiVideoPlayerController.swift | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/Sources/ApiVideoPlayer/ApiVideoPlayerController.swift b/Sources/ApiVideoPlayer/ApiVideoPlayerController.swift index 8f4d0766..2a797b5b 100644 --- a/Sources/ApiVideoPlayer/ApiVideoPlayerController.swift +++ b/Sources/ApiVideoPlayer/ApiVideoPlayerController.swift @@ -72,24 +72,6 @@ public class ApiVideoPlayerController: NSObject { ) } - private func getVideoUrl(videoOptions: VideoOptions) -> String { - let privateToken: String? = nil - var baseUrl = "" - if videoOptions.videoType == .vod { - baseUrl = "https://cdn.api.video/vod/" - } else { - baseUrl = "https://live.api.video/" - } - var url: String! - - if let privateToken = privateToken { - url = baseUrl + "\(videoOptions.videoId)/token/\(privateToken)/player.json" - } else { - url = baseUrl + "\(videoOptions.videoId)/player.json" - } - return url - } - private func retrySetUpPlayerUrlWithMp4() { self.playerItemFactory?.getMp4PlayerItem { currentItem in self.preparePlayer(playerItem: currentItem) From 51f18e4e9e8b5b8ad39b5a589bf9ea617fe43c72 Mon Sep 17 00:00:00 2001 From: Romain Petit Date: Thu, 23 Mar 2023 15:52:20 +0100 Subject: [PATCH 2/5] feat() add analytics --- .../ApiVideoPlayerController.swift | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/Sources/ApiVideoPlayer/ApiVideoPlayerController.swift b/Sources/ApiVideoPlayer/ApiVideoPlayerController.swift index 2a797b5b..a6e5dadc 100644 --- a/Sources/ApiVideoPlayer/ApiVideoPlayerController.swift +++ b/Sources/ApiVideoPlayer/ApiVideoPlayerController.swift @@ -43,7 +43,8 @@ public class ApiVideoPlayerController: NSObject { /// - videoOptions: The video to play. /// - delegates: The delegates of the player events. /// - autoplay: True to play the video when it has been loaded, false to wait for an explicit play. - /// - taskExecutor: The executor for the calls to the private session endpoint. Only for test purpose. Default is``TasksExecutor``. + /// - taskExecutor: The executor for the calls to the private session endpoint. Only for test purpose. Default + /// is``TasksExecutor``. public init( videoOptions: VideoOptions?, delegates: [PlayerDelegate] = [], @@ -75,6 +76,9 @@ public class ApiVideoPlayerController: NSObject { private func retrySetUpPlayerUrlWithMp4() { self.playerItemFactory?.getMp4PlayerItem { currentItem in self.preparePlayer(playerItem: currentItem) + if let urlAsset = currentItem.asset as? AVURLAsset { + self.setUpAnalytics(url: urlAsset.url.absoluteString) + } } } @@ -146,7 +150,8 @@ public class ApiVideoPlayerController: NSObject { /// Requests invocation of a block during playback to report changing time. /// /// - Parameter callback: The block to be invoked periodically during playback. - /// - Returns: You must retain this returned value as long as you want the time observer to be invoked by the player. + /// - Returns: You must retain this returned value as long as you want the time observer to be invoked by the + /// player. public func addTimerObserver(callback: @escaping () -> Void) -> Any { let interval = CMTime(seconds: 0.1, preferredTimescale: CMTimeScale(NSEC_PER_SEC)) return avPlayer.addPeriodicTimeObserver( @@ -274,6 +279,9 @@ public class ApiVideoPlayerController: NSObject { playerItemFactory?.delegate = self playerItemFactory?.getHlsPlayerItem { currentItem in self.preparePlayer(playerItem: currentItem) + if let urlAsset = currentItem.asset as? AVURLAsset { + self.setUpAnalytics(url: urlAsset.url.absoluteString) + } } } } @@ -453,6 +461,12 @@ public class ApiVideoPlayerController: NSObject { if self.autoplay { self.play() } + self.analytics?.ready { result in + switch result { + case .success: break + case let .failure(error): print("analytics error ready event: \(error)") + } + } } } @@ -483,14 +497,14 @@ public class ApiVideoPlayerController: NSObject { self.isFirstPlay = false self.analytics?.play { result in switch result { - case .success: return + case .success: break case let .failure(error): print("analytics error on play event: \(error)") } } } else { self.analytics?.resume { result in switch result { - case .success: return + case .success: break case let .failure(error): print("analytics error on resume event: \(error)") } } From f4c26b2cb97ca25e6adfeeb0b3bcf5ac51dbc8ef Mon Sep 17 00:00:00 2001 From: Romain Petit Date: Thu, 23 Mar 2023 17:10:34 +0100 Subject: [PATCH 3/5] chore() upgrade player-analytics lib --- .../project.xcworkspace/xcshareddata/swiftpm/Package.resolved | 4 ++-- Package.swift | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Examples/ExampleUIKit/ExampleUIKit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Examples/ExampleUIKit/ExampleUIKit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index e8c83596..ff69920f 100644 --- a/Examples/ExampleUIKit/ExampleUIKit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Examples/ExampleUIKit/ExampleUIKit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -32,8 +32,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apivideo/api.video-ios-player-analytics", "state" : { - "revision" : "c34d58405161c8055ee14b33af7a06ff4e55d00a", - "version" : "1.0.4" + "revision" : "1d479316c75de5045dc12e471351e70a55f32270", + "version" : "1.0.5" } } ], diff --git a/Package.swift b/Package.swift index 91aa6c5c..2a6729f8 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-ios-player-analytics", from: "1.0.4"), + .package(url: "https://github.com/apivideo/api.video-ios-player-analytics", from: "1.0.5"), .package(url: "https://github.com/apivideo/api.video-ios-client", from: "1.1.1") ], targets: [ From 4cbcf0fc5013ad8a93f37232a281d03e55487779 Mon Sep 17 00:00:00 2001 From: Romain Petit Date: Thu, 23 Mar 2023 17:33:43 +0100 Subject: [PATCH 4/5] fix() setup analytics in 'preparePlayer' method --- Sources/ApiVideoPlayer/ApiVideoPlayerController.swift | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Sources/ApiVideoPlayer/ApiVideoPlayerController.swift b/Sources/ApiVideoPlayer/ApiVideoPlayerController.swift index a6e5dadc..7a1e602e 100644 --- a/Sources/ApiVideoPlayer/ApiVideoPlayerController.swift +++ b/Sources/ApiVideoPlayer/ApiVideoPlayerController.swift @@ -76,9 +76,6 @@ public class ApiVideoPlayerController: NSObject { private func retrySetUpPlayerUrlWithMp4() { self.playerItemFactory?.getMp4PlayerItem { currentItem in self.preparePlayer(playerItem: currentItem) - if let urlAsset = currentItem.asset as? AVURLAsset { - self.setUpAnalytics(url: urlAsset.url.absoluteString) - } } } @@ -127,6 +124,9 @@ 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) { @@ -279,9 +279,6 @@ public class ApiVideoPlayerController: NSObject { playerItemFactory?.delegate = self playerItemFactory?.getHlsPlayerItem { currentItem in self.preparePlayer(playerItem: currentItem) - if let urlAsset = currentItem.asset as? AVURLAsset { - self.setUpAnalytics(url: urlAsset.url.absoluteString) - } } } } From 2cd156d4be8a3da5d5fee109a24d1452814c1949 Mon Sep 17 00:00:00 2001 From: Romain Petit Date: Thu, 23 Mar 2023 17:35:43 +0100 Subject: [PATCH 5/5] chore() upgrade cocoapods analytics lib --- ApiVideoPlayer.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ApiVideoPlayer.podspec b/ApiVideoPlayer.podspec index ee9fb68d..b612485c 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.0.4" + s.dependency "ApiVideoPlayerAnalytics", "1.0.5" end