Advertisement
Guest User

Untitled

a guest
Apr 14th, 2014
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <meta charset="utf-8" />
  5.         <title>RecordRTC over Node.js</title>
  6.  
  7.         <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  8.         <script src="/js/RecordRTC.js"> </script>
  9.         <style>
  10.             html { background-color: #f7f7f7; }
  11.  
  12.             body {
  13.                 background-color: white;
  14.                 border: 1px solid rgb(15, 158, 238);
  15.                 margin: 1% 35%;
  16.                 text-align: center;
  17.             }
  18.  
  19.             hr {
  20.                 border: 0;
  21.                 border-top: 1px solid rgb(15, 158, 238);
  22.             }
  23.  
  24.             a {
  25.                 color: #2844FA;
  26.                 text-decoration: none;
  27.             }
  28.  
  29.             a:hover, a:focus { color: #1B29A4; }
  30.  
  31.             a:active { color: #000; }
  32.         </style>
  33.     </head>
  34.     <body>
  35.         <p>
  36.             <video id="camera-preview" autoplay controls style="border: 1px solid rgb(15, 158, 238); width: 94%;"></video>
  37.         </p><hr />
  38.  
  39.         <div>
  40.                 <h2 id="download-url"></h2><br />
  41.             <button id="start-recording">Start Recording</button>
  42.             <button id="stop-recording" >Stop Recording</button>
  43.             <button id="upload-recording">Upload Recording</button>
  44.         </div>
  45.         <div id="result">
  46.               <video id="result_camera" controls style="border: 1px solid rgb(15, 158, 238); width: 94%;">
  47.                      <source id="mkv_source" type="video/mkv"/>
  48.               </video>
  49.         </div>
  50.  
  51. <script>
  52.  
  53. $(document).ready(function(){
  54.  
  55.  
  56.       var startRecording = document.getElementById('start-recording');
  57.       var stopRecording = document.getElementById('stop-recording');
  58.       var uploadRecordingBtn = document.getElementById('upload-recording');
  59.       var cameraPreview = document.getElementById('camera-preview');
  60.      
  61.             var timeoutInt = 0;
  62.             var secondCount;
  63.       var audio = document.querySelector('audio');
  64.      
  65.             var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
  66.            
  67.             navigator.getUserMedia = navigator.getUserMedia ||
  68.                     navigator.webkitGetUserMedia || navigator.mozGetUserMedia ||
  69.                     navigator.msGetUserMedia;
  70.  
  71.       var recordAudio, recordVideo;
  72.       startRecording.onclick = function() {
  73.  
  74.             navigator.getUserMedia = navigator.getUserMedia ||
  75.                     navigator.webkitGetUserMedia || navigator.mozGetUserMedia ||
  76.                     navigator.msGetUserMedia;
  77.  
  78.           navigator.getUserMedia({
  79.          
  80.                   audio: true
  81.                  
  82.               }, function(stream) {
  83.              
  84.                   recordAudio = RecordRTC(stream, {
  85.                       bufferSize: 16384
  86.                   });
  87.  
  88.                                   navigator.getUserMedia({
  89.                                  
  90.                                           video: true
  91.                                          
  92.                                       }, function(stream2) {
  93.                                      
  94.                                           cameraPreview.src = window.URL.createObjectURL(stream2);
  95.                                           cameraPreview.play();
  96.  
  97.                                                     if(isFirefox){
  98.                                                 recordVideo = RecordRTC(stream2);
  99.                                                     }else{
  100.                                                         recordVideo = RecordRTC(stream2,{type:"video"});
  101.                                                     }
  102.                                                    
  103.                                           stopRecording.disabled = false;
  104.                                                     uploadRecordingBtn.disabled = true;
  105.                                             startRecording.disabled = true;
  106.                                            
  107.                                            
  108.                                                     recordAudio.startRecording();
  109.                                                     recordVideo.startRecording();
  110.                                                     secondCount = 1;
  111.                                                     setTimer(secondCount);
  112.                                            
  113.                                       }, function(error) {
  114.                                           alert(JSON.stringify(error));
  115.                                       });
  116.  
  117.                   stopRecording.disabled = false;
  118.                             uploadRecordingBtn.disabled = true;
  119.                     startRecording.disabled = true;
  120.                    
  121.               }, function(error) {
  122.                   alert(JSON.stringify(error));
  123.               });
  124.              
  125.  
  126.                            
  127.       };
  128.  
  129.  
  130.       stopRecording.onclick = function() {
  131.                 stopRecordingAll();            
  132.       };
  133.      
  134.             uploadRecordingBtn.onclick =  function() {
  135.            
  136.             startRecording.disabled = false;
  137.             stopRecording.disabled = true;
  138.           //uploadRecordingBtn.disabled = true;
  139.                 uploadBlob();
  140.                
  141.       };
  142.      
  143.       function stopRecordingAll(){
  144.         cameraPreview.src = null;
  145.             startRecording.disabled = false;
  146.             stopRecording.disabled = true;
  147.           uploadRecordingBtn.disabled = false; 
  148.          
  149.             recordAudio.stopRecording();
  150.             recordVideo.stopRecording();
  151.             clearTimeout(timeoutInt);
  152.       }
  153.      
  154.             function setTimer(secondCount){
  155.            
  156.                 if(secondCount < 12){
  157.                
  158.                     document.getElementById("txt").innerHTML="seconds : "+secondCount ;
  159.                 secondCount++;
  160.                
  161.                 timeoutInt = setTimeout(
  162.                
  163.                     function(){
  164.                         setTimer(secondCount);
  165.                         },
  166.                        
  167.                         1000);
  168.                                                
  169.                 }else{
  170.                
  171.                 clearTimeout(timeoutInt);
  172.                     alert("You reach to maximum limit of 11 seconds");
  173.                     stopRecordingAll();
  174.                
  175.                 }
  176.                
  177.             }
  178.  
  179.         function uploadBlob(){
  180.  
  181.             var fd = new FormData();
  182.                 var vblob = new Blob([recordVideo.getBlob()],{type: "video/webm"});
  183.                 var ablob = new Blob([recordAudio.getBlob()],{type: "audio/wav"});
  184.                
  185.             fd.append('videoBlob', vblob);
  186.             fd.append('audioBlob', ablob);
  187.             fd.append('chrome',true);
  188.            
  189.             $.ajax({
  190.                 type: 'POST',
  191.                 url: '/uploadBlob',
  192.                 data: fd,
  193.                 processData: false,
  194.                 contentType: false
  195.             }).done(function(data) {
  196.                 console.log(data);
  197.                 resultVideo = document.getElementById("result_camera")
  198.                 resultVideo.src = document.location.origin+data.video_url
  199.                 resultVideo.play();
  200.             });
  201.  
  202.         }
  203.        
  204.        
  205. });
  206.         </script>
  207.         <div id="txt"></div>
  208.     </body>
  209. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement