Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/release the microphone after record an audio for a tile #1444

Merged
merged 3 commits into from
Apr 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/components/VoiceRecorder/VoiceRecorder.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import IconButton from '../UI/IconButton';
import { isCordova, requestCvaPermissions } from '../../cordova-util';
import messages from './VoiceRecorder.messages';
import './VoiceRecorder.css';

let mediaStream = undefined;
class VoiceRecorder extends Component {
static propTypes = {
/**
Expand Down Expand Up @@ -45,6 +45,7 @@ class VoiceRecorder extends Component {
this.mediaRecorder = new window.MediaRecorder(stream);
this.mediaRecorder.start();
this.setState({ isRecording: true });
mediaStream = stream;
})
.catch(function(err) {
console.log(err.message);
Expand All @@ -53,6 +54,11 @@ class VoiceRecorder extends Component {

stopRecording = () => {
this.mediaRecorder.stop();
try {
if (mediaStream) mediaStream.getTracks().forEach(track => track.stop());
} catch (error) {
console.error('Error during stop recording', error);
}

this.mediaRecorder.ondataavailable = event => {
this.chunks = event.data;
Expand Down