Renamed the RecordingService protocol in the Recording package target as Capturing.
This commit is contained in:
+15
-15
@@ -6,7 +6,7 @@ import AVFoundation
|
||||
/// The user's permission to record is requested before a recording starts and, on the platforms that require it, the shared audio session is
|
||||
/// configured for recording while the capture is in progress.
|
||||
@MainActor
|
||||
public final class AudioRecordingService: RecordingService {
|
||||
public final class AudioCapturing: Capturing {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
@@ -22,12 +22,12 @@ public final class AudioRecordingService: RecordingService {
|
||||
|
||||
/// Starts a new audio recording from the microphone.
|
||||
///
|
||||
/// - Throws: ``AudioRecordingError/permissionNotGranted`` when the user denies the app access to the microphone,
|
||||
/// ``AudioRecordingError/captureNotStarted`` when the recorder fails to start, or any error thrown while configuring
|
||||
/// - Throws: ``AudioCapturingError/permissionNotGranted`` when the user denies the app access to the microphone,
|
||||
/// ``AudioCapturingError/captureNotStarted`` when the recorder fails to start, or any error thrown while configuring
|
||||
/// the audio session or creating the recorder.
|
||||
public func start() async throws {
|
||||
guard await AVAudioApplication.requestRecordPermission() else {
|
||||
throw AudioRecordingError.permissionNotGranted
|
||||
throw AudioCapturingError.permissionNotGranted
|
||||
}
|
||||
|
||||
#if os(iOS) || os(visionOS)
|
||||
@@ -43,7 +43,7 @@ public final class AudioRecordingService: RecordingService {
|
||||
)
|
||||
|
||||
guard recorder.record() else {
|
||||
throw AudioRecordingError.captureNotStarted
|
||||
throw AudioCapturingError.captureNotStarted
|
||||
}
|
||||
|
||||
self.recorder = recorder
|
||||
@@ -51,10 +51,10 @@ public final class AudioRecordingService: RecordingService {
|
||||
|
||||
/// Pauses the ongoing recording.
|
||||
///
|
||||
/// - Throws: ``AudioRecordingError/noOngoingRecording`` when no recording is in progress.
|
||||
/// - Throws: ``AudioCapturingError/noOngoingRecording`` when no recording is in progress.
|
||||
public func pause() async throws {
|
||||
guard let recorder else {
|
||||
throw AudioRecordingError.noOngoingRecording
|
||||
throw AudioCapturingError.noOngoingRecording
|
||||
}
|
||||
|
||||
recorder.pause()
|
||||
@@ -62,25 +62,25 @@ public final class AudioRecordingService: RecordingService {
|
||||
|
||||
/// Resumes a paused recording.
|
||||
///
|
||||
/// - Throws: ``AudioRecordingError/noOngoingRecording`` when no recording is in progress, or
|
||||
/// ``AudioRecordingError/captureNotStarted`` when the recorder fails to resume.
|
||||
/// - Throws: ``AudioCapturingError/noOngoingRecording`` when no recording is in progress, or
|
||||
/// ``AudioCapturingError/captureNotStarted`` when the recorder fails to resume.
|
||||
public func resume() async throws {
|
||||
guard let recorder else {
|
||||
throw AudioRecordingError.noOngoingRecording
|
||||
throw AudioCapturingError.noOngoingRecording
|
||||
}
|
||||
guard recorder.record() else {
|
||||
throw AudioRecordingError.captureNotStarted
|
||||
throw AudioCapturingError.captureNotStarted
|
||||
}
|
||||
}
|
||||
|
||||
/// Stops the recording, deleting the temporary audio file after its contents are read.
|
||||
///
|
||||
/// - Returns: The audio captured since the recording started.
|
||||
/// - Throws: ``AudioRecordingError/noOngoingRecording`` when no recording is in progress, or any error thrown
|
||||
/// - Throws: ``AudioCapturingError/noOngoingRecording`` when no recording is in progress, or any error thrown
|
||||
/// while reading the recorded audio file.
|
||||
public func stop() async throws -> Data {
|
||||
guard let recorder else {
|
||||
throw AudioRecordingError.noOngoingRecording
|
||||
throw AudioCapturingError.noOngoingRecording
|
||||
}
|
||||
|
||||
recorder.stop()
|
||||
@@ -102,8 +102,8 @@ public final class AudioRecordingService: RecordingService {
|
||||
|
||||
// MARK: - Errors
|
||||
|
||||
/// The errors thrown by ``AudioRecordingService``.
|
||||
public enum AudioRecordingError: Error {
|
||||
/// The errors thrown by ``AudioCapturing``.
|
||||
public enum AudioCapturingError: Error {
|
||||
/// The recorder failed to start or resume the audio capture.
|
||||
case captureNotStarted
|
||||
/// No recording is in progress.
|
||||
+1
-1
@@ -4,7 +4,7 @@ import Foundation
|
||||
///
|
||||
/// The service is internal on purpose: it only backs the feature's previews and the default values of its model, and is not part of the
|
||||
/// package's public interface.
|
||||
struct DummyRecordingService: RecordingService {
|
||||
struct DummyCapturing: Capturing {
|
||||
|
||||
// MARK: Methods
|
||||
|
||||
Reference in New Issue
Block a user