You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: resources/views/docs/mobile/2/apis/microphone.md
+29-32Lines changed: 29 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,48 +1,50 @@
1
1
---
2
-
title: Audio
2
+
title: Microphone
3
3
order: 50
4
4
---
5
5
6
6
## Overview
7
7
8
-
The Audio API provides access to the device's microphone for recording audio. It offers a fluent interface for starting and managing recordings, tracking them with unique identifiers, and responding to completion events.
8
+
The Microphone API provides access to the device's microphone for recording audio. It offers a fluent interface for
9
+
starting and managing recordings, tracking them with unique identifiers, and responding to completion events.
9
10
10
11
```php
11
-
use Native\Mobile\Facades\Audio;
12
+
use Native\Mobile\Facades\Microphone;
12
13
```
13
14
14
15
## Methods
15
16
16
17
### `record()`
17
18
18
-
Start an audio recording. Returns a `PendingAudioRecorder` instance that controls the recording lifecycle.
19
+
Start an audio recording. Returns a `PendingMicrophone` instance that controls the recording lifecycle.
19
20
20
21
```php
21
-
Audio::record()->start();
22
+
Microphone::record()->start();
22
23
```
23
24
24
25
### `stop()`
25
26
26
-
Stop the current audio recording. This dispatches the `AudioRecorded` event with the recording file path.
27
+
Stop the current audio recording. If this results in a saved file, this dispatches the `AudioRecorded` event with the
28
+
recording file path.
27
29
28
30
```php
29
-
Audio::stop();
31
+
Microphone::stop();
30
32
```
31
33
32
34
### `pause()`
33
35
34
36
Pause the current audio recording without ending it.
35
37
36
38
```php
37
-
Audio::pause();
39
+
Microphone::pause();
38
40
```
39
41
40
42
### `resume()`
41
43
42
44
Resume a paused audio recording.
43
45
44
46
```php
45
-
Audio::resume();
47
+
Microphone::resume();
46
48
```
47
49
48
50
### `getStatus()`
@@ -52,7 +54,7 @@ Get the current recording status.
52
54
**Returns:**`string` - One of: `"idle"`, `"recording"`, or `"paused"`
53
55
54
56
```php
55
-
$status = Audio::getStatus();
57
+
$status = Microphone::getStatus();
56
58
57
59
if ($status === 'recording') {
58
60
// A recording is in progress
@@ -66,25 +68,27 @@ Get the file path to the last recorded audio file.
66
68
**Returns:**`string|null` - Path to the last recording, or `null` if none exists
67
69
68
70
```php
69
-
$path = Audio::getRecording();
71
+
$path = Microphone::getRecording();
70
72
71
73
if ($path) {
72
74
// Process the recording file
73
75
}
74
76
```
75
77
76
-
## PendingAudioRecorder
78
+
## PendingMicrophone
77
79
78
-
The `PendingAudioRecorder` provides a fluent interface for configuring and starting audio recordings. Most methods return `$this` for method chaining.
80
+
The `PendingMicrophone` provides a fluent interface for configuring and starting audio recordings. Most methods return
81
+
`$this` for method chaining.
79
82
80
83
### `id(string $id)`
81
84
82
-
Set a unique identifier for this recording. This ID will be included in the `AudioRecorded` event, allowing you to correlate recordings with completion events.
85
+
Set a unique identifier for this recording. This ID will be included in the `AudioRecorded` event, allowing you to
86
+
correlate recordings with completion events.
83
87
84
88
```php
85
89
$recorderId = 'message-recording-' . $this->id;
86
90
87
-
Audio::record()
91
+
Microphone::record()
88
92
->id($recorderId)
89
93
->start();
90
94
```
@@ -94,7 +98,7 @@ Audio::record()
94
98
Get the recorder's unique identifier. If no ID was set, one is automatically generated (UUID v4).
95
99
96
100
```php
97
-
$recorder = Audio::record()
101
+
$recorder = Microphone::record()
98
102
->id('my-recording');
99
103
100
104
$id = $recorder->getId(); // 'my-recording'
@@ -109,7 +113,7 @@ Set a custom event class to dispatch when recording completes. By default, `Audi
109
113
```php
110
114
use App\Events\VoiceMessageRecorded;
111
115
112
-
Audio::record()
116
+
Microphone::record()
113
117
->event(VoiceMessageRecorded::class)
114
118
->start();
115
119
```
@@ -119,7 +123,7 @@ Audio::record()
119
123
Store the recorder's ID in the session for later retrieval. This is useful when the recording completes on the next request.
120
124
121
125
```php
122
-
Audio::record()
126
+
Microphone::record()
123
127
->id('voice-note')
124
128
->remember()
125
129
->start();
@@ -130,10 +134,10 @@ Audio::record()
130
134
Retrieve the last remembered audio recorder ID from the session. Use this in event listeners to correlate recordings.
131
135
132
136
```php
133
-
use Livewire\Attributes\On;
134
-
use Native\Mobile\Events\Audio\AudioRecorded;
137
+
use Native\Mobile\Attributes\OnNative;
138
+
use Native\Mobile\Events\Microphone\MicrophoneRecorded;
135
139
136
-
#[On('native:'.AudioRecorded::class)]
140
+
#[OnNative(MicrophoneRecorded::class)]
137
141
public function handleAudioRecorded(string $path, string $mimeType, ?string $id)
138
142
{
139
143
// For comparing with remembered IDs
@@ -150,7 +154,7 @@ Explicitly start the audio recording. This is optional - recordings auto-start i
150
154
**Returns:**`bool` - `true` if recording started successfully, `false` if it failed or was already started
Dispatched when an audio recording completes. The event includes the file path and recording ID.
167
171
@@ -171,10 +175,7 @@ Dispatched when an audio recording completes. The event includes the file path a
171
175
-`?string $id` - The recorder's ID, if one was set
172
176
173
177
```php
174
-
use Livewire\Attributes\On;
175
-
use Native\Mobile\Events\Audio\AudioRecorded;
176
-
177
-
#[On('native:'.AudioRecorded::class)]
178
+
#[OnNative(MicrophoneRecorded::class)]
178
179
public function handleAudioRecorded(string $path, string $mimeType, ?string $id)
179
180
{
180
181
// Store or process the recording
@@ -192,10 +193,6 @@ public function handleAudioRecorded(string $path, string $mimeType, ?string $id)
192
193
193
194
-**File Format:** Recordings are stored as M4A/AAC audio files (`.m4a`). This format is optimized for small file sizes while maintaining quality.
194
195
195
-
-**Storage Location:**
196
-
-**Android:** Recordings are stored in the app's cache directory (`context.cacheDir/audio_{timestamp}.m4a`). These are temporary files and may be deleted by the system.
197
-
-**iOS:** Recordings are stored persistently in `~/Library/Application Support/Audio/NativePHP_{timestamp}.m4a` and are excluded from iCloud backup.
198
-
199
196
-**Recording State:** Only one recording can be active at a time. Calling `start()` while a recording is in progress will return `false`.
200
197
201
-
-**Auto-Start Behavior:** If you don't explicitly call `start()`, the recording will automatically start when the `PendingAudioRecorder` is destroyed. This maintains backward compatibility with earlier versions.
198
+
-**Auto-Start Behavior:** If you don't explicitly call `start()`, the recording will automatically start when the `PendingMicrophone is destroyed. This maintains backward compatibility with earlier versions.
@@ -74,7 +74,7 @@ Fired when a barcode is successfully scanned.
74
74
-`string|null $id` - The scan session ID (if set)
75
75
76
76
```php
77
-
#[On('native:'.Scanned::class)]
77
+
#[OnNative(CodeScanned::class)]
78
78
public function handleScan($data, $format, $id = null)
79
79
{
80
80
if ($id === 'product-scanner') {
@@ -88,4 +88,6 @@ public function handleScan($data, $format, $id = null)
88
88
-**Platform Support:**
89
89
-**Android:** ML Kit Barcode Scanning (API 21+)
90
90
-**iOS:** AVFoundation (iOS 13.0+)
91
-
-**Permissions:** You must enable the `qr_code` permission in `config/nativephp.php` to use the scanner. Camera permissions are then handled automatically, and users will be prompted for permission the first time the scanner is used.
91
+
-**Permissions:** You must enable the `qr_code` permission in `config/nativephp.php` to use the scanner. Camera
92
+
permissions are then handled automatically, and users will be prompted for permission the first time the scanner is
0 commit comments