8
8
<v-toolbar color =" primary" flat >
9
9
<v-toolbar-title >VoiceMail</v-toolbar-title >
10
10
<v-spacer ></v-spacer >
11
+
12
+ <!-- Start / Finish recording -->
11
13
<v-btn
12
14
:color =" isRecording ? 'red' : 'primary darken-2'"
13
15
@click =" toggleRecorder"
14
16
>
15
17
<v-icon dark >{{
16
- isRecording ? 'mdi-pause ' : 'mdi-microphone'
18
+ isRecording ? 'mdi-stop ' : 'mdi-microphone'
17
19
}}</v-icon >
18
20
</v-btn >
19
- <v-btn icon @click =" stopRecording" >
20
- <v-icon >mdi-stop</v-icon >
21
+
22
+ <!-- discard recording -->
23
+ <v-btn icon :disabled =" !isRecording" @click =" stopRecording" >
24
+ <v-icon small >mdi-delete</v-icon >
21
25
</v-btn >
22
26
</v-toolbar >
23
27
<v-card-text >
24
- <current- timer :elapsed-time = " timer " ></current- timer >
28
+ <timer :timer-status = " timerStatus " ></timer >
25
29
26
30
<recordings-list
27
31
v-model =" selected"
53
57
import { WebAudioRecorder } from ' web-audio-recorder-js-webpack'
54
58
55
59
import RecordingsList from ' @/components/RecordingsList'
56
- import CurrentTimer from ' @/components/CurrentTimer '
60
+ import Timer from ' @/components/Timer '
57
61
58
62
const ENCODING_TYPE = ' mp3'
59
63
const ENCODE_AFTER_RECORD = true
60
64
61
65
export default {
62
66
components: {
63
67
RecordingsList,
64
- CurrentTimer
68
+ Timer
65
69
},
66
70
data () {
67
71
return {
68
- availableDevices: [],
69
- selectedDevice: null ,
70
- logData: ' ' ,
71
72
isRecording: false ,
72
73
audios: [
73
74
{ isPlaying: false , duration: ' 01:45' , volume: 50 },
@@ -80,58 +81,13 @@ export default {
80
81
input: null ,
81
82
audioContext: null ,
82
83
selected: null ,
83
- timer: null
84
- }
85
- },
86
- async created () {
87
- if (navigator && navigator .mediaDevices ) {
88
- const mediaDevices = await navigator .mediaDevices .getUserMedia ({
89
- audio: true
90
- })
91
-
92
- if (mediaDevices) {
93
- const devices = await navigator .mediaDevices .enumerateDevices ()
94
-
95
- this .availableDevices = devices .filter (
96
- (device ) => device .kind === ' audioinput'
97
- )
98
- }
84
+ timerStatus: ' stopped'
99
85
}
100
86
},
101
87
methods: {
102
88
toggleRecorder () {
103
89
this .isRecording = ! this .isRecording
104
- this .toggleTimer ()
105
- },
106
- toggleTimer () {
107
- if (this .isRunning ) {
108
- clearInterval (this .interval )
109
- console .log (' timer stops' )
110
- } else {
111
- this .interval = setInterval (this .incrementTime , 1000 )
112
- }
113
- this .isRunning = ! this .isRunning
114
- },
115
- incrementTime () {
116
- this .timer = + this .timer + 1
117
- },
118
- stopTimer () {
119
- // reset the count
120
- this .timer = 0
121
- // and reset the timer
122
- clearInterval (this .interval )
123
- this .isRunning = false
124
- },
125
- inputChanged () {
126
- // console.log('input changed')
127
- if (this .getUserMediaStream ) {
128
- }
129
- navigator .mediaDevices .getUserMedia ({
130
- audio: true ,
131
- deviceId: {
132
- exact: this .selectedDevice
133
- }
134
- })
90
+ this .timerStatus = this .isRecording ? ' started' : ' stopped'
135
91
},
136
92
startRecording () {
137
93
if (navigator .mediaDevices ) {
@@ -154,7 +110,7 @@ export default {
154
110
)
155
111
})
156
112
157
- this . log (
113
+ console . warn (
158
114
' getUserMedia() success, stream created, initializing WebAudioRecorder...'
159
115
)
160
116
@@ -172,30 +128,30 @@ export default {
172
128
encoding: ENCODING_TYPE ,
173
129
onEncoderLoading : (recorder , encoding ) => {
174
130
// show "loading encoder..." display
175
- this . log (' Loading ' + encoding + ' encoder...' )
131
+ console . warn (' Loading ' + encoding + ' encoder...' )
176
132
},
177
133
onEncoderLoaded : (recorder , encoding ) => {
178
134
// hide "loading encoder..." display
179
- this . log (encoding + ' encoder loaded' )
135
+ console . warn (encoding + ' encoder loaded' )
180
136
},
181
137
onComplete : (recorder , blob ) => {
182
- this . log (' Encoding complete' )
138
+ console . warn (' Encoding complete' )
183
139
const url = URL .createObjectURL (blob)
184
140
this .audios .push (url)
185
141
// createDownloadLink(blob, recorder.encoding);
186
142
}
187
143
})
188
144
189
145
this .recorder .setOptions ({
190
- timeLimit: 300 ,
146
+ timeLimit: 60 ,
191
147
encodeAfterRecord: ENCODE_AFTER_RECORD ,
192
148
mp3: {
193
149
bitRate: 160
194
150
}
195
151
})
196
152
197
153
this .recorder .startRecording ()
198
- this . log (' Recording started' )
154
+ console . warn (' Recording started' )
199
155
this .isRecording = true
200
156
})
201
157
.catch ((err ) => {
@@ -205,8 +161,7 @@ export default {
205
161
},
206
162
stopRecording () {
207
163
this .isRecording = false
208
-
209
- this .stopTimer ()
164
+ this .timerStatus = ' stopped'
210
165
211
166
// // stop microphone access
212
167
// //! can't do this, otherwise can't record further notes
@@ -216,12 +171,12 @@ export default {
216
171
// // every single time a new recording is started 🤔
217
172
// this.getUserMediaStream.getAudioTracks()[0].stop()
218
173
219
- // // tell the recorder to finish the recording (stop recording + encode the recorded audio)
220
- // this.recorder.finishRecording()
221
- // this.log ('Recording stopped')
174
+ // tell the recorder to finish the recording (stop recording + encode the recorded audio)
175
+ // this.recorder.finishRecording()
176
+ // console.warn ('Recording stopped')
222
177
// },
223
178
// log(event) {
224
- // this.logData += event + `<br>`
179
+ // console.warnData += event + `<br>`
225
180
// }
226
181
}
227
182
}
0 commit comments