Skip to content

Commit

Permalink
Apply code style
Browse files Browse the repository at this point in the history
  • Loading branch information
wuyuehyang authored and fanyu committed Nov 16, 2021
1 parent be79681 commit b4a5644
Showing 1 changed file with 28 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ extension GalleryVideoItemViewController {
playerDidReachEnd = false
player.seek(to: .zero)
}
Logger.general.info(category: "GalleryVideoItemViewController", message: "Playing video")
player.play()
} else if let url = item.url {
controlView.style.insert(.loading)
Expand Down Expand Up @@ -570,13 +571,13 @@ extension GalleryVideoItemViewController {
updateControlView(playControlsHidden: false, otherControlsHidden: false, animated: true)
removeTimeObservers()
AudioSession.shared.deactivateAsynchronously(client: self, notifyOthersOnDeactivation: false)
let message: String
let errorDescription: String
if let error = notification.userInfo?[AVPlayerItemFailedToPlayToEndTimeErrorKey] as? Error {
message = error.localizedDescription
errorDescription = error.localizedDescription
} else {
message = ""
errorDescription = "(null)"
}
Logger.general.error(category: "GalleryVideoItemViewController", message: "Player item failed to play to end time: \(message)")
Logger.general.error(category: "GalleryVideoItemViewController", message: "Player item failed to play to end time: \(errorDescription)")
}

@objc private func playerItemNewErrorLogEntry(_ notification: Notification) {
Expand Down Expand Up @@ -657,6 +658,7 @@ extension GalleryVideoItemViewController {
func showReloadAndReport(error: Error?) {
if let error = error {
reporter.report(error: error)
Logger.general.error(category: "GalleryVideoItemViewController", message: "Failed to load asset: \(error)")
}
controlView.style.remove(.loading)
controlView.playControlStyle = .reload
Expand Down Expand Up @@ -688,30 +690,41 @@ extension GalleryVideoItemViewController {
private func load(playableAsset asset: AVURLAsset, playAfterLoaded: Bool) {
guard asset.isPlayable else {
// TODO: UI Update
Logger.general.error(category: "GalleryVideoItemViewController", message: "Asset is not playable")
return
}
removeAllObservers()

let item = AVPlayerItem(asset: asset)
itemStatusObserver = item.observe(\.status, options: [.initial, .new]) { [weak self] (item, change) in
// Known issue: https://bugs.swift.org/browse/SR-5872
// 'change' are always nil here
// 'change' is always nil here
self?.updateControlView()
if case .failed = item.status, let error = item.error {
Logger.general.error(category: "GalleryVideoItemViewController", message: "Player item can no longer be played because of an error: \(error)")
} else if case .unknown = item.status {
Logger.general.error(category: "GalleryVideoItemViewController", message: "Player item has not tried to load new media resources for playback")
switch item.status {
case .readyToPlay:
break
case .failed:
Logger.general.error(category: "GalleryVideoItemViewController", message: "Player item failed: \(item.error?.localizedDescription ?? "(null)")")
case .unknown:
Logger.general.info(category: "GalleryVideoItemViewController", message: "Player item becomes unknown")
@unknown default:
Logger.general.info(category: "GalleryVideoItemViewController", message: "Player item status: \(item.status.rawValue)")
}
}
itemPresentationSizeObserver = item.observe(\.presentationSize) { [weak self] (item, _) in
self?.updateVideoViewSize(with: item)
}

playerStatusObserver = player.observe(\.status, options: [.initial, .new]) { player, _ in
if case .failed = player.status, let error = player.error {
Logger.general.error(category: "GalleryVideoItemViewController", message: "Player can no longer play AVPlayerItem instances because of an error: \(error)")
} else if case .unknown = player.status {
Logger.general.error(category: "GalleryVideoItemViewController", message: "Player has not tried to load new media resources for playback")
switch player.status {
case .readyToPlay:
break
case .failed:
Logger.general.error(category: "GalleryVideoItemViewController", message: "Player failed: \(player.error?.localizedDescription ?? "(null)")")
case .unknown:
Logger.general.info(category: "GalleryVideoItemViewController", message: "Player becomes unknown")
@unknown default:
Logger.general.info(category: "GalleryVideoItemViewController", message: "Player status: \(player.status.rawValue)")
}
}

Expand Down Expand Up @@ -750,6 +763,7 @@ extension GalleryVideoItemViewController {
Logger.general.error(category: "GalleryVideoItemViewController", message: "AudioSession activate error: \(error)")
}
player.isMuted = mute
Logger.general.info(category: "GalleryVideoItemViewController", message: "Playing video")
player.play()
}
}
Expand Down

0 comments on commit b4a5644

Please sign in to comment.