Skip to content

Commit

Permalink
Merge pull request #19 from apivideo/fix/player-analytics
Browse files Browse the repository at this point in the history
Fix/player analytics
  • Loading branch information
ThibaultBee authored Mar 23, 2023
2 parents 88b3f7b + 2cd156d commit 0ed758d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 26 deletions.
2 changes: 1 addition & 1 deletion ApiVideoPlayer.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
],
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
37 changes: 15 additions & 22 deletions Sources/ApiVideoPlayer/ApiVideoPlayerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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] = [],
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand All @@ -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(
Expand Down Expand Up @@ -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)")
}
}
}
}

Expand Down Expand Up @@ -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)")
}
}
Expand Down

0 comments on commit 0ed758d

Please sign in to comment.