瀏覽代碼

update more audio format

alqindiirsyam 5 月之前
父節點
當前提交
9184630ba3
共有 1 個文件被更改,包括 26 次插入1 次删除
  1. 26 1
      AppBuilder/AppBuilderShare/ShareViewController.swift

+ 26 - 1
AppBuilder/AppBuilderShare/ShareViewController.swift

@@ -593,7 +593,7 @@ class ShareViewController: UIViewController, UITableViewDelegate, UITableViewDat
                     }
                     }
                 }
                 }
                 return
                 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
                 attachment.loadItem(forTypeIdentifier: UTType.data.identifier, options: nil) { (fileItem, error) in
                     if let fileURL = fileItem as? URL {
                     if let fileURL = fileItem as? URL {
                         self.getExactAudioDuration(url: fileURL) { durationFormatted in
                         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 {
     func getExactFileSize(url: URL) -> Int64 {
         do {
         do {