From b8d3c87ae96715e849e896bf90c0b03de387dfbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthieu=20D=C3=A9glon?= Date: Mon, 18 Nov 2024 14:27:04 +0100 Subject: [PATCH] fix: Stop playback when you leave the player --- kDrive/UI/View/Files/Preview/VideoCollectionViewCell.swift | 2 ++ kDriveCore/VideoPlayer/VideoPlayer.swift | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/kDrive/UI/View/Files/Preview/VideoCollectionViewCell.swift b/kDrive/UI/View/Files/Preview/VideoCollectionViewCell.swift index 0faa04d28..3b1a22e96 100644 --- a/kDrive/UI/View/Files/Preview/VideoCollectionViewCell.swift +++ b/kDrive/UI/View/Files/Preview/VideoCollectionViewCell.swift @@ -54,6 +54,7 @@ class VideoCollectionViewCell: PreviewCollectionViewCell { override func prepareForReuse() { super.prepareForReuse() + videoPlayer?.stopPlayback() previewFrameImageView.image = nil previewDownloadTask?.cancel() } @@ -97,6 +98,7 @@ class VideoCollectionViewCell: PreviewCollectionViewCell { let navController = VideoPlayerNavigationController(rootViewController: playerViewController) navController.disappearCallback = { [weak self] in MatomoUtils.track(eventWithCategory: .mediaPlayer, name: "pause") + self?.videoPlayer?.stopPlayback() self?.presentFloatingPanel() } navController.setNavigationBarHidden(true, animated: false) diff --git a/kDriveCore/VideoPlayer/VideoPlayer.swift b/kDriveCore/VideoPlayer/VideoPlayer.swift index 7d4842885..c2e1f6237 100644 --- a/kDriveCore/VideoPlayer/VideoPlayer.swift +++ b/kDriveCore/VideoPlayer/VideoPlayer.swift @@ -143,4 +143,8 @@ public final class VideoPlayer { } return MediaMetadata(title: title, artist: artist, artwork: artwork) } + + public func stopPlayback() { + player?.pause() + } }