iosswiftavfoundationavurlassetavassetreader

Reading remote audio file using AVAssetReader aborts


I have a iOS app that tries to read an audio file using an AVAssetReader from a remote server. However the AVAssetReader never gets created, during creation it throws an error "Process aborted". What is wrong with that code ?

BTW: The URL/resource is reachable and valid. I can play the file in the same app using SwiftUI's VideoPlayPlayer !

if let url = URL(string: "https://my-server.com/audio.m4a") {
  let asset = AVURLAsset(url: url, options: nil)
  print(asset) // looks OK
  do {
    let assetReader = try AVAssetReader(asset: asset)
    print(#fileID, #function, assetReader) // never reached
  } catch {
    print(#fileID, #function, error.localizedDescription) // instead I get error 'Vorgang gestoppt'
  }
}

Any ideas ?


Solution

  • The AVAssetReader documentation says that

    The assets you read may represent file-based media like QuickTime movies or MPEG-4 files, or media that you compose from multiple sources using AVComposition.
    

    and AVComposition's header file documentation says

    An AVComposition combines media data from multiple local file-based sources in a custom temporal arrangement
    

    so it looks like AVAssetReader can only read file based, or compositions of file based assets and not remote assets.