Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
PruthiviRaj27 committed Jan 9, 2024
1 parent 1eb6230 commit 4258ed7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
7 changes: 7 additions & 0 deletions Source/Network/Models/Asset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,10 @@ struct Asset {
let status: String
}
}

extension Asset {
func isDownloaded() -> Bool {
let offlineAsset = OfflineAsset.manager.get(assetId: self.id)
return offlineAsset != nil
}
}
6 changes: 6 additions & 0 deletions Source/Offline/Model/OfflineAsset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ extension OfflineAsset {
}
}
}

internal static func create(assetId: String, srcURL: String) -> OfflineAsset {
let offlineAsset.assetId = asset.id
offlineAsset.srcURL = asset.video.playbackURL
return offlineAsset
}
}

enum Status: String {
Expand Down
20 changes: 4 additions & 16 deletions Source/Offline/TPStreamsDownloadManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,34 +31,22 @@ public final class TPStreamsDownloadManager {

internal func startDownload(asset: Asset, bitRate: Int) {

if isDownloaded(asset: asset){
print("\(asset.id) Asset already downloaded or in progress")
return
}
if asset.isDownloaded() { return}

let avUrlAsset = AVURLAsset(url: URL(string: asset.video.playbackURL)!)
guard let avUrlAsset = AVURLAsset(url: URL(string: asset.video.playbackURL)) else { return }

guard let task = assetDownloadURLSession.makeAssetDownloadTask(
asset: avUrlAsset,
assetTitle: asset.title,
assetArtworkData: nil,
options: [AVAssetDownloadTaskMinimumRequiredMediaBitrateKey: bitRate]
) else {
return
}
) else { return }

let offlineAsset = OfflineAsset()
offlineAsset.assetId = asset.id
offlineAsset.srcURL = asset.video.playbackURL
let offlineAsset = OfflineAsset.create(assetId: asset.id, srcURL: asset.video.playbackURL)
OfflineAsset.manager.add(object: offlineAsset)
offlineAssetDownloadManager.activeDownloadsMap[task] = offlineAsset
task.resume()
}

private func isDownloaded(asset: Asset) -> Bool {
let offlineAsset = OfflineAsset.manager.get(assetId: asset.id)
return offlineAsset != nil
}

}

Expand Down

0 comments on commit 4258ed7

Please sign in to comment.