marinofaggiana %!s(int64=3) %!d(string=hai) anos
pai
achega
d59335bcae
Modificáronse 1 ficheiros con 33 adicións e 15 borrados
  1. 33 15
      iOSClient/Main/Create cloud/NCCreateFormUploadVoiceNote.swift

+ 33 - 15
iOSClient/Main/Create cloud/NCCreateFormUploadVoiceNote.swift

@@ -80,6 +80,14 @@ class NCCreateFormUploadVoiceNote: XLFormViewController, NCSelectDelegate, AVAud
         updateTimerUI()
     }
     
+    override func viewDidDisappear(_ animated: Bool) {
+        super.viewDidDisappear(animated)
+        
+        if audioPlayer.isPlaying {
+            stop()
+        }
+    }
+    
     override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
         super.traitCollectionDidChange(previousTraitCollection)
         
@@ -311,27 +319,37 @@ class NCCreateFormUploadVoiceNote: XLFormViewController, NCSelectDelegate, AVAud
 
         if audioPlayer.isPlaying {
             
-            audioPlayer.currentTime = 0.0
-            audioPlayer.stop()
-            
-            timer.invalidate()
-            counterSecondPlayer = 0
-            progressView.progress = 0
-            updateTimerUI()
-            
-            buttonPlayStop.setImage(UIImage(named: "audioPlay")!.image(color: NCBrandColor.shared.gray, size: 100), for: .normal)
+            stop()
             
         } else {
             
-            audioPlayer.prepareToPlay()
-            audioPlayer.play()
-            
-            timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(updateTimer), userInfo: nil, repeats: true)
-            
-            buttonPlayStop.setImage(UIImage(named: "stop")!.image(color: NCBrandColor.shared.gray, size: 100), for: .normal)
+            start()
         }
     }
     
+    func start() {
+        
+        audioPlayer.prepareToPlay()
+        audioPlayer.play()
+        
+        timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(updateTimer), userInfo: nil, repeats: true)
+        
+        buttonPlayStop.setImage(UIImage(named: "stop")!.image(color: NCBrandColor.shared.gray, size: 100), for: .normal)
+    }
+    
+    func stop() {
+        
+        audioPlayer.currentTime = 0.0
+        audioPlayer.stop()
+        
+        timer.invalidate()
+        counterSecondPlayer = 0
+        progressView.progress = 0
+        updateTimerUI()
+        
+        buttonPlayStop.setImage(UIImage(named: "audioPlay")!.image(color: NCBrandColor.shared.gray, size: 100), for: .normal)
+    }
+    
     func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool) {
         
         timer.invalidate()