Read an entire buffer.
SDKs
- iOS 8.0+
- macOS 10.10+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 3.0+
Framework
- AVFoundation
Declaration
func read(into buffer: AVAudio PCMBuffer) throws
Parameters
buffer
The buffer from which to read the file. Its format must match the file’s processing format.
outError
Returns, by-reference, a description of the error, if an error occurs.
Return Value
true
, if the read was successful; otherwise false
.
Discussion
Reading sequentially from the frame
property, attempts to fill the buffer to its capacity. On return, the buffer’s length
property indicates the number of sample frames successfully read.
Handling Errors in Swift:
In Swift, this method returns Void
and is marked with the throws
keyword to indicate that it throws an error in cases of failure.
You call this method in a try
expression and handle any errors in the catch
clauses of a do
statement, as described in Error Handling in The Swift Programming Language and About Imported Cocoa Error Parameters.