marinofaggiana 6 vuotta sitten
vanhempi
commit
dd3123fc34

+ 12 - 2
iOSClient/Main/Create cloud/NCCreateFormUploadVoiceNote.storyboard

@@ -30,7 +30,7 @@
                                 </connections>
                             </tableView>
                             <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="s98-hk-uUP">
-                                <rect key="frame" x="150" y="319" width="75" height="75"/>
+                                <rect key="frame" x="150" y="346" width="75" height="75"/>
                                 <constraints>
                                     <constraint firstAttribute="width" constant="75" id="h48-gg-iPB"/>
                                     <constraint firstAttribute="height" constant="75" id="mjB-VI-Gzf"/>
@@ -40,12 +40,21 @@
                                     <action selector="playStop:" destination="uQo-FX-ejX" eventType="touchUpInside" id="4AN-dB-Qq8"/>
                                 </connections>
                             </button>
+                            <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="we1-Q7-8Us">
+                                <rect key="frame" x="10" y="309" width="355" height="17"/>
+                                <fontDescription key="fontDescription" type="system" pointSize="14"/>
+                                <nil key="textColor"/>
+                                <nil key="highlightedColor"/>
+                            </label>
                         </subviews>
                         <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
                         <constraints>
                             <constraint firstItem="eeP-9N-ZRP" firstAttribute="top" secondItem="ILQ-5j-b92" secondAttribute="top" constant="25" id="AEH-dn-vHh"/>
-                            <constraint firstItem="s98-hk-uUP" firstAttribute="top" secondItem="eeP-9N-ZRP" secondAttribute="bottom" constant="30" id="HDU-PP-dpD"/>
+                            <constraint firstItem="we1-Q7-8Us" firstAttribute="top" secondItem="eeP-9N-ZRP" secondAttribute="bottom" constant="20" id="Rgu-v2-bFJ"/>
+                            <constraint firstItem="ILQ-5j-b92" firstAttribute="trailing" secondItem="we1-Q7-8Us" secondAttribute="trailing" constant="10" id="hlz-TT-1Ue"/>
+                            <constraint firstItem="we1-Q7-8Us" firstAttribute="leading" secondItem="ILQ-5j-b92" secondAttribute="leading" constant="10" id="mDe-vt-V6l"/>
                             <constraint firstItem="eeP-9N-ZRP" firstAttribute="leading" secondItem="ILQ-5j-b92" secondAttribute="leading" id="pNx-zH-54E"/>
+                            <constraint firstItem="s98-hk-uUP" firstAttribute="top" secondItem="we1-Q7-8Us" secondAttribute="bottom" constant="20" id="t2J-Ir-ONd"/>
                             <constraint firstItem="s98-hk-uUP" firstAttribute="centerX" secondItem="ILQ-5j-b92" secondAttribute="centerX" id="vLn-iu-xOz"/>
                             <constraint firstItem="ILQ-5j-b92" firstAttribute="trailing" secondItem="eeP-9N-ZRP" secondAttribute="trailing" id="yxz-bK-MTp"/>
                         </constraints>
@@ -54,6 +63,7 @@
                     <navigationItem key="navigationItem" id="YB9-Lg-X9d"/>
                     <connections>
                         <outlet property="buttonPlayStop" destination="s98-hk-uUP" id="Aek-KA-loq"/>
+                        <outlet property="labelTimer" destination="we1-Q7-8Us" id="9LN-EV-8tm"/>
                         <outlet property="tableView" destination="eeP-9N-ZRP" id="dzG-bV-m9u"/>
                     </connections>
                 </viewController>

+ 38 - 2
iOSClient/Main/Create cloud/NCCreateFormUploadVoiceNote.swift

@@ -26,14 +26,17 @@ import Foundation
 class NCCreateFormUploadVoiceNote: XLFormViewController, NCSelectDelegate, AVAudioPlayerDelegate {
     
     @IBOutlet weak var buttonPlayStop: UIButton!
+    @IBOutlet weak var labelTimer: UILabel!
 
     private var serverUrl = ""
     private var titleServerUrl = ""
     private var fileName = ""
     private var fileNamePath = ""
-    private var duration: TimeInterval = 0
+    private var durationPlayerString = ""
+    private var counterSecondPlayer: TimeInterval = 0
     
     private var audioPlayer = AVAudioPlayer()
+    private var timer = Timer()
 
     let appDelegate = UIApplication.shared.delegate as! AppDelegate
     
@@ -54,7 +57,7 @@ class NCCreateFormUploadVoiceNote: XLFormViewController, NCSelectDelegate, AVAud
             try audioPlayer = AVAudioPlayer(contentsOf: URL(fileURLWithPath: fileNamePath))
             audioPlayer.prepareToPlay()
             audioPlayer.delegate = self
-            duration = audioPlayer.duration
+            durationPlayerString = NCUtility.sharedInstance.formatSecondsToString(TimeInterval(audioPlayer.duration))
         } catch {
             buttonPlayStop.isEnabled = false
         }
@@ -86,6 +89,12 @@ class NCCreateFormUploadVoiceNote: XLFormViewController, NCSelectDelegate, AVAud
         initializeForm()
     }
     
+    override func viewWillAppear(_ animated: Bool) {
+        super.viewWillAppear(animated)
+        
+        updateLabelTimer()
+    }
+    
     func initializeForm() {
         
         let form : XLFormDescriptor = XLFormDescriptor() as XLFormDescriptor
@@ -254,20 +263,47 @@ class NCCreateFormUploadVoiceNote: XLFormViewController, NCSelectDelegate, AVAud
         self.present(navigationController, animated: true, completion: nil)
     }
     
+    //MARK: Player
+
+    func updateLabelTimer() {
+        labelTimer.text = NCUtility.sharedInstance.formatSecondsToString(counterSecondPlayer) + " - " + durationPlayerString
+    }
+    
+    @objc func updateTimer() {
+        counterSecondPlayer += 1
+        updateLabelTimer()
+    }
+    
     @IBAction func playStop(_ sender: Any) {
 
         if audioPlayer.isPlaying {
+            
             audioPlayer.currentTime = 0.0
             audioPlayer.stop()
+            
+            timer.invalidate()
+            counterSecondPlayer = 0
+            updateLabelTimer()
+            
             buttonPlayStop.setImage(CCGraphics.changeThemingColorImage(UIImage(named: "audioPlay")!, width: 200, height: 200, color: NCBrandColor.sharedInstance.icon), for: .normal)
+            
         } else {
+            
             audioPlayer.prepareToPlay()
             audioPlayer.play()
+            
+            timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(updateTimer), userInfo: nil, repeats: true)
+            
             buttonPlayStop.setImage(CCGraphics.changeThemingColorImage(UIImage(named: "audioStop")!, width: 200, height: 200, color: NCBrandColor.sharedInstance.icon), for: .normal)
         }
     }
     
     func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool) {
+        
+        timer.invalidate()
+        counterSecondPlayer = 0
+        updateLabelTimer()
+        
         buttonPlayStop.setImage(CCGraphics.changeThemingColorImage(UIImage(named: "audioPlay")!, width: 200, height: 200, color: NCBrandColor.sharedInstance.icon), for: .normal)
     }
 }