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 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: [ diff --git a/Sources/ApiVideoPlayer/ApiVideoPlayerController.swift b/Sources/ApiVideoPlayer/ApiVideoPlayerController.swift index 2a831543..ef2aea95 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: [ApiVideoPlayerControllerPlayerDelegate] = [], @@ -72,24 +73,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) @@ -141,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) { @@ -164,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( @@ -471,6 +458,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)") + } + } } } @@ -501,14 +494,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)") } }