Browse Source

dev audio save form

marinofaggiana 6 years ago
parent
commit
a48e34f9c8

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


+ 0 - 0
iOSClient/Images.xcassets/play.imageset/play.pdf → iOSClient/Images.xcassets/audioPlay.imageset/play.pdf


+ 0 - 0
iOSClient/Images.xcassets/stop.imageset/Contents.json → iOSClient/Images.xcassets/audioStop.imageset/Contents.json


+ 0 - 0
iOSClient/Images.xcassets/stop.imageset/stop.pdf → iOSClient/Images.xcassets/audioStop.imageset/stop.pdf


+ 17 - 0
iOSClient/Main/Create cloud/NCCreateFormUploadVoiceNote.storyboard

@@ -29,17 +29,31 @@
                                     <outlet property="delegate" destination="uQo-FX-ejX" id="gsE-cc-f9G"/>
                                 </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"/>
+                                <constraints>
+                                    <constraint firstAttribute="width" constant="75" id="h48-gg-iPB"/>
+                                    <constraint firstAttribute="height" constant="75" id="mjB-VI-Gzf"/>
+                                </constraints>
+                                <state key="normal" image="audioPlay"/>
+                                <connections>
+                                    <action selector="playStop:" destination="uQo-FX-ejX" eventType="touchUpInside" id="4AN-dB-Qq8"/>
+                                </connections>
+                            </button>
                         </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="eeP-9N-ZRP" firstAttribute="leading" secondItem="ILQ-5j-b92" secondAttribute="leading" id="pNx-zH-54E"/>
+                            <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>
                         <viewLayoutGuide key="safeArea" id="ILQ-5j-b92"/>
                     </view>
                     <navigationItem key="navigationItem" id="YB9-Lg-X9d"/>
                     <connections>
+                        <outlet property="buttonPlayStop" destination="s98-hk-uUP" id="Aek-KA-loq"/>
                         <outlet property="tableView" destination="eeP-9N-ZRP" id="dzG-bV-m9u"/>
                     </connections>
                 </viewController>
@@ -66,4 +80,7 @@
             <point key="canvasLocation" x="256.80000000000001" y="228.93553223388307"/>
         </scene>
     </scenes>
+    <resources>
+        <image name="audioPlay" width="300" height="300"/>
+    </resources>
 </document>

+ 28 - 8
iOSClient/Main/Create cloud/NCCreateFormUploadVoiceNote.swift

@@ -23,8 +23,10 @@
 
 import Foundation
 
-class NCCreateFormUploadVoiceNote: XLFormViewController, NCSelectDelegate {
+class NCCreateFormUploadVoiceNote: XLFormViewController, NCSelectDelegate, AVAudioPlayerDelegate {
     
+    @IBOutlet weak var buttonPlayStop: UIButton!
+
     private var serverUrl = ""
     private var titleServerUrl = ""
     private var fileName = ""
@@ -45,6 +47,15 @@ class NCCreateFormUploadVoiceNote: XLFormViewController, NCSelectDelegate {
         self.fileName = fileName
         self.serverUrl = serverUrl
         self.fileNamePath = fileNamePath
+        
+        // player
+        do {
+            try audioPlayer = AVAudioPlayer(contentsOf: URL(fileURLWithPath: fileNamePath))
+            audioPlayer.prepareToPlay()
+            audioPlayer.delegate = self
+        } catch {
+            buttonPlayStop.isEnabled = false
+        }
     }
     
     override func viewDidLoad() {
@@ -240,12 +251,21 @@ class NCCreateFormUploadVoiceNote: XLFormViewController, NCSelectDelegate {
         self.present(navigationController, animated: true, completion: nil)
     }
     
-    func play() {
-        try! AVAudioSession.sharedInstance().setCategory(.playback, mode: .default)
-        try! AVAudioSession.sharedInstance().setActive(true)
-        
-        try! audioPlayer = AVAudioPlayer(contentsOf: URL(fileURLWithPath: fileNamePath))
-        audioPlayer.prepareToPlay()
-        audioPlayer.play()
+    @IBAction func playStop(_ sender: Any) {
+
+        if audioPlayer.isPlaying {
+            audioPlayer.currentTime = 0.0
+            audioPlayer.stop()
+            buttonPlayStop.setImage(UIImage.init(named: "audioPlay"), for: .normal)
+        } else {
+            audioPlayer.prepareToPlay()
+            audioPlayer.play()
+            buttonPlayStop.setImage(UIImage.init(named: "audioStop"), for: .normal)
+        }
+    }
+    
+    func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool) {
+        buttonPlayStop.setImage(UIImage.init(named: "audioPlay"), for: .normal)
     }
 }
+