Click here to Skip to main content
15,889,651 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="https://cdn.webrtc-experiment.com/commits.js"></script>
    <script src="https://cdn.WebRTC-Experiment.com/MediaStreamRecorder.js"></script>
    <script src="https://cdn.WebRTC-Experiment.com/gumadapter.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>




    <script>

        function captureUserMedia(mediaConstraints, successCallback, errorCallback) {
            navigator.mediaDevices.getUserMedia(mediaConstraints).then(successCallback).catch(errorCallback);
        }

        var mediaConstraints = {
            audio: true
        };
        document.querySelector('#save-recording').onclick = function () {
            this.disabled = true;
            mediaRecorder.save();
            // alert('Drop WebM file on Chrome or Firefox. Both can play entire file. VLC player or other players may not work.');
        };
        function startRecording(idx) {
            $('#start-recording').disabled = true;
            audiosContainer = document.getElementById('audios-container');
            document.getElementById("clicks").innerHTML = "Recording Started";

            var f = document.getElementById('clicks');
            setInterval(function () {
                f.style.display = (f.style.display == 'none' ? '' : 'none');
            }, 1000);

            captureUserMedia(mediaConstraints, onMediaSuccess, onMediaError);
        };

        function stopRecording() {
            $('#stop-recording').disabled = true;

            document.getElementById("clicks").innerHTML = "Recording Stopped";

            var f = document.getElementById('clicks');
            setInterval(function () {
                f.style.display = (f.style.display == 'none' ? '' : 'none');
            }, 1000);
            mediaRecorder.stop();
            mediaRecorder.stream.stop();


            $('.start-recording').disabled = false;
        };

        function saveRecording() {
            mediaRecorder.save();
        };

        var mediaRecorder;

        function onMediaSuccess(stream) {
            mediaRecorder = new MediaStreamRecorder(stream);
            mediaRecorder.stream = stream;
            mediaRecorder.mimeType = 'audio/wav';
            mediaRecorder.audioChannels = 1;
            mediaRecorder.ondataavailable = function (blob) {
                $('#record-audio').html("<audio controls=''><source src=" + URL.createObjectURL(blob) + "></source></audio>");
            };

            var timeInterval = 360 * 1000;

            mediaRecorder.start(timeInterval);

            $('#stop-recording').disabled = false;
        }

        function onMediaError(e) {
            console.error('media error', e);
        }

        function bytesToSize(bytes) {
            var k = 1000;
            var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
            if (bytes === 0) return '0 Bytes';
            var i = parseInt(Math.floor(Math.log(bytes) / Math.log(k)), 10);
            return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i];
        }

        function getTimeLength(milliseconds) {
            var data = new Date(milliseconds);
            return data.getUTCHours() + " hours, " + data.getUTCMinutes() + " minutes and " + data.getUTCSeconds() + " second(s)";
        }

        window.onbeforeunload = function () {
            $('#start-recording').disabled = false;
        };


 
    </script>


</head>
<body>

    <button class="btn btn-primary" id="start-recording" onclick="startRecording()">Recording Start</button>
    <button class="btn btn-default" id="stop-recording" onclick="stopRecording()">Stop</button>
    <button class="btn btn-default" id="save-recording" onclick="saveRecording()">Save</button>
    <div id="record-audio"></div>
    <span id="clicks">0</span>
 
</body>
</html>


What I have tried:

How to Audio Recording Directly save database please Help me not file we have path only how to retrieve 
Posted
Updated 28-Mar-19 5:20am
v2

1 solution

I've looked at the official document here: GitHub - streamproc/MediaStreamRecorder[^] and seems like the Save() method has an overload method which allows you to dump a Blob data. You can then create an API that accepts the blob data and save it to your database via AJAX call.

To get a direct support from this library, I would recommend you to open an issue to their official repo here: Issues · streamproc/MediaStreamRecorder · GitHub[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900