phonegap / phonegap-plugin-media-recorder

Apache License 2.0
14 stars 20 forks source link

Get the data after recording iOS #22

Closed facuzeta closed 5 years ago

facuzeta commented 5 years ago

Expected Behaviour

I wonder why I cant get the data as a blob using iOS

Actual Behaviour

I can record the audio and after recording I can listen using a <audio> but I cant find the way to get the data as blob or even read correctly the recorded file and build a blob.

I just want a blob because I need to send the file to a server.

This code works ok in Android

Reproduce Scenario (including but not limited to)

Simple recording example

my_recorder = null;
navigator.mediaDevices.getUserMedia({audio: true}).then(function(mediaStream){
    my_recorder = new MediaRecorder(mediaStream);
    console.log(my_recorder)

    recorder.ondataavailable = function(blob_without_data){
        console.log(blob_without_data)
    };
    my_recorder.onstop = console.log
    my_recorder.onerror = console.log;
},console.log );

After run this, I did

my_recorder.start()

and after a few seconds I did

my_recorder.stop()

After doing this, I can listen the audio if I set an audio element source to my_recorder.src (by the way it has the following value: file:///var/mobile/Containers/Data/Application/11945153-8685-4C9F-9A1E-E5DEE39A6FCE/tmp/recording.m4a

When I change the native path of my_recorder to cvdfile:// with


resolveLocalFileSystemURL(my_recorder.src, function(entry) {
    console.log('cdvfile URI: ' + entry.toInternalURL())})

it returns

cdvfile URI: cdvfile://localhost/temporary/recording.m4a

So, with this I tried to convert read this file to create a blob with the following code:

my_blob = null;
window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, function (fs) {
    fs.root.getFile('recording.m4a', {},
        function (fileEntry) {
            fileEntry.file(function (file) {
                var reader = new FileReader();
                reader.onloadend = function() {
                    mimeType='audio/m4a';                             
                    my_blob = new Blob([new Uint8Array(this.result)], { type: mimeType });
                    console.log('my_blob.size:',my_blob.size)
                };
                ;
                 reader.readAsArrayBuffer(file);
            });
        },);
});

And I got no errors and

my_blob.size: – 78865

my_blob < Blob {size: 78865, type: "audio/m4a", slice: function}

But my_blob actually has not data.

Is there any other way to get this?

Platform and Version (eg. Android 5.0 or iOS 9.2.1)

Running on an iPad with iOS

Cordova CLI version and cordova platform version

9.0.0 (cordova-lib@9.0.1) ios 5.0.1

Plugin version

phonegap-plugin-media-recorder 1.1.0 "Media Recorder" phonegap-plugin-media-stream 1.2.1 "MediaStream"

Sample Code that illustrates the problem

Logs taken while reproducing problem

facuzeta commented 5 years ago

I find the way to send the file