phonegap / phonegap-plugin-media-recorder

Apache License 2.0
14 stars 20 forks source link

Can't get plugin to work #21

Closed liping11 closed 6 years ago

liping11 commented 6 years ago

Total beginner here, please bear with me. I have been trying to get the Phonegap Media Recorder plugin working on my app the past week but no luck. What I'd like to do is simply allow users to record, stop recording and playback their recording.

Placed this code in a JS file and it works - browser test shows it request access for camera and microphone:

navigator.mediaDevices.getUserMedia({
    'audio': true,
    'video': {facingMode: 'user'}
 }).then(function(stream) {
    var mediaRecorder = new MediaRecorder(stream);
 });

But then I can't get any recording happening.

I placed mediaRecorder.start(); as on click event for record button; mediaRecorder.stop(); as on click event for stop button;

and this chunk of code in Play button:

mediaRecorder.ondataavailable = function(blob) {
    var videoTag = document.getElementById("vid");// video tag
    if(device.platform === 'iOS') {               // iOS device
        videoTag.src = mediaRecorder.src;
    } else {                                     // Android device
        var recordedChunks = [];
        recordedChunks.push(blob.data);
        videoTag.src = URL.createObjectURL(new
                       Blob(recordedChunks));
    }
}
mediaRecorder.requestData();

I'm completely stumped with this. Am I doing this correctly at all? I tried following the Github instructions as best as I could and simply couldn't get it to work. Could anyone please help with guiding me how to do it? Thanks!