Skip to content

Commit

Permalink
fix: Simulator Crash for Non-DRM Video Playback
Browse files Browse the repository at this point in the history
- Currently, we initialize the AVContentKeySession even for non-DRM videos. This causes issues when attempting to play non-DRM videos in the simulator, as the content key session cannot be initialized on the simulator. Consequently, this results in a crash during playback.
- This is fixed by initialization AVContentKeySession only when the Asset is DRM-encrypted, so the app won't crash while playing non-DRM content in Simulator.
  • Loading branch information
harinath01 committed Jan 18, 2024
1 parent 2a3e261 commit 75fbce0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions Source/Network/Models/Asset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ struct Asset {
let playbackURL: String
let status: String
let duration: Double
let drm_encrypted: Bool
}
}
10 changes: 8 additions & 2 deletions Source/Network/StreamsAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,20 @@ class StreamsAPI: BaseAPI {
let title = responseDict["title"] as? String,
let playbackURL = video["playback_url"] as? String,
let duration = video["duration"] as? Double,
let status = video["status"] as? String else {
let status = video["status"] as? String,
let content_protection_type = video["content_protection_type"] as? String else {
throw NSError(domain: "InvalidResponseError", code: 0)
}

return Asset(
id: id,
title: title,
video: Asset.Video(playbackURL: playbackURL, status: status, duration: duration)
video: Asset.Video(
playbackURL: playbackURL,
status: status,
duration: duration,
drm_encrypted: content_protection_type == "drm"
)
)
}
}
5 changes: 3 additions & 2 deletions Source/Network/TestpressAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ class TestpressAPI: BaseAPI {
let title = responseDict["title"] as? String,
let playbackURL = responseDict["hls_url"] as? String ?? responseDict["url"] as? String,
let duration = responseDict["duration"] as? Double,
let status = responseDict["transcoding_status"] as? String else {
let status = responseDict["transcoding_status"] as? String,
let drm_encrypted = responseDict["drm_enabled"] as? Bool else {
throw NSError(domain: "InvalidResponseError", code: 0)
}
let video = Asset.Video(playbackURL: playbackURL, status: status, duration: duration)
let video = Asset.Video(playbackURL: playbackURL, status: status, duration: duration, drm_encrypted: drm_encrypted)
return Asset(id: id, title: title, video: video)
}
}
5 changes: 4 additions & 1 deletion Source/TPAVPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ public class TPAVPlayer: AVPlayer {
let avURLAsset = AVURLAsset(url: url)
avURLAsset.resourceLoader.setDelegate(resourceLoaderDelegate, queue: DispatchQueue.main)
self.setPlayerItem(avURLAsset)
self.setupDRM(avURLAsset)

if asset.video.drm_encrypted{
self.setupDRM(avURLAsset)
}
self.populateAvailableVideoQualities(url)
}

Expand Down

0 comments on commit 75fbce0

Please sign in to comment.