cordova-plugin-audioinput icon indicating copy to clipboard operation
cordova-plugin-audioinput copied to clipboard

Add getAudioMediaStream() function returning MediaStream

Open edimuj opened this issue 6 years ago • 3 comments

Some apps may need a MediaStream instead of an AudioNode or raw audio data.

It should therefore be possible to also get a MediaStream from the audioinput.

Should be implemented by returning the stream from a MediaStreamAudioDestinationNode.

This would enable you to do stuff like this:

var chunks = [];
audioinput.start({streamToWebAudio: true}); // Start the capture
var stream = audioinput.getAudioMediaStream(); // Create/get a stream destination
var mediaRecorder = new MediaRecorder(stream); // Create a MediaRecorder

mediaRecorder.ondataavailable = function(evt) {
    chunks.push(evt.data); // push each chunk (blobs) in an array
};

mediaRecorder.onstop = function(evt) {
    var blob = new Blob(chunks, { 'type' : 'audio/ogg; codecs=opus' }); // Create a blob
    document.querySelector("audio").src = URL.createObjectURL(blob); // <audio controls></audio>
};

edimuj avatar Apr 05 '18 23:04 edimuj

Reminder: MediaStream and CreateMediaStreamDestination isn't available in the iOS WebViews, the change should take this into account. Maybe using polyfills on platforms where these where they aren't available so that getAudioMediaStream returns an object implementing the major functionality that MediaStream normally offers would be a good approach?

edimuj avatar Aug 02 '18 12:08 edimuj

Hi i want implement this plugin in my cordova app. I want implement this in webRTC conection, but ios not have getUserMedia() function. Please you can me help ?

projetoarduino avatar Oct 16 '18 10:10 projetoarduino

Yes, the missing getUserMedia in the iOS webviews is one of the reasons that this plugin exists, but it isn't currently a complete implementation of getUserMedia (for example only audio input is supported).

But luckily there already exists a cordova plugin for using WebRTC on iOS: https://github.com/BasqueVoIPMafia/cordova-plugin-iosrtc

I would recommend you to look into that plugin instead.

edimuj avatar Oct 17 '18 09:10 edimuj