Marino Faggiana 2 years ago
parent
commit
f95b0dddb9

+ 0 - 16
Nextcloud.xcodeproj/project.pbxproj

@@ -584,8 +584,6 @@
 		F7EFC0C6256BC77700461AAD /* NCMoreUserCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = F7EFC0C5256BC77700461AAD /* NCMoreUserCell.xib */; };
 		F7EFC0CD256BF8DD00461AAD /* NCUserStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7EFC0CC256BF8DD00461AAD /* NCUserStatus.swift */; };
 		F7F1E54C2492369A00E42386 /* NCMediaCommandView.xib in Resources */ = {isa = PBXBuildFile; fileRef = F7F1E54B2492369A00E42386 /* NCMediaCommandView.xib */; };
-		F7F4F0F727ECDBA4008676F9 /* NCSubtitles.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7F4F0F327ECDBA4008676F9 /* NCSubtitles.swift */; };
-		F7F4F0F927ECDBA4008676F9 /* NCSubtitlePlayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7F4F0F527ECDBA4008676F9 /* NCSubtitlePlayer.swift */; };
 		F7F4F10527ECDBDB008676F9 /* Inconsolata-SemiBold.ttf in Resources */ = {isa = PBXBuildFile; fileRef = F7F4F0FD27ECDBDB008676F9 /* Inconsolata-SemiBold.ttf */; };
 		F7F4F10627ECDBDB008676F9 /* Inconsolata-Medium.ttf in Resources */ = {isa = PBXBuildFile; fileRef = F7F4F0FE27ECDBDB008676F9 /* Inconsolata-Medium.ttf */; };
 		F7F4F10727ECDBDB008676F9 /* Inconsolata-Black.ttf in Resources */ = {isa = PBXBuildFile; fileRef = F7F4F0FF27ECDBDB008676F9 /* Inconsolata-Black.ttf */; };
@@ -1232,8 +1230,6 @@
 		F7EFC0CC256BF8DD00461AAD /* NCUserStatus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCUserStatus.swift; sourceTree = "<group>"; };
 		F7F1E54B2492369A00E42386 /* NCMediaCommandView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NCMediaCommandView.xib; sourceTree = "<group>"; };
 		F7F35B592578FB63003F5589 /* CollaboraOnlineWebViewKeyboardManager.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CollaboraOnlineWebViewKeyboardManager.framework; path = Carthage/Build/iOS/CollaboraOnlineWebViewKeyboardManager.framework; sourceTree = "<group>"; };
-		F7F4F0F327ECDBA4008676F9 /* NCSubtitles.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCSubtitles.swift; sourceTree = "<group>"; };
-		F7F4F0F527ECDBA4008676F9 /* NCSubtitlePlayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCSubtitlePlayer.swift; sourceTree = "<group>"; };
 		F7F4F0FD27ECDBDB008676F9 /* Inconsolata-SemiBold.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Inconsolata-SemiBold.ttf"; sourceTree = "<group>"; };
 		F7F4F0FE27ECDBDB008676F9 /* Inconsolata-Medium.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Inconsolata-Medium.ttf"; sourceTree = "<group>"; };
 		F7F4F0FF27ECDBDB008676F9 /* Inconsolata-Black.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Inconsolata-Black.ttf"; sourceTree = "<group>"; };
@@ -1868,7 +1864,6 @@
 		F79EDA9E26B004980007D134 /* NCPlayer */ = {
 			isa = PBXGroup;
 			children = (
-				F7F4F0F227ECDBA4008676F9 /* NCSubtitle */,
 				F79EDAA126B004980007D134 /* NCPlayer.swift */,
 				F732D23227CF8AED000B0F1B /* NCPlayerToolBar.xib */,
 				F79EDA9F26B004980007D134 /* NCPlayerToolBar.swift */,
@@ -2159,15 +2154,6 @@
 			path = UserStatus;
 			sourceTree = "<group>";
 		};
-		F7F4F0F227ECDBA4008676F9 /* NCSubtitle */ = {
-			isa = PBXGroup;
-			children = (
-				F7F4F0F327ECDBA4008676F9 /* NCSubtitles.swift */,
-				F7F4F0F527ECDBA4008676F9 /* NCSubtitlePlayer.swift */,
-			);
-			path = NCSubtitle;
-			sourceTree = "<group>";
-		};
 		F7F4F0FB27ECDBDA008676F9 /* Font */ = {
 			isa = PBXGroup;
 			children = (
@@ -3204,7 +3190,6 @@
 				370D26AF248A3D7A00121797 /* NCCellProtocol.swift in Sources */,
 				F77B0DF51D118A16002130FE /* CCUtility.m in Sources */,
 				F70D87D025EE6E58008CBBBD /* NCRenameFile.swift in Sources */,
-				F7F4F0F727ECDBA4008676F9 /* NCSubtitles.swift in Sources */,
 				F71CD6CA2930D7B1006C95C1 /* NCApplicationHandle.swift in Sources */,
 				F790110E21415BF600D7B136 /* NCViewerRichdocument.swift in Sources */,
 				F78ACD4021903CC20088454D /* NCGridCell.swift in Sources */,
@@ -3276,7 +3261,6 @@
 				AF2D7C7C2742556F00ADF566 /* NCShareLinkCell.swift in Sources */,
 				F7E41316294A19B300839300 /* UIView+Extension.swift in Sources */,
 				F7C30E00291BD2610017149B /* NCNetworkingE2EERename.swift in Sources */,
-				F7F4F0F927ECDBA4008676F9 /* NCSubtitlePlayer.swift in Sources */,
 				F7651A8B23A2A3F2001403D2 /* NCCreateFormUploadDocuments.swift in Sources */,
 				F74AF3A4247FB6AE00AC767B /* NCUtilityFileSystem.swift in Sources */,
 				F7239871253D86B600257F49 /* NCEmptyDataSet.swift in Sources */,

+ 7 - 10
iOSClient/Viewer/NCViewerMedia/NCPlayer/NCPlayer.swift

@@ -38,8 +38,6 @@ class NCPlayer: NSObject {
     internal weak var viewController: UIViewController?
     internal var isStartPlayer: Bool
     internal var isStartObserver: Bool
-    internal var subtitleUrls: [URL] = []
-    internal var currentSubtitle: URL?
 
     private weak var imageVideoContainer: imageVideoContainerView?
     private weak var detailView: NCViewerMediaDetailView?
@@ -99,11 +97,6 @@ class NCPlayer: NSObject {
         player?.media = VLCMedia(url: url)
         player?.media?.addOption("--network-caching=10000")
         player?.delegate = self
-        playerToolBar?.show()
-        playerToolBar?.setMetadata(self.metadata)
-#if MFFFLIB
-        setUpForSubtitle()
-#endif
 
         let volume = CCUtility.getAudioVolume()
         if metadata.livePhoto {
@@ -118,10 +111,16 @@ class NCPlayer: NSObject {
         }
 
         player?.drawable = self.imageVideoContainer
+
+        playerToolBar?.setBarPlayer(ncplayer: self)
+        playerToolBar?.setMetadata(self.metadata)
+
         if autoplay {
             player?.play()
+            playerToolBar?.show(enableTimerAutoHide: true)
+        } else {
+            playerToolBar?.show(enableTimerAutoHide: false)
         }
-        self.playerToolBar?.setBarPlayer(ncplayer: self)
     }
 
     // MARK: - NotificationCenter
@@ -348,6 +347,4 @@ extension NCPlayer: VLCMediaPlayerDelegate {
     func mediaPlayer(_ player: VLCMediaPlayer, recordingStoppedAtPath path: String) {
         // Handle other states...
     }
-
-
 }

+ 1 - 1
iOSClient/Viewer/NCViewerMedia/NCPlayer/NCPlayerToolBar.swift

@@ -449,7 +449,7 @@ class NCPlayerToolBar: UIView {
     }
 
     @IBAction func tapSubtitle(_ sender: Any) {
-        self.ncplayer?.showAlertSubtitles()
+
     }
 
     func forward() {

+ 0 - 409
iOSClient/Viewer/NCViewerMedia/NCPlayer/NCSubtitle/NCSubtitlePlayer.swift

@@ -1,409 +0,0 @@
-//
-//  NCSubtitlePlayer.swift
-//  Nextcloud
-//
-//  Created by Federico Malagoni on 18/02/22.
-//  Copyright © 2022 Federico Malagoni. All rights reserved.
-//  Copyright © 2022 Marino Faggiana All rights reserved.
-//
-//  Author Federico Malagoni <federico.malagoni@astrairidium.com>
-//  Author Marino Faggiana <marino.faggiana@nextcloud.com>
-//
-//  This program is free software: you can redistribute it and/or modify
-//  it under the terms of the GNU General Public License as published by
-//  the Free Software Foundation, either version 3 of the License, or
-//  (at your option) any later version.
-//
-//  This program is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//  GNU General Public License for more details.
-//
-//  You should have received a copy of the GNU General Public License
-//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
-//
-
-import Foundation
-import AVKit
-import NextcloudKit
-
-extension NCPlayer {
-
-    private struct AssociatedKeys {
-        static var FontKey = "FontKey"
-        static var ColorKey = "FontKey"
-        static var SubtitleKey = "SubtitleKey"
-        static var SubtitleContainerViewKey = "SubtitleContainerViewKey"
-        static var SubtitleContainerViewHeightKey = "SubtitleContainerViewHeightKey"
-        static var SubtitleHeightKey = "SubtitleHeightKey"
-        static var SubtitleWidthKey = "SubtitleWidthKey"
-        static var SubtitleContainerViewWidthKey = "SubtitleContainerViewWidthKey"
-        static var SubtitleBottomKey = "SubtitleBottomKey"
-        static var PayloadKey = "PayloadKey"
-    }
-
-    private var widthProportion: CGFloat {
-        return 0.9
-    }
-
-    private var bottomConstantPortrait: CGFloat {
-        get {
-            if UIDevice.current.hasNotch {
-                return -60
-            } else {
-                return -40
-            }
-        } set {
-            _ = newValue
-        }
-    }
-
-    private var bottomConstantLandscape: CGFloat {
-        get {
-            if UIDevice.current.hasNotch {
-                return -120
-            } else {
-                return -100
-            }
-        } set {
-            _ = newValue
-        }
-    }
-
-    var subtitleContainerView: UIView? {
-        get { return objc_getAssociatedObject(self, &AssociatedKeys.SubtitleContainerViewKey) as? UIView }
-        set (value) { objc_setAssociatedObject(self, &AssociatedKeys.SubtitleContainerViewKey, value, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)}
-    }
-
-    var subtitleLabel: UILabel? {
-        get { return objc_getAssociatedObject(self, &AssociatedKeys.SubtitleKey) as? UILabel }
-        set (value) { objc_setAssociatedObject(self, &AssociatedKeys.SubtitleKey, value, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC) }
-    }
-
-    fileprivate var subtitleLabelHeightConstraint: NSLayoutConstraint? {
-        get { return objc_getAssociatedObject(self, &AssociatedKeys.SubtitleHeightKey) as? NSLayoutConstraint }
-        set (value) { objc_setAssociatedObject(self, &AssociatedKeys.SubtitleHeightKey, value, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC) }
-    }
-
-    fileprivate var subtitleContainerViewHeightConstraint: NSLayoutConstraint? {
-        get { return objc_getAssociatedObject(self, &AssociatedKeys.SubtitleContainerViewHeightKey) as? NSLayoutConstraint }
-        set (value) { objc_setAssociatedObject(self, &AssociatedKeys.SubtitleContainerViewHeightKey, value, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC) }
-    }
-
-    fileprivate var subtitleLabelBottomConstraint: NSLayoutConstraint? {
-        get { return objc_getAssociatedObject(self, &AssociatedKeys.SubtitleBottomKey) as? NSLayoutConstraint }
-        set (value) { objc_setAssociatedObject(self, &AssociatedKeys.SubtitleBottomKey, value, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC) }
-    }
-
-    fileprivate var subtitleLabelWidthConstraint: NSLayoutConstraint? {
-        get { return objc_getAssociatedObject(self, &AssociatedKeys.SubtitleWidthKey) as? NSLayoutConstraint }
-        set (value) { objc_setAssociatedObject(self, &AssociatedKeys.SubtitleWidthKey, value, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC) }
-    }
-    fileprivate var subtitleContainerViewWidthConstraint: NSLayoutConstraint? {
-        get { return objc_getAssociatedObject(self, &AssociatedKeys.SubtitleContainerViewWidthKey) as? NSLayoutConstraint }
-        set (value) { objc_setAssociatedObject(self, &AssociatedKeys.SubtitleContainerViewWidthKey, value, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC) }
-    }
-
-    fileprivate var parsedPayload: NSDictionary? {
-        get { return objc_getAssociatedObject(self, &AssociatedKeys.PayloadKey) as? NSDictionary }
-        set (value) { objc_setAssociatedObject(self, &AssociatedKeys.PayloadKey, value, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC) }
-    }
-
-    func setUpForSubtitle() {
-        self.subtitleUrls.removeAll()
-        if let url = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId) {
-            let enumerator = FileManager.default.enumerator(atPath: url)
-            let filePaths = (enumerator?.allObjects as? [String])
-            if let filePaths = filePaths {
-                let txtFilePaths = (filePaths.filter { $0.contains(".srt") }).sorted {
-                    guard let str1LastChar = $0.dropLast(4).last, let str2LastChar = $1.dropLast(4).last else {
-                        return false
-                    }
-                    return str1LastChar < str2LastChar
-                }
-                for txtFilePath in txtFilePaths {
-                    let subtitleUrl = URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: txtFilePath))
-                    self.subtitleUrls.append(subtitleUrl)
-                }
-            }
-        }
-        let (all, existing) = NCManageDatabase.shared.getSubtitles(account: metadata.account, serverUrl: metadata.serverUrl, fileName: metadata.fileName)
-        if !existing.isEmpty {
-            for subtitle in existing {
-                let subtitleUrl = URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(subtitle.ocId, fileNameView: subtitle.fileName))
-                self.subtitleUrls.append(subtitleUrl)
-            }
-        }
-        if all.count != existing.count {
-            let error = NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_subtitle_not_dowloaded_")
-            NCContentPresenter.shared.showInfo(error: error)
-        }
-        self.setSubtitleToolbarIcon(subtitleUrls: subtitleUrls)
-        self.hideSubtitle()
-    }
-
-    func setSubtitleToolbarIcon(subtitleUrls: [URL]) {
-        if subtitleUrls.isEmpty {
-            playerToolBar?.subtitleButton.isHidden = true
-        } else {
-            playerToolBar?.subtitleButton.isHidden = false
-        }
-    }
-
-    func addSubtitlesTo(_ vc: UIViewController, _ playerToolBar: NCPlayerToolBar?) {
-        addSubtitleLabel(vc, playerToolBar)
-        NotificationCenter.default.addObserver(self, selector: #selector(deviceRotated(_:)), name: UIDevice.orientationDidChangeNotification, object: nil)
-    }
-
-    func loadText(filePath: URL, _ completion: @escaping (_ contents: String?) -> Void) {
-        DispatchQueue.global().async {
-            guard let data = try? Data(contentsOf: filePath),
-                  let encoding = NCUtility.shared.getEncondingDataType(data: data) else {
-                return
-            }
-            if let decodedString = String(data: data, encoding: encoding) {
-                completion(decodedString)
-            } else {
-                completion(nil)
-            }
-         }
-    }
-
-    func open(fileFromLocal url: URL) {
-
-        subtitleLabel?.text = ""
-
-        self.loadText(filePath: url) { contents in
-            guard let contents = contents else {
-                return
-            }
-            DispatchQueue.main.async {
-                self.subtitleLabel?.text = ""
-                self.show(subtitles: contents)
-            }
-        }
-    }
-
-    @objc public func hideSubtitle() {
-        self.subtitleLabel?.isHidden = true
-        self.subtitleContainerView?.isHidden = true
-        self.currentSubtitle = nil
-    }
-
-    @objc public func showSubtitle(url: URL) {
-        self.subtitleLabel?.isHidden = false
-        self.subtitleContainerView?.isHidden = false
-        self.currentSubtitle = url
-    }
-
-    private func show(subtitles string: String) {
-        parsedPayload = try? NCSubtitles.parseSubRip(string)
-        if let parsedPayload = parsedPayload {
-            addPeriodicNotification(parsedPayload: parsedPayload)
-        }
-    }
-
-    private func showByDictionary(dictionaryContent: NSMutableDictionary) {
-        parsedPayload = dictionaryContent
-        if let parsedPayload = parsedPayload {
-            addPeriodicNotification(parsedPayload: parsedPayload)
-        }
-    }
-
-    func addPeriodicNotification(parsedPayload: NSDictionary) {
-        // Add periodic notifications
-        let interval = CMTimeMake(value: 1, timescale: 60)
-        /*
-        self.player?.addPeriodicTimeObserver(forInterval: interval, queue: .main) { [weak self] time in
-            guard let strongSelf = self, let label = strongSelf.subtitleLabel, let containerView = strongSelf.subtitleContainerView else {
-                return
-            }
-            DispatchQueue.main.async {
-                label.text = NCSubtitles.searchSubtitles(strongSelf.parsedPayload, time.seconds)
-                strongSelf.adjustViewWidth(containerView: containerView)
-                strongSelf.adjustLabelHeight(label: label)
-            }
-        }
-        */
-    }
-
-    @objc private func deviceRotated(_ notification: Notification) {
-        guard let label = self.subtitleLabel,
-              let containerView = self.subtitleContainerView else { return }
-        DispatchQueue.main.async {
-            self.adjustViewWidth(containerView: containerView)
-            self.adjustLabelHeight(label: label)
-            self.adjustLabelBottom(label: label)
-            containerView.layoutIfNeeded()
-            label.layoutIfNeeded()
-        }
-    }
-
-    private func adjustLabelHeight(label: UILabel) {
-        let baseSize = CGSize(width: label.bounds.width, height: .greatestFiniteMagnitude)
-        let rect = label.sizeThatFits(baseSize)
-        if label.text != nil {
-            self.subtitleLabelHeightConstraint?.constant = rect.height + 5.0
-        } else {
-            self.subtitleLabelHeightConstraint?.constant = rect.height
-        }
-    }
-
-    private func adjustLabelBottom(label: UILabel) {
-        var bottomConstant: CGFloat = bottomConstantPortrait
-
-        switch UIApplication.shared.windows.first?.windowScene?.interfaceOrientation {
-        case .portrait:
-            bottomConstant = bottomConstantLandscape
-        case .landscapeLeft, .landscapeRight, .portraitUpsideDown:
-            bottomConstant = bottomConstantPortrait
-        default:
-            ()
-        }
-        subtitleLabelBottomConstraint?.constant = bottomConstant
-    }
-
-    private func adjustViewWidth(containerView: UIView) {
-        let widthConstant: CGFloat = UIScreen.main.bounds.width * widthProportion
-        subtitleContainerViewWidthConstraint!.constant = widthConstant
-        subtitleLabel?.preferredMaxLayoutWidth = (widthConstant - 20)
-    }
-
-    fileprivate func addSubtitleLabel(_ vc: UIViewController, _ playerToolBar: NCPlayerToolBar?) {
-        guard subtitleLabel == nil,
-              subtitleContainerView == nil else {
-                  return
-              }
-        subtitleContainerView = UIView()
-        subtitleLabel = UILabel()
-
-        subtitleContainerView?.translatesAutoresizingMaskIntoConstraints = false
-        subtitleContainerView?.layer.cornerRadius = 5.0
-        subtitleContainerView?.layer.masksToBounds = true
-        subtitleContainerView?.layer.shouldRasterize = true
-        subtitleContainerView?.layer.rasterizationScale = UIScreen.main.scale
-        subtitleContainerView?.backgroundColor = UIColor.black.withAlphaComponent(0.35)
-
-        subtitleLabel?.translatesAutoresizingMaskIntoConstraints = false
-        subtitleLabel?.textAlignment = .center
-        subtitleLabel?.numberOfLines = 0
-        let fontSize = UIDevice.current.userInterfaceIdiom == .pad ? 38.0 : 20.0
-        subtitleLabel?.font = UIFont.incosolataMedium(size: fontSize)
-        subtitleLabel?.lineBreakMode = .byWordWrapping
-        subtitleLabel?.textColor = .white
-        subtitleLabel?.backgroundColor = .clear
-
-        subtitleContainerView?.addSubview(subtitleLabel!)
-
-        var isFound = false
-
-        for v in vc.view.subviews where v is UIScrollView {
-            if let scrollView = v as? UIScrollView {
-                for subView in scrollView.subviews where subView is imageVideoContainerView {
-                    subView.addSubview(subtitleContainerView!)
-                    isFound = true
-                    break
-                }
-            }
-        }
-
-        if !isFound {
-            vc.view.addSubview(subtitleContainerView!)
-        }
-
-        NSLayoutConstraint.activate([
-            subtitleLabel!.centerXAnchor.constraint(equalTo: subtitleContainerView!.centerXAnchor),
-            subtitleLabel!.centerYAnchor.constraint(equalTo: subtitleContainerView!.centerYAnchor)
-        ])
-
-        subtitleContainerViewHeightConstraint = NSLayoutConstraint(item: subtitleContainerView!, attribute: .height, relatedBy: .equal, toItem: subtitleLabel!, attribute: .height, multiplier: 1.0, constant: 0.0)
-        vc.view?.addConstraint(subtitleContainerViewHeightConstraint!)
-
-        var bottomConstant: CGFloat = bottomConstantPortrait
-
-        switch UIApplication.shared.windows.first?.windowScene?.interfaceOrientation {
-        case .portrait, .portraitUpsideDown:
-            bottomConstant = bottomConstantLandscape
-        case .landscapeLeft, .landscapeRight:
-            bottomConstant = bottomConstantPortrait
-        default:
-            ()
-        }
-
-        let widthConstant: CGFloat = UIScreen.main.bounds.width * widthProportion
-
-        NSLayoutConstraint.activate([
-            subtitleContainerView!.centerXAnchor.constraint(equalTo: vc.view.centerXAnchor)
-        ])
-
-        subtitleContainerViewWidthConstraint = NSLayoutConstraint(item: subtitleContainerView!, attribute: .width, relatedBy: .lessThanOrEqual, toItem: nil,
-                                                                  attribute: .width, multiplier: 1, constant: widthConstant)
-
-        // setting default width == 0 because there is no text inside of the label
-        subtitleLabelWidthConstraint = NSLayoutConstraint(item: subtitleLabel!, attribute: .width, relatedBy: .equal, toItem: subtitleContainerView,
-                                                          attribute: .width, multiplier: 1, constant: -20)
-
-        subtitleLabelBottomConstraint = NSLayoutConstraint(item: subtitleContainerView!, attribute: .bottom, relatedBy: .equal, toItem: vc.view, attribute:
-                                                                .bottom, multiplier: 1, constant: bottomConstant)
-
-        vc.view?.addConstraint(subtitleContainerViewWidthConstraint!)
-        vc.view?.addConstraint(subtitleLabelWidthConstraint!)
-        vc.view?.addConstraint(subtitleLabelBottomConstraint!)
-    }
-
-    internal func showAlertSubtitles() {
-
-        let alert = UIAlertController(title: nil, message: NSLocalizedString("_subtitle_", comment: ""), preferredStyle: .actionSheet)
-
-        for url in subtitleUrls {
-
-            print("Play Subtitle at:\n\(url.path)")
-
-            let videoUrlTitle = self.metadata.fileName.alphanumeric.dropLast(3)
-            let subtitleUrlTitle = url.lastPathComponent.alphanumeric.dropLast(3)
-
-            var titleSubtitle = String(subtitleUrlTitle.dropFirst(videoUrlTitle.count))
-            if titleSubtitle.isEmpty {
-                titleSubtitle = NSLocalizedString("_subtitle_", comment: "")
-            }
-
-            let action = UIAlertAction(title: titleSubtitle, style: .default, handler: { [self] _ in
-
-                if NCUtilityFileSystem.shared.getFileSize(filePath: url.path) > 0 {
-
-                    self.open(fileFromLocal: url)
-                    if let viewController = viewController {
-                        self.addSubtitlesTo(viewController, self.playerToolBar)
-                        self.showSubtitle(url: url)
-                    }
-
-                } else {
-
-                    let alertError = UIAlertController(title: NSLocalizedString("_error_", comment: ""), message: NSLocalizedString("_subtitle_not_found_", comment: ""), preferredStyle: .alert)
-                    alertError.addAction(UIKit.UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: nil))
-
-                    viewController?.present(alertError, animated: true, completion: nil)
-                }
-            })
-            alert.addAction(action)
-            if currentSubtitle == url {
-                action.setValue(true, forKey: "checked")
-            }
-        }
-
-        let disable = UIAlertAction(title: NSLocalizedString("_disable_", comment: ""), style: .default, handler: { _ in
-            self.hideSubtitle()
-        })
-        alert.addAction(disable)
-        if currentSubtitle == nil {
-            disable.setValue(true, forKey: "checked")
-        }
-
-        alert.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: { _ in
-        }))
-
-        alert.popoverPresentationController?.sourceView = self.viewController?.view
-
-        self.viewController?.present(alert, animated: true, completion: nil)
-    }
-}

+ 0 - 150
iOSClient/Viewer/NCViewerMedia/NCPlayer/NCSubtitle/NCSubtitles.swift

@@ -1,150 +0,0 @@
-//
-//  NCSubtitles
-//  Nextcloud
-//
-//  Created by Marc Hervera.
-//  Copyright 2017 Marc Hervera AVPlayerViewController-Subtitles v1.3.1 iOS
-//
-//  Modified by Federico Malagoni on 23/02/22 for Nextcloud.
-//
-//  Licensed under Apache License v2.0.
-//
-
-import AVKit
-
-class NCSubtitles {
-
-    // MARK: - Private properties
-
-    private var parsedPayload: NSDictionary?
-
-    // MARK: - Public methods
-
-    public init(file filePath: URL, encoding: String.Encoding = .utf8) throws {
-        // Get string
-        let string = try String(contentsOf: filePath, encoding: encoding)
-        // Parse string
-        parsedPayload = try NCSubtitles.parseSubRip(string)
-    }
-
-    public init(subtitles string: String) throws {
-        // Parse string
-        parsedPayload = try NCSubtitles.parseSubRip(string)
-    }
-
-    /// Search subtitles at time
-    ///
-    /// - Parameter time: Time
-    /// - Returns: String if exists
-    public func searchSubtitles(at time: TimeInterval) -> String? {
-        return NCSubtitles.searchSubtitles(parsedPayload, time)
-    }
-
-    // MARK: - Static methods
-
-    /// Subtitle parser
-    ///
-    /// - Parameter payload: Input string
-    /// - Returns: NSDictionary
-    static func parseSubRip(_ payload: String) throws -> NSDictionary? {
-        // Prepare payload
-        var payload = payload.replacingOccurrences(of: "\n\r\n", with: "\n\n")
-        payload = payload.replacingOccurrences(of: "\n\n\n", with: "\n\n")
-        payload = payload.replacingOccurrences(of: "\r\n", with: "\n")
-
-        // Parsed dict
-        let parsed = NSMutableDictionary()
-
-        // Get groups
-        let regexStr = "(\\d+)\\n([\\d:,.]+)\\s+-{2}\\>\\s+([\\d:,.]+)\\n([\\s\\S]*?(?=\\n{2,}|$))"
-        let regex = try NSRegularExpression(pattern: regexStr, options: .caseInsensitive)
-        let matches = regex.matches(in: payload, options: NSRegularExpression.MatchingOptions(rawValue: 0), range: NSRange(location: 0, length: payload.count))
-
-        for m in matches {
-            let group = (payload as NSString).substring(with: m.range)
-
-            // Get index
-            var regex = try NSRegularExpression(pattern: "^[0-9]+", options: .caseInsensitive)
-            var match = regex.matches(in: group, options: NSRegularExpression.MatchingOptions(rawValue: 0), range: NSRange(location: 0, length: group.count))
-
-            guard let i = match.first else {
-                continue
-            }
-
-            let index = (group as NSString).substring(with: i.range)
-
-            // Get "from" & "to" time
-            regex = try NSRegularExpression(pattern: "\\d{1,2}:\\d{1,2}:\\d{1,2}[,.]\\d{1,3}", options: .caseInsensitive)
-            match = regex.matches(in: group, options: NSRegularExpression.MatchingOptions(rawValue: 0), range: NSRange(location: 0, length: group.count))
-
-            guard match.count == 2 else {
-                continue
-            }
-
-            guard let from = match.first, let to = match.last else {
-                continue
-            }
-
-            var h: TimeInterval = 0.0, m: TimeInterval = 0.0, s: TimeInterval = 0.0, c: TimeInterval = 0.0
-
-            let fromStr = (group as NSString).substring(with: from.range)
-            var scanner = Scanner(string: fromStr)
-            scanner.scanDouble(&h)
-            scanner.scanString(":", into: nil)
-            scanner.scanDouble(&m)
-            scanner.scanString(":", into: nil)
-            scanner.scanDouble(&s)
-            scanner.scanString(",", into: nil)
-            scanner.scanDouble(&c)
-            let fromTime = (h * 3600.0) + (m * 60.0) + s + (c / 1000.0)
-
-            let toStr = (group as NSString).substring(with: to.range)
-            scanner = Scanner(string: toStr)
-            scanner.scanDouble(&h)
-            scanner.scanString(":", into: nil)
-            scanner.scanDouble(&m)
-            scanner.scanString(":", into: nil)
-            scanner.scanDouble(&s)
-            scanner.scanString(",", into: nil)
-            scanner.scanDouble(&c)
-            let toTime = (h * 3600.0) + (m * 60.0) + s + (c / 1000.0)
-
-            // Get text & check if empty
-            let range = NSRange(location: 0, length: to.range.location + to.range.length + 1)
-            guard (group as NSString).length - range.length > 0 else {
-                continue
-            }
-
-            let text = (group as NSString).replacingCharacters(in: range, with: "")
-
-            // Create final object
-            let final = NSMutableDictionary()
-            final["from"] = fromTime
-            final["to"] = toTime
-            final["text"] = text
-            parsed[index] = final
-        }
-
-        return parsed
-    }
-
-    /// Search subtitle on time
-    ///
-    /// - Parameters:
-    ///   - payload: Inout payload
-    ///   - time: Time
-    /// - Returns: String
-    static func searchSubtitles(_ payload: NSDictionary?, _ time: TimeInterval) -> String? {
-        let predicate = NSPredicate(format: "(%f >= %K) AND (%f <= %K)", time, "from", time, "to")
-
-        guard let values = payload?.allValues, let result = (values as NSArray).filtered(using: predicate).first as? NSDictionary else {
-            return nil
-        }
-
-        guard let text = result.value(forKey: "text") as? String else {
-            return nil
-        }
-
-        return text.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
-    }
-}

+ 0 - 4
iOSClient/Viewer/NCViewerMedia/NCViewerMedia.swift

@@ -569,8 +569,4 @@ extension NCViewerMedia: EasyTipViewDelegate {
 class imageVideoContainerView: UIImageView {
     var playerLayer: CALayer?
     var metadata: tableMetadata?
-    override func layoutSublayers(of layer: CALayer) {
-        super.layoutSublayers(of: layer)
-        playerLayer?.frame = self.bounds
-    }
 }

+ 0 - 1
iOSClient/Viewer/NCViewerMedia/NCViewerMediaPage.swift

@@ -631,7 +631,6 @@ extension NCViewerMediaPage: UIGestureRecognizerDelegate {
             currentViewController.statusViewImage.isHidden = false
             currentViewController.statusLabel.isHidden = false
             currentViewController.imageVideoContainer.image = currentViewController.image
-            // ncplayerLivePhoto?.deactivateObserver()
         }
     }
 }