Parcourir la source

update more audio format

alqindiirsyam il y a 5 mois
Parent
commit
9184630ba3
1 fichiers modifiés avec 26 ajouts et 1 suppressions
  1. 26 1
      AppBuilder/AppBuilderShare/ShareViewController.swift

+ 26 - 1
AppBuilder/AppBuilderShare/ShareViewController.swift

@@ -593,7 +593,7 @@ class ShareViewController: UIViewController, UITableViewDelegate, UITableViewDat
                     }
                 }
                 return
-            } else if attachment.hasItemConformingToTypeIdentifier(UTType.mpeg4Audio.identifier) || attachment.hasItemConformingToTypeIdentifier(UTType.mp3.identifier) || attachment.hasItemConformingToTypeIdentifier("org.opus-codec.opus") {
+            } else if isSupportedAudioFormat(attachment: attachment) {
                 attachment.loadItem(forTypeIdentifier: UTType.data.identifier, options: nil) { (fileItem, error) in
                     if let fileURL = fileItem as? URL {
                         self.getExactAudioDuration(url: fileURL) { durationFormatted in
@@ -660,6 +660,31 @@ class ShareViewController: UIViewController, UITableViewDelegate, UITableViewDat
             }
         }
     }
+    
+    func isSupportedAudioFormat(attachment: NSItemProvider) -> Bool {
+        var supportedAudioTypes: [UTType] = [
+            .mpeg4Audio,
+            .mp3,
+            .aiff,
+            .wav,
+            .appleProtectedMPEG4Audio
+        ]
+        
+        if let flacType = UTType(filenameExtension: "flac") {
+            supportedAudioTypes.append(flacType)
+        }
+        if let oggType = UTType(filenameExtension: "ogg") {
+            supportedAudioTypes.append(oggType)
+        }
+        if let cafType = UTType(filenameExtension: "caf") {
+            supportedAudioTypes.append(cafType)
+        }
+        if let opusType = UTType(filenameExtension: "opus") {
+            supportedAudioTypes.append(opusType)
+        }
+        
+        return supportedAudioTypes.contains { attachment.hasItemConformingToTypeIdentifier($0.identifier) }
+    }
 
     func getExactFileSize(url: URL) -> Int64 {
         do {