Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Nextcloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -6303,7 +6303,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 4;
CURRENT_PROJECT_VERSION = 5;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = NKUJUXUJ3B;
Expand Down Expand Up @@ -6371,7 +6371,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 4;
CURRENT_PROJECT_VERSION = 5;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = NKUJUXUJ3B;
Expand Down
12 changes: 12 additions & 0 deletions iOSClient/Images.xcassets/Vlc-Logo.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "Vlc-Logo.svg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
10 changes: 10 additions & 0 deletions iOSClient/Images.xcassets/Vlc-Logo.imageset/Vlc-Logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions iOSClient/Settings/NCPreferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,37 @@ final class NCPreferences: NSObject {
setUserDefaults(weekString, forKey: "cleaningWeek")
}

// MARK: - Video

func alwaysUseVLCForVideo(account: String, ocId: String) -> Bool {
let key = alwaysUseVLCForVideoKey(
account: account,
ocId: ocId
)

return UserDefaults.standard.object(forKey: key) as? Bool == true
}

func setAlwaysUseVLCForVideo(_ value: Bool, account: String, ocId: String) {
let key = alwaysUseVLCForVideoKey(
account: account,
ocId: ocId
)

if value {
UserDefaults.standard.set(true, forKey: key)
} else {
UserDefaults.standard.removeObject(forKey: key)
}
}

private func alwaysUseVLCForVideoKey(
account: String,
ocId: String
) -> String {
"Preferences_alwaysUseVLCForVideo_\(account)|\(ocId)"
}

// MARK: -

private func migrate(key: String) {
Expand Down
2 changes: 2 additions & 0 deletions iOSClient/Supporting Files/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,8 @@
"_no_assistant_installed_" = "Assistant is not installed on this server. Ask your administrator to install the Assistant app";
"_open_in_office_" = "Open in Office";
"_select_date_" = "Select date";
"_play_with_vlc_" = "Play with VLC";
"_always_play_with_vlc_" = "Always play with VLC";

// Tip
"_tip_pdf_thumbnails_" = "Swipe left from the right edge of the screen to show the thumbnails";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ final class NCVideoPlaybackController: ObservableObject {
private var currentOcId: String?
private var currentEtag: String?
private var currentURL: URL?
private var currentFileName: String?
private var currentUserAgent: String?
private var loadToken = UUID()

private init() { }
Expand Down Expand Up @@ -94,7 +94,7 @@ final class NCVideoPlaybackController: ObservableObject {
currentOcId = metadata.ocId
currentEtag = metadata.etag
currentURL = url
currentFileName = fileName
currentUserAgent = userAgent
engine = .loading

if url.isFileURL,
Expand All @@ -105,6 +105,15 @@ final class NCVideoPlaybackController: ObservableObject {

configureAudioSession()

if NCPreferences().alwaysUseVLCForVideo(account: metadata.account, ocId: metadata.ocId) {
resolveWithVLC(
url: url,
userAgent: userAgent,
token: token
)
return
}

if shouldUseVLCWithoutAVFoundation(
url: url,
fileName: fileName
Expand All @@ -118,21 +127,67 @@ final class NCVideoPlaybackController: ObservableObject {
}

prepareAVFoundation(
metadata: metadata,
url: url,
userAgent: userAgent,
httpHeaders: url.isFileURL ? [:] : httpHeaders,
token: token
)
}

// Changes only the prepared engine. Playback still starts from the cover.
func switchToVLC() {
guard let currentURL else {
return
}

resolveWithVLC(
url: currentURL,
userAgent: currentUserAgent,
token: loadToken
)
}

func retryAVFoundation() {
guard let currentURL else {
return
}

let token = UUID()
loadToken = token

statusObservation?.invalidate()
statusObservation = nil

avProbePlayer?.pause()
avProbePlayer = nil
avProbeItem = nil

engine = .loading

var httpHeaders: [String: String] = [:]

if let currentUserAgent,
!currentUserAgent.isEmpty,
!currentURL.isFileURL {
httpHeaders["User-Agent"] = currentUserAgent
}

prepareAVFoundation(
url: currentURL,
userAgent: currentUserAgent,
httpHeaders: httpHeaders,
token: token
)
}

func stopIfCurrent(ocId: String) {
guard currentOcId == ocId else {
return
}

stop()
}

// Releases the current prepared playback state and pending AVFoundation probes.
func stop() {
loadToken = UUID()
Expand All @@ -147,15 +202,13 @@ final class NCVideoPlaybackController: ObservableObject {
currentOcId = nil
currentEtag = nil
currentURL = nil
currentFileName = nil

currentUserAgent = nil
engine = .loading
}

// MARK: - AVFoundation

private func prepareAVFoundation(
metadata: tableMetadata,
url: URL,
userAgent: String?,
httpHeaders: [String: String],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ enum NCVideoVLCPresenter {
return
}

// Stop VLC synchronously before changing the Media Viewer page.
currentViewController.stop()

currentViewController.dismiss(animated: false) {
clearCurrent(currentViewController)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ final class NCVideoVLCViewController: UIViewController {
private var shouldAutoPlayOnStart: Bool
private var isChromeHidden: Bool
private weak var contextMenuController: NCMainTabBarController?
private var isReplayFromBeginningRequested = false

// MARK: - Paging Callbacks

Expand Down Expand Up @@ -545,8 +546,10 @@ final class NCVideoVLCViewController: UIViewController {
stopControlsHideTimer()
}

private func stop() {
func stop() {
stopControlsHideTimer()
isPlaybackRequested = false
isReplayFromBeginningRequested = false

mediaPlayer.stop()
mediaPlayer.media = nil
Expand All @@ -558,6 +561,40 @@ final class NCVideoVLCViewController: UIViewController {
clearVLCTrackMenuItems()
}

func restartPlaybackFromBeginning() {
isReplayFromBeginningRequested = true
isPlaybackRequested = true
updatePlayPauseButton()

if mediaPlayer.state == .stopped {
startReplayAfterStop()
} else {
mediaPlayer.stop()
}
}

private func startReplayAfterStop() {
guard isReplayFromBeginningRequested else {
return
}

isReplayFromBeginningRequested = false

let media = VLCMedia(url: url)

if let userAgent,
!userAgent.isEmpty,
!url.isFileURL {
media.addOption(":http-user-agent=\(userAgent)")
}

mediaPlayer.media = media
mediaPlayer.play()

startProgressTimer()
scheduleControlsHide()
}

private func attachDrawable() {
guard drawableView.bounds.width > 0,
drawableView.bounds.height > 0 else {
Expand All @@ -577,9 +614,24 @@ final class NCVideoVLCViewController: UIViewController {
case .playing:
isPlaybackRequested = true

case .ended:
isPlaybackRequested = false
stopProgressTimer()
updatePlayPauseButton()
updateProgressLabels(position: 1)
showControls(animated: true)
stopControlsHideTimer()
return

case .stopped:
if isReplayFromBeginningRequested {
startReplayAfterStop()
return
}

isPlaybackRequested = false

case .paused,
.stopped,
.ended,
.error:
isPlaybackRequested = false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,14 @@ extension NCVideoVLCViewController: NCVideoControlsViewDelegate {
updatePlayPauseButton()
showControls(animated: false)
stopControlsHideTimer()
} else if mediaPlayer.state == .ended ||
mediaPlayer.state == .stopped {
restartPlaybackFromBeginning()
} else {
isPlaybackRequested = true
updatePlayPauseButton()
mediaPlayer.play()
startProgressTimer()
scheduleControlsHide()
}

Expand Down
Loading
Loading