Skip to content

Commit

Permalink
refactor: Remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthieu-dgl committed Oct 17, 2024
1 parent 5d107f9 commit 696ce86
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions kDrive/UI/View/Files/Preview/VideoCollectionViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class VideoCollectionViewCell: PreviewCollectionViewCell {

private var playableFileName: String?

private var currentVideoMetadata: MediaMetadata?
private var previewDownloadTask: Kingfisher.DownloadTask?
private var file: File!
private var player: AVPlayer? {
Expand All @@ -56,6 +55,12 @@ class VideoCollectionViewCell: PreviewCollectionViewCell {
override func awakeFromNib() {
super.awakeFromNib()
playButton.accessibilityLabel = KDriveResourcesStrings.Localizable.buttonPlayerPlayPause
NotificationCenter.default.addObserver(
self,
selector: #selector(playerDidPlayToEnd),
name: .AVPlayerItemDidPlayToEndTime,
object: player?.currentItem
)
}

override func prepareForReuse() {
Expand Down Expand Up @@ -100,13 +105,15 @@ class VideoCollectionViewCell: PreviewCollectionViewCell {
MatomoUtils.trackMediaPlayer(leaveAt: player?.progressPercentage)
}

@objc private func playerDidPlayToEnd() {
setNowPlayingMetadata()
}

@IBAction func playVideoPressed(_ sender: Any) {
guard let player else { return }

MatomoUtils.trackMediaPlayer(playMedia: .video)

setNowPlayingMetadata()

let playerViewController = AVPlayerViewController()
playerViewController.player = player

Expand All @@ -130,6 +137,10 @@ class VideoCollectionViewCell: PreviewCollectionViewCell {
floatingPanelController?.dismiss(animated: true)
parentViewController?.present(navController, animated: true) {
playerViewController.player?.play()
let interval = CMTime(seconds: 1.0, preferredTimescale: CMTimeScale(NSEC_PER_SEC))
player.addPeriodicTimeObserver(forInterval: interval, queue: .main) { [weak self] _ in
self?.setNowPlayingMetadata()
}
}
}

Expand All @@ -138,18 +149,7 @@ class VideoCollectionViewCell: PreviewCollectionViewCell {

nowPlayingInfo[MPNowPlayingInfoPropertyMediaType] = MPNowPlayingInfoMediaType.video.rawValue
nowPlayingInfo[MPNowPlayingInfoPropertyIsLiveStream] = false

if let currentVideoMetadata {
nowPlayingInfo[MPMediaItemPropertyTitle] = currentVideoMetadata.title
nowPlayingInfo[MPMediaItemPropertyArtist] = currentVideoMetadata.artist

if let artwork = currentVideoMetadata.artwork {
let artworkItem = MPMediaItemArtwork(boundsSize: artwork.size) { _ in artwork }
nowPlayingInfo[MPMediaItemPropertyArtwork] = artworkItem
}
} else {
nowPlayingInfo[MPMediaItemPropertyTitle] = playableFileName ?? ""
}
nowPlayingInfo[MPMediaItemPropertyTitle] = playableFileName

if let player = player, let currentItem = player.currentItem {
nowPlayingInfo[MPMediaItemPropertyPlaybackDuration] = CMTimeGetSeconds(currentItem.asset.duration)
Expand Down

0 comments on commit 696ce86

Please sign in to comment.