Use Swift 5.7 if-let style

This commit is contained in:
Arkadiusz Fal
2022-09-28 16:27:01 +02:00
parent 8f96a7c5e0
commit a086a0f440
50 changed files with 114 additions and 114 deletions

View File

@@ -211,7 +211,7 @@ final class AVPlayerBackend: PlayerBackend {
model: PlayerModel
) {
asset.loadValuesAsynchronously(forKeys: Self.assetKeysToLoad) { [weak self] in
guard let self = self else {
guard let self else {
return
}
model.logger.info("loading \(type.rawValue) track")
@@ -285,7 +285,7 @@ final class AVPlayerBackend: PlayerBackend {
guard let item = self.model.playerItem, self.isAutoplaying(item) else { return }
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { [weak self] in
guard let self = self else {
guard let self else {
return
}
@@ -361,7 +361,7 @@ final class AVPlayerBackend: PlayerBackend {
}
private func playerItem(_: Stream) -> AVPlayerItem? {
if let asset = asset {
if let asset {
return AVPlayerItem(asset: asset)
} else {
return AVPlayerItem(asset: composition)
@@ -380,7 +380,7 @@ final class AVPlayerBackend: PlayerBackend {
if let thumbnailURL = video.thumbnailURL(quality: .medium) {
let task = URLSession.shared.dataTask(with: thumbnailURL) { [weak self] thumbnailData, _, _ in
guard let thumbnailData = thumbnailData else { return }
guard let thumbnailData else { return }
let image = UIImage(data: thumbnailData)
if let pngData = image?.pngData() {
@@ -425,7 +425,7 @@ final class AVPlayerBackend: PlayerBackend {
private func observePlayerItemStatus(_ item: AVPlayerItem) {
statusObservation?.invalidate()
statusObservation = item.observe(\.status, options: [.old, .new]) { [weak self] playerItem, _ in
guard let self = self else {
guard let self else {
return
}
@@ -507,7 +507,7 @@ final class AVPlayerBackend: PlayerBackend {
forInterval: interval,
queue: .main
) { [weak self] _ in
guard let self = self, self.model.activeBackend == .appleAVPlayer else {
guard let self, self.model.activeBackend == .appleAVPlayer else {
return
}
@@ -551,7 +551,7 @@ final class AVPlayerBackend: PlayerBackend {
forInterval: interval,
queue: .main
) { [weak self] _ in
guard let self = self else {
guard let self else {
return
}
@@ -567,7 +567,7 @@ final class AVPlayerBackend: PlayerBackend {
private func addPlayerTimeControlStatusObserver() {
playerTimeControlStatusObserver = avPlayer.observe(\.timeControlStatus) { [weak self] player, _ in
guard let self = self,
guard let self,
self.avPlayer == player,
self.model.activeBackend == .appleAVPlayer
else {

View File

@@ -22,7 +22,7 @@ final class MPVBackend: PlayerBackend {
var stream: Stream?
var video: Video?
var captions: Captions? { didSet {
guard let captions = captions else {
guard let captions else {
client.removeSubs()
return
}
@@ -33,7 +33,7 @@ final class MPVBackend: PlayerBackend {
var loadedVideo = false
var isLoadingVideo = true { didSet {
DispatchQueue.main.async { [weak self] in
guard let self = self else {
guard let self else {
return
}
@@ -71,7 +71,7 @@ final class MPVBackend: PlayerBackend {
var isSeeking = false {
didSet {
DispatchQueue.main.async { [weak self] in
guard let self = self else { return }
guard let self else { return }
self.model.isSeeking = self.isSeeking
}
}
@@ -187,7 +187,7 @@ final class MPVBackend: PlayerBackend {
#endif
DispatchQueue.main.async { [weak self] in
guard let self = self else {
guard let self else {
return
}
@@ -213,14 +213,14 @@ final class MPVBackend: PlayerBackend {
}
let replaceItem: (CMTime?) -> Void = { [weak self] time in
guard let self = self else {
guard let self else {
return
}
self.stop()
DispatchQueue.main.async { [weak self] in
guard let self = self else {
guard let self else {
return
}
@@ -345,7 +345,7 @@ final class MPVBackend: PlayerBackend {
model.updateNowPlayingInfo()
handleSegmentsThrottle.execute {
if let currentTime = currentTime {
if let currentTime {
model.handleSegments(at: currentTime)
}
}
@@ -453,7 +453,7 @@ final class MPVBackend: PlayerBackend {
}
func updateNetworkState() {
guard let client = client, let networkState = networkState else {
guard let client, let networkState else {
return
}

View File

@@ -29,7 +29,7 @@ final class MPVClient: ObservableObject {
func create(frame: CGRect? = nil) {
#if !os(macOS)
if let frame = frame {
if let frame {
glView = MPVOGLView(frame: frame)
}
#endif
@@ -134,7 +134,7 @@ final class MPVClient: ObservableObject {
var args = [url.absoluteString]
var options = [String]()
if let time = time {
if let time {
args.append("replace")
options.append("start=\(Int(time.seconds))")
}
@@ -268,7 +268,7 @@ final class MPVClient: ObservableObject {
}
DispatchQueue.main.async { [weak self] in
guard let self = self, let model = self.backend.model else { return }
guard let self, let model = self.backend.model else { return }
UIView.animate(withDuration: 0.2, animations: {
let aspectRatio = self.aspectRatio > 0 && self.aspectRatio < VideoPlayerView.defaultAspectRatio ? self.aspectRatio : VideoPlayerView.defaultAspectRatio
let height = [model.playerSize.height, model.playerSize.width / aspectRatio].min()!

View File

@@ -79,7 +79,7 @@ extension PlayerBackend {
}
func seek(relative time: CMTime, seekType: SeekType, completionHandler: ((Bool) -> Void)? = nil) {
if let currentTime = currentTime, let duration = playerItemDuration {
if let currentTime, let duration = playerItemDuration {
let seekTime = min(max(0, currentTime.seconds + time.seconds), duration.seconds)
model.seek.registerSeek(at: .secondsInDefaultTimescale(seekTime), type: seekType, restore: currentTime)
seek(to: seekTime, seekType: seekType, completionHandler: completionHandler)