Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Offline DRM: Minimal update for Swift Concurrency migration (#147)" #148

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 10 additions & 21 deletions JWBestPracticeApps/Offline DRM/Offline DRM/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,39 +54,20 @@ class ViewController: UIViewController, AVAssetDownloadDelegate {
/// An observer to track the download progress.
var progressObserver: NSKeyValueObservation?

override func viewDidLoad() {
super.viewDidLoad()
// Create the configuration for the AVAssetDownloadURLSession.
let backgroundConfiguration = URLSessionConfiguration.background(withIdentifier: "AAPL-Identifier")
assetDownloadURLSession = AVAssetDownloadURLSession(configuration: backgroundConfiguration,
assetDownloadDelegate: self, delegateQueue: delegateQueue)
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)

// It's safe to sping this off in an unstructured Task because all work prior to this (in viewDidLoad) is synchronous.
Task(priority: .userInitiated) {
// NOTE: This app demonstrates best practices with regards to Offline DRM implementation, NOT with
// implementing Swift Concurrency integration, which would require bridging Apple's `AVContentKeySessionDelegate`
// methods as a starting point.
await setupPlayer()
}
}

private func setupPlayer() async {
// The keys can be pre-loaded by calling load on the content loader.
guard let url = URL(string: playlistURL) else {
print("Cannot initialize player because playlistURL is invalid. URL:'\(playlistURL)'")
return
}
contentLoader = JWDRMContentLoader(dataSource: keyDataSource, keyManager: keyManager)
await self.contentLoader?.load(playlist: url)
self.contentLoader?.load(playlist: url)

// We construct a playlist either from the remote asset or a local asset if it is saved.
var config: JWPlayerConfiguration!

if let localURL {
if let localURL = localURL {
config = self.getPlaylist(local: localURL)
// Updates the UI to reflect that the asset is already downloaded.
stateLabel?.text = "Saved"
Expand All @@ -99,6 +80,14 @@ class ViewController: UIViewController, AVAssetDownloadDelegate {
self.player?.configurePlayer(with: config)
}

override func viewDidLoad() {
super.viewDidLoad()
// Create the configuration for the AVAssetDownloadURLSession.
let backgroundConfiguration = URLSessionConfiguration.background(withIdentifier: "AAPL-Identifier")
assetDownloadURLSession = AVAssetDownloadURLSession(configuration: backgroundConfiguration,
assetDownloadDelegate: self, delegateQueue: delegateQueue)
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
guard let playerViewController = segue.destination as? JWPlayerViewController else {
return
Expand Down