Skip to content

Commit b36ccd0

Browse files
committed
Fix remaining issues from final logical evaluation
- Add CSS styles for audio visualizer (.pid and .pids-wrapper) - Fix audio MIME type from video/mp4 to audio/mp4 in audioRecordAudioTask - Make video recordings include audio by default with opt-out via disableAudio flag - Add URL cleanup to prevent memory leaks (track and revoke blob URLs) - Add beforeDestroy lifecycle hook to clean up resources
1 parent ce341eb commit b36ccd0

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

src/components/InputSelector/InputSelector.vue

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
:constraints="valueConstraints"
3838
:selected_language="selected_language"
3939
:init="init"
40-
:audio="false"
40+
:audio="getVideoAudioSetting('videoCheck')"
4141
:visualizer="false"
4242
v-on:valueChanged="sendData"/>
4343
</div>
@@ -59,7 +59,7 @@
5959
:constraints="valueConstraints"
6060
:selected_language="selected_language"
6161
:init="init"
62-
:audio="false"
62+
:audio="getVideoAudioSetting(inputType)"
6363
:visualizer="false"
6464
:mode="inputType"
6565
:fieldData="fieldData"
@@ -333,6 +333,15 @@ export default {
333333
};
334334
},
335335
methods: {
336+
getVideoAudioSetting(inputType) {
337+
// Check if there's a specific setting to disable audio for video recording
338+
// Look in valueConstraints for a disableAudio flag
339+
if (this.valueConstraints && this.valueConstraints['http://schema.repronim.org/disableAudio']) {
340+
return !this.valueConstraints['http://schema.repronim.org/disableAudio'][0]['@value'];
341+
}
342+
// Default: include audio for all video recordings
343+
return true;
344+
},
336345
skip() {
337346
this.$emit('skip');
338347
},

src/components/Inputs/MediaRecord/MediaRecord.vue

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
</div>
2929
<div v-if="mode==='audioRecordAudioTask' || mode==='videoRecordAudioTask'" class="mb-3">
3030
<audio controls>
31-
<source :src="getAudioSource" type="video/mp4">
31+
<source :src="getAudioSource" type="audio/mp4">
3232
Your browser does not support the audio element.
3333
</audio>
3434
</div>
@@ -74,6 +74,7 @@ function handleInit(newInit) {
7474
this.hasRecording = true;
7575
} else if (newInit instanceof Blob) {
7676
const blobURL = URL.createObjectURL(newInit);
77+
this.blobURLs.push(blobURL); // Track for cleanup
7778
if (this.video) {
7879
this.recording.src = blobURL;
7980
} else {
@@ -128,6 +129,7 @@ export default {
128129
hasError: false,
129130
devices: [],
130131
tempDeviceName: null,
132+
blobURLs: [], // Track blob URLs for cleanup
131133
};
132134
},
133135
computed: {
@@ -180,6 +182,14 @@ export default {
180182
}
181183
handleInit.call(this, this.init);
182184
},
185+
beforeDestroy() {
186+
// Clean up blob URLs when component is destroyed
187+
this.cleanupBlobURLs();
188+
// Stop any active media streams
189+
if (this.mediaRecorder && this.mediaRecorder.stream) {
190+
this.mediaRecorder.stream.getTracks().forEach(track => track.stop());
191+
}
192+
},
183193
methods: {
184194
getDevices() {
185195
navigator.mediaDevices.enumerateDevices().then((devices) => {
@@ -236,10 +246,18 @@ export default {
236246
clearInterval(this.interval);
237247
},
238248
reset() {
249+
this.cleanupBlobURLs();
239250
this.hasRecording = false;
240251
this.isRecording = false;
241252
this.initializeMedia();
242253
},
254+
cleanupBlobURLs() {
255+
// Clean up all blob URLs to prevent memory leaks
256+
this.blobURLs.forEach(url => {
257+
URL.revokeObjectURL(url);
258+
});
259+
this.blobURLs = [];
260+
},
243261
initializeMedia() {
244262
navigator.mediaDevices.getUserMedia(this.mediaConstraints).then(this.initializeRecorder).catch(() => {
245263
this.hasError = true;
@@ -260,6 +278,7 @@ export default {
260278
this.timeRemaining = this.recordingTime / 1000;
261279
this.mediaRecorder.ondataavailable = (e) => {
262280
const blobURL = URL.createObjectURL(e);
281+
this.blobURLs.push(blobURL); // Track for cleanup
263282
if (this.video) {
264283
this.recording.src = blobURL;
265284
} else {
@@ -312,3 +331,20 @@ export default {
312331
},
313332
};
314333
</script>
334+
335+
<style scoped>
336+
.pids-wrapper {
337+
width: 100%;
338+
background-color: white;
339+
padding: 10px 0;
340+
}
341+
342+
.pid {
343+
width: calc(8% - 10px);
344+
height: 10px;
345+
display: inline-block;
346+
margin: 5px;
347+
background-color: #e6e7e8;
348+
transition: background-color 0.1s ease;
349+
}
350+
</style>

0 commit comments

Comments
 (0)