Wednesday, May 8, 2024
HomeiOS Developmentjavascript - Report and play audio on iOS

javascript – Report and play audio on iOS


I’ve a activity play some audio tracks, then report person voice and ship it to server as 1 second chunks. Each of this actions repeat is in loop. In different phrases, one thing like a dialogue.

Generally the recorder stops listening to the person, though recording is in progress (ondataavailable continues firing). And after about 10 seconds an error seems within the console:

A MediaStreamTrack ended as a result of a seize failure

Participant:

const audio = new Audio();
audio.loop = false;

const playAudio = (base64: string) =>
  new Promise((resolve, reject) => {
    audio.onended = resolve;
    audio.onerror = reject;
    audio.src = base64;
    audio.play().catch(reject);
  });

Recorder:

import { IMediaRecorder, MediaRecorder, register, } from 'extendable-media-recorder';
import { join } from 'extendable-media-recorder-wav-encoder';

let mediaRecorder: IMediaRecorder;
navigator.mediaDevices.getUserMedia({ audio: { echoCancellation: true } })
  .then(stream => (mediaRecorder = new MediaRecorder(stream, { mimeType: 'audio/wav' })));

export const begin = async (listener: (buffer: Blob) => void) => {
  cease();
  mediaRecorder?.ondataavailable = ({ knowledge }) => listener(blob);
  mediaRecorder?.begin(1000);
};

export const cease = () => mediaRecorder?.cease();

This error is noticed primarily on iOS



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments