I experienced this same problem when playing downloaded files from AWS S3.
I don't have an explanation for the meaning behind the error message.
But in my case it was because the file was not actually playable.
1. Make sure the path is correct.
I did not use Bundle
.
I put the file under the Documents directory and I used FileManager
to set the path:
let documentsUrl: URL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
let localFileName: String = "recording.mp4"
let localFileUrl = documentsUrl.appendingPathComponent(localFileName)
print("Playing \(localFileUrl.absoluteString)")
That would print something like this:
file:///var/mobile/Containers/Data/Application/D8AF92BD-D736-4B86-9FF4-C60ABA6C741B/Documents/recording.mp4
2. Make sure the file is actually playable.
For this, I wanted to check what the file is actually like when it's stored on the device.
It turned out that file was "corrupted" (ex. copy/download interrupted), so it really wasn't playable.
- Connect the iOS device to your Mac.
- From Xcode, go to Window > Devices and Simulators
- Look for your device from the Connected list on the left.
- Look for your app from the Installed Apps list.
- Click the gears on the bottom of the list.
- Select Download Container..

- Download the *.xcappdata to a local directory
- Open the directory in Finder
- Right-click on the *.xcappdata, then select Show Package Contents
- It should show something like the image below
- Check the file's properties and try to play it

3. Make sure the file format is actually supported by AVPlayer
To see the supported AVPlayer formats, use print(AVURLAsset.audiovisualTypes())
.
Reference:
https://developer.apple.com/documentation/avfoundation/avurlasset/1386800-audiovisualtypes
Once the path, the file, and the format were all OK, and I was able to play it normally using AVPlayer
and AVPlayerViewController
.
let player = AVPlayer(url: localFileUrl)
let playerViewController = AVPlayerViewController()
playerViewController.player = player
self.present(playerViewController, animated: true) {
playerViewController.player!.play()
}