Skip to content

Instantly share code, notes, and snippets.

@HomidWay
HomidWay / multiFilePlayer.swift
Last active March 29, 2024 08:31
Swift | AVPlayer, load and play multiple audio files with one player
//Pass urls to files you want to play in one compossition,
//works with any file recognised as AVAsset and containing audio tracks,
//!!only first track in file will be played!!
func loadFiles(filesURL: [URL]) async throws -> AVPlayer{
//Initialize Mutable composition
let composition: AVMutableComposition = .init()
for file in filesURL{
//Add new Composition track for new file