Browse Source

Merge pull request #2413 from nextcloud/general-improvements

General improvements
Marino Faggiana 1 year ago
parent
commit
fc63fbeb14

+ 0 - 15
iOSClient/Images.xcassets/play.imageset/Contents.json

@@ -1,15 +0,0 @@
-{
-  "images" : [
-    {
-      "filename" : "play.svg",
-      "idiom" : "universal"
-    }
-  ],
-  "info" : {
-    "author" : "xcode",
-    "version" : 1
-  },
-  "properties" : {
-    "preserves-vector-representation" : true
-  }
-}

+ 0 - 1
iOSClient/Images.xcassets/play.imageset/play.svg

@@ -1 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24"><path d="M8,5.14V19.14L19,12.14L8,5.14Z" /></svg>

+ 1 - 1
iOSClient/Media/NCMedia.swift

@@ -108,7 +108,7 @@ class NCMedia: UIViewController, NCEmptyDataSetDelegate, NCSelectDelegate {
         collectionView.prefetchDataSource = self
 
         cacheImages.cellLivePhotoImage = NCUtility.shared.loadImage(named: "livephoto", color: .white)
-        cacheImages.cellPlayImage = NCUtility.shared.loadImage(named: "play", color: .white)
+        cacheImages.cellPlayImage = NCUtility.shared.loadImage(named: "play.fill", color: .white)
     }
 
     override func viewWillAppear(_ animated: Bool) {

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

@@ -36,19 +36,18 @@ class NCPlayer: NSObject {
     internal var width: Int?
     internal var height: Int?
     internal var length: Int?
-    internal let userAgent = CCUtility.getUserAgent()!
     internal var pauseAfterPlay: Bool = false
 
     internal weak var playerToolBar: NCPlayerToolBar?
     internal weak var viewerMediaPage: NCViewerMediaPage?
 
-    weak var imageVideoContainer: imageVideoContainerView?
+    weak var imageVideoContainer: UIImageView?
 
     internal var counterSeconds: Double = 0
 
     // MARK: - View Life Cycle
 
-    init(imageVideoContainer: imageVideoContainerView, playerToolBar: NCPlayerToolBar?, metadata: tableMetadata, viewerMediaPage: NCViewerMediaPage?) {
+    init(imageVideoContainer: UIImageView, playerToolBar: NCPlayerToolBar?, metadata: tableMetadata, viewerMediaPage: NCViewerMediaPage?) {
 
         self.imageVideoContainer = imageVideoContainer
         self.playerToolBar = playerToolBar
@@ -67,6 +66,8 @@ class NCPlayer: NSObject {
     func openAVPlayer(url: URL, autoplay: Bool = false) {
 
         var position: Float = 0
+        let userAgent = CCUtility.getUserAgent()!
+
         self.url = url
         self.singleTapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(didSingleTapWith(gestureRecognizer:)))
 
@@ -104,20 +105,21 @@ class NCPlayer: NSObject {
 
     func restartAVPlayer(position: Float) {
 
-        if let url = self.url {
+        if let url = self.url, !player.isPlaying {
+
             player.media = VLCMedia(url: url)
             player.position = position
             playerToolBar?.setBarPlayer(position: position)
             viewerMediaPage?.changeScreenMode(mode: .normal)
             pauseAfterPlay = true
             player.play()
-        }
 
-        if position == 0 {
-            let fileNamePreviewLocalPath = CCUtility.getDirectoryProviderStoragePreviewOcId(metadata.ocId, etag: metadata.etag)!
-            imageVideoContainer?.image = UIImage(contentsOfFile: fileNamePreviewLocalPath)
-        } else {
-            imageVideoContainer?.image = nil
+            if position == 0 {
+                let fileNamePreviewLocalPath = CCUtility.getDirectoryProviderStoragePreviewOcId(metadata.ocId, etag: metadata.etag)!
+                imageVideoContainer?.image = UIImage(contentsOfFile: fileNamePreviewLocalPath)
+            } else {
+                imageVideoContainer?.image = nil
+            }
         }
     }
 
@@ -236,6 +238,7 @@ extension NCPlayer: VLCMediaPlayerDelegate {
             print("Played mode: ERROR")
             break
         case .playing:
+            playerToolBar?.playerView(hidden: false)
             if pauseAfterPlay {
                 player.pause()
                 pauseAfterPlay = false

+ 9 - 2
iOSClient/Viewer/NCViewerMedia/NCPlayer/NCPlayerToolBar.swift

@@ -87,7 +87,7 @@ class NCPlayerToolBar: UIView {
         playButton.setImage(NCUtility.shared.loadImage(named: "play.fill", color: .white, symbolConfiguration: UIImage.SymbolConfiguration(pointSize: pointSize)), for: .normal)
         forwardButton.setImage(NCUtility.shared.loadImage(named: "goforward.10", color: .white, symbolConfiguration: UIImage.SymbolConfiguration(pointSize: pointSize)), for: .normal)
 
-        playbackSlider.setThumbImage(UIImage(systemName: "circle.fill", withConfiguration: UIImage.SymbolConfiguration(pointSize: 10)), for: .normal)
+        playbackSlider.setThumbImage(UIImage(systemName: "circle.fill", withConfiguration: UIImage.SymbolConfiguration(pointSize: 15)), for: .normal)
         playbackSlider.value = 0
         playbackSlider.tintColor = .white
         playbackSlider.addTarget(self, action: #selector(playbackValChanged(slider:event:)), for: .valueChanged)
@@ -127,6 +127,8 @@ class NCPlayerToolBar: UIView {
             self.viewerMediaPage = viewerMediaPage
         }
 
+        playerView(hidden: true)
+        
         playButton.setImage(NCUtility.shared.loadImage(named: "play.fill", color: .white, symbolConfiguration: UIImage.SymbolConfiguration(pointSize: pointSize)), for: .normal)
         MPNowPlayingInfoCenter.default().nowPlayingInfo?[MPNowPlayingInfoPropertyPlaybackRate] = 0
 
@@ -167,6 +169,11 @@ class NCPlayerToolBar: UIView {
         self.audioButton.isEnabled = !audioTrackIndexes.isEmpty
     }
 
+    public func playerView(hidden: Bool) {
+
+        playerButtonView.isHidden = hidden
+    }
+
     // MARK: -
 
     public func show() {
@@ -239,7 +246,7 @@ class NCPlayerToolBar: UIView {
         } else {
             fullscreenButton.setImage(NCUtility.shared.loadImage(named: "arrow.up.left.and.arrow.down.right", color: .white), for: .normal)
         }
-        ncplayer?.changeScreenMode()
+        viewerMediaPage?.changeScreenMode(mode: viewerMediaScreenMode)
     }
 
     @IBAction func tapSubTitle(_ sender: Any) {

+ 16 - 42
iOSClient/Viewer/NCViewerMedia/NCViewerMedia.swift

@@ -26,6 +26,7 @@ import SVGKit
 import NextcloudKit
 import EasyTipView
 import SwiftUI
+import MobileVLCKit
 
 class NCViewerMedia: UIViewController {
 
@@ -34,12 +35,13 @@ class NCViewerMedia: UIViewController {
     @IBOutlet weak var imageViewTopConstraint: NSLayoutConstraint!
     @IBOutlet weak var imageViewBottomConstraint: NSLayoutConstraint!
     @IBOutlet weak var scrollView: UIScrollView!
-    @IBOutlet weak var imageVideoContainer: imageVideoContainerView!
+    @IBOutlet weak var imageVideoContainer: UIImageView!
     @IBOutlet weak var statusViewImage: UIImageView!
     @IBOutlet weak var statusLabel: UILabel!
     @IBOutlet weak var detailView: NCViewerMediaDetailView!
 
     private var tipView: EasyTipView?
+    private let player = VLCMediaPlayer()
 
     let appDelegate = UIApplication.shared.delegate as! AppDelegate
     weak var viewerMediaPage: NCViewerMediaPage?
@@ -52,9 +54,6 @@ class NCViewerMedia: UIViewController {
     var imageViewConstraint: CGFloat = 0
     var isDetailViewInitializze: Bool = false
 
-    var avPlayerLayer: AVPlayerLayer?
-    var avPlayer: AVPlayer?
-
     // MARK: - View Life Cycle
 
     required init?(coder aDecoder: NSCoder) {
@@ -140,32 +139,6 @@ class NCViewerMedia: UIViewController {
                 loadImage()
             }
         }
-
-        if viewerMediaScreenMode == .normal {
-
-            viewerMediaPage?.navigationController?.setNavigationBarHidden(false, animated: true)
-
-            if metadata.isMovie {
-                viewerMediaPage?.view.backgroundColor = .black
-                viewerMediaPage?.textColor = .white
-            } else {
-                viewerMediaPage?.view.backgroundColor = .systemBackground
-                viewerMediaPage?.textColor = .label
-            }
-            viewerMediaPage?.progressView.isHidden = false
-
-            NCUtility.shared.colorNavigationController(viewerMediaPage?.navigationController, backgroundColor: .systemBackground, titleColor: .label, tintColor: nil, withoutShadow: false)
-
-        } else {
-
-            viewerMediaPage?.navigationController?.setNavigationBarHidden(true, animated: true)
-
-            viewerMediaPage?.view.backgroundColor = .black
-            viewerMediaPage?.textColor = .white
-            viewerMediaPage?.progressView.isHidden = true
-
-            NCUtility.shared.colorNavigationController(viewerMediaPage?.navigationController, backgroundColor: .black, titleColor: .white, tintColor: nil, withoutShadow: false)
-        }
     }
 
     override func viewDidAppear(_ animated: Bool) {
@@ -214,6 +187,10 @@ class NCViewerMedia: UIViewController {
         super.viewWillTransition(to: size, with: coordinator)
 
         self.tipView?.dismiss()
+        if metadata.isVideo {
+            self.imageVideoContainer.isHidden = true
+        }
+
         coordinator.animate(alongsideTransition: { context in
             // back to the original size
             self.scrollView.zoom(to: CGRect(x: 0, y: 0, width: self.scrollView.bounds.width, height: self.scrollView.bounds.height), animated: false)
@@ -225,6 +202,9 @@ class NCViewerMedia: UIViewController {
             }
         }, completion: { context in
             self.showTip()
+            if self.metadata.isVideo {
+                self.imageVideoContainer.isHidden = false
+            }
         })
     }
 
@@ -344,22 +324,14 @@ class NCViewerMedia: UIViewController {
         statusViewImage.isHidden = true
         statusLabel.isHidden = true
 
-        avPlayer = AVPlayer(url: URL(fileURLWithPath: filePath))
-        avPlayerLayer = AVPlayerLayer(player: avPlayer)
-
-        if let avPlayerLayer = self.avPlayerLayer, let imageView = imageVideoContainer {
-            avPlayerLayer.videoGravity = .resizeAspect
-            avPlayerLayer.frame = imageView.bounds
-            imageView.layer.addSublayer(avPlayerLayer)
-            imageView.playerLayer = avPlayerLayer
-            avPlayer?.play()
-        }
+        player.media = VLCMedia(url: URL(fileURLWithPath: filePath))
+        player.drawable = imageVideoContainer
+        player.play()
     }
 
     func stopLivePhoto() {
 
-        avPlayer?.pause()
-        avPlayerLayer?.removeFromSuperlayer()
+        player.stop()
 
         statusViewImage.isHidden = false
         statusLabel.isHidden = false
@@ -592,6 +564,7 @@ extension NCViewerMedia: EasyTipViewDelegate {
 
 // MARK: -
 
+/*
 class imageVideoContainerView: UIImageView {
     var playerLayer: CALayer?
     var metadata: tableMetadata?
@@ -600,3 +573,4 @@ class imageVideoContainerView: UIImageView {
         playerLayer?.frame = self.bounds
     }
 }
+*/

+ 6 - 6
iOSClient/Viewer/NCViewerMedia/NCViewerMediaPage.storyboard

@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="20037" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="ne8-hS-cp3">
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="21701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="ne8-hS-cp3">
     <device id="retina5_5" orientation="portrait" appearance="light"/>
     <dependencies>
         <deployment identifier="iOS"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="20020"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21678"/>
         <capability name="Safe area layout guides" minToolsVersion="9.0"/>
         <capability name="System colors in document resources" minToolsVersion="11.0"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
@@ -28,7 +28,7 @@
                                 </connections>
                             </containerView>
                             <progressView opaque="NO" contentMode="scaleToFill" verticalHuggingPriority="750" progress="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="sD9-1i-ZdY">
-                                <rect key="frame" x="0.0" y="0.0" width="414" height="1"/>
+                                <rect key="frame" x="0.0" y="20" width="414" height="1"/>
                                 <constraints>
                                     <constraint firstAttribute="height" constant="1" id="F4E-lI-3jZ"/>
                                 </constraints>
@@ -79,18 +79,18 @@
                             <scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" maximumZoomScale="4" translatesAutoresizingMaskIntoConstraints="NO" id="CdQ-LC-Trx">
                                 <rect key="frame" x="0.0" y="0.0" width="414" height="736"/>
                                 <subviews>
-                                    <imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="networkInProgress" translatesAutoresizingMaskIntoConstraints="NO" id="kPV-JM-UnM" customClass="imageVideoContainerView" customModule="Nextcloud" customModuleProvider="target">
+                                    <imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="networkInProgress" translatesAutoresizingMaskIntoConstraints="NO" id="kPV-JM-UnM">
                                         <rect key="frame" x="0.0" y="0.0" width="414" height="736"/>
                                     </imageView>
                                     <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="2AU-85-K8y">
-                                        <rect key="frame" x="10" y="10" width="30" height="30"/>
+                                        <rect key="frame" x="10" y="30" width="30" height="30"/>
                                         <constraints>
                                             <constraint firstAttribute="height" constant="30" id="l1v-vA-4gG"/>
                                             <constraint firstAttribute="width" constant="30" id="mSt-o6-S1g"/>
                                         </constraints>
                                     </imageView>
                                     <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="DAi-gz-qGP">
-                                        <rect key="frame" x="50" y="16.666666666666668" width="344" height="17.000000000000004"/>
+                                        <rect key="frame" x="50" y="36.666666666666664" width="344" height="17"/>
                                         <fontDescription key="fontDescription" type="system" pointSize="14"/>
                                         <color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
                                         <nil key="highlightedColor"/>

+ 13 - 8
iOSClient/Viewer/NCViewerMedia/NCViewerMediaPage.swift

@@ -112,16 +112,18 @@ class NCViewerMediaPage: UIViewController {
         pageViewController.view.addGestureRecognizer(panGestureRecognizer)
         pageViewController.view.addGestureRecognizer(singleTapGestureRecognizer)
         pageViewController.view.addGestureRecognizer(longtapGestureRecognizer)
-        
-        let viewerMedia = getViewerMedia(index: currentIndex, metadata: metadatas[currentIndex])
-        pageViewController.setViewControllers([viewerMedia], direction: .forward, animated: true, completion: nil)
-
-        NotificationCenter.default.addObserver(self, selector: #selector(viewUnload), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMenuDetailClose), object: nil)
 
         progressView.tintColor = NCBrandColor.shared.brandElement
         progressView.trackTintColor = .clear
         progressView.progress = 0
 
+
+        let viewerMedia = getViewerMedia(index: currentIndex, metadata: metadatas[currentIndex])
+        pageViewController.setViewControllers([viewerMedia], direction: .forward, animated: true, completion: nil)
+        changeScreenMode(mode: viewerMediaScreenMode)
+
+        NotificationCenter.default.addObserver(self, selector: #selector(viewUnload), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterMenuDetailClose), object: nil)
+
         NotificationCenter.default.addObserver(self, selector: #selector(pageViewController.enableSwipeGesture), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterEnableSwipeGesture), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(pageViewController.disableSwipeGesture), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterDisableSwipeGesture), object: nil)
 
@@ -167,6 +169,7 @@ class NCViewerMediaPage: UIViewController {
     override func viewDidDisappear(_ animated: Bool) {
         super.viewDidDisappear(animated)
 
+        currentViewController.ncplayer?.playerStop()
         timerAutoHide?.invalidate()
     }
 
@@ -216,7 +219,6 @@ class NCViewerMediaPage: UIViewController {
 
         let metadata = currentViewController.metadata
         let fullscreen = currentViewController.playerToolBar?.isFullscreen ?? false
-        NCUtility.shared.colorNavigationController(navigationController, backgroundColor: .systemBackground, titleColor: .label, tintColor: nil, withoutShadow: false)
 
         if mode == .normal {
 
@@ -231,10 +233,12 @@ class NCViewerMediaPage: UIViewController {
             }
 
             if metadata.isMovie {
+                NCUtility.shared.colorNavigationController(navigationController, backgroundColor: .black, titleColor: .label, tintColor: nil, withoutShadow: false)
                 currentViewController.playerToolBar?.show()
                 view.backgroundColor = .black
                 textColor = .white
             } else {
+                NCUtility.shared.colorNavigationController(navigationController, backgroundColor: .systemBackground, titleColor: .label, tintColor: nil, withoutShadow: false)
                 view.backgroundColor = .systemBackground
                 textColor = .label
             }
@@ -563,8 +567,6 @@ extension NCViewerMediaPage: UIPageViewControllerDelegate, UIPageViewControllerD
 
         guard let nextViewController = pendingViewControllers.first as? NCViewerMedia else { return }
         nextIndex = nextViewController.index
-
-        startTimerAutoHide()
     }
 
     // END TRANSITION
@@ -578,6 +580,9 @@ extension NCViewerMediaPage: UIPageViewControllerDelegate, UIPageViewControllerD
             currentIndex = nextIndex!
         }
 
+        changeScreenMode(mode: viewerMediaScreenMode)
+        startTimerAutoHide()
+
         self.nextIndex = nil
     }
 }

+ 3 - 3
iOSClient/Viewer/NCViewerProviderContextMenu.swift

@@ -33,7 +33,6 @@ class NCViewerProviderContextMenu: UIViewController {
     private var metadataLivePhoto: tableMetadata?
     private var image: UIImage?
     private let player = VLCMediaPlayer()
-    private let userAgent = CCUtility.getUserAgent()!
 
     private let sizeIcon: CGFloat = 150
 
@@ -235,10 +234,10 @@ class NCViewerProviderContextMenu: UIViewController {
     private func viewVideo(metadata: tableMetadata) {
 
         NCNetworking.shared.getVideoUrl(metadata: metadata) { url, autoplay in
-            if let url = url {
+            if let url = url, let userAgent = CCUtility.getUserAgent() {
                 self.player.media = VLCMedia(url: url)
                 self.player.delegate = self
-                self.player.media?.addOption(":http-user-agent=\(self.userAgent)")
+                self.player.media?.addOption(":http-user-agent=\(userAgent)")
                 self.player.drawable = self.imageView
                 self.player.play()
             }
@@ -303,6 +302,7 @@ extension NCViewerProviderContextMenu: VLCMediaPlayerDelegate {
             print("Played mode: ERROR")
             break
         case .playing:
+            imageView.image = nil
             NCActivityIndicator.shared.stop()
             print("Played mode: PLAYING")
             break