Thursday, October 29, 2026
HomeiOS Developmentios - Swift -Transformed Audio URL to Video URL Does not Play...

ios – Swift -Transformed Audio URL to Video URL Does not Play in Photographs Library

[ad_1]

I’ve an audio url that I create utilizing the AVAudioRecorder. I need to share that audio on Instagram so I convert the audio to a video. The problem is after the conversion, once I save the video url to the Recordsdata app utilizing the UIActivityViewController, I can replay the video, see the time (eg 7 seconds) and listen to the audio with no drawback. A black display with a sound icon seems.

However once I save the video to the Photographs Library utilizing the UIActivityViewController, the video reveals the 7 seconds however nothing performs, the video is all grey, and the sound icon would not present.

Why is the video efficiently saving/enjoying within the Recordsdata app however not the Photographs Library?

let asset: AVURLAsset = AVURLAsset(url: audioURL)

let mixComposition = AVMutableComposition()
guard let compositionTrack = mixComposition.addMutableTrack(withMediaType: .audio, preferredTrackID: CMPersistentTrackID()) else { return }

let observe = asset.tracks(withMediaType: .audio)
guard let assetTrack = observe.first else { return }

do {
            
    attempt compositionTrack.insertTimeRange(CMTimeRangeMake(begin: .zero, period: assetTrack.timeRange.period), of: assetTrack, at: .zero)
            
} catch {
    print(error.localizedDescription)
}

guard let exporter = AVAssetExportSession(asset: mixComposition, presetName: AVAssetExportPresetPassthrough) else { return }

let dirPath = NSTemporaryDirectory().appending("(UUID().uuidString).mov")
let outputFileURL = URL(fileURLWithPath: dirPath)

exporter.outputFileType = .mov
exporter.outputURL = outputFileURL
exporter.shouldOptimizeForNetworkUse = true

exporter.exportAsynchronously {
    swap exporter.standing {

    // ...
    guard let videoURL = exporter.outputURL else { return }


        // current UIActivityViewController to save lots of videoURL after which put it aside to the Photographs Library
    }
}

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments