LIST PRODUCTS PAGE

//Code snippets for MyVoiceCloud List Products page:  
	

RECORDING PAGE

//Code snippets for MyVoiceCloud Recording page:  
	
	var recorder = MyVoiceCloud.init({
                targetSelectorId: '#audio-player', 	//Put your own id here for your customised player
                clientId: 1, 						//Your MyVoiceCloud clientId
                apiUrl: 'https://api.myvoicecloud.com',
                hideFrontend: false, 				//Set to true/false to show/hide the player
                clientEntity: 3, 					//Your members unique id
  });

  recorder.clientAPI.socket.on('connected', function (e) {
      console.log('connected');    
      recorder.clientAPI.socket.on('file_recorded', function (e) {
          console.log('file recorded');
      });
  });
  
  MyVoiceCloud.onRecording(function (e) {
      console.log(e);
      $('.levels').html(e.levels[0]);
      $('.timing').html(e.recordingTime);
      $('.ar-sound-now').css('width', e.levels[0] + '%');
  });

//Example usage of GetProduct call
	recorder.clientAPI.getProduct('{{$product->category_tag}}',function(response){
      $('#transcript').html(response.data.transcription);
      document.getElementById('transcript').stop();
	})
	var saveTimeout = null;
	var pauseInterval = null;

//Listener to start record button:
//__________________________________

  $('.btn-start').click(function () {

    $('.btn-save').attr('disabled', 'disabled'); //Set the save button to disabled so user cant click until recording is done

    MyVoiceCloud.startRecording(); // < - THIS LINE STARTS THE RECORDING

    if(pauseInterval){
        $('#transcript').attr('scrollamount',1);
        clearInterval(pauseInterval);
        pauseInterval = null;
        $('.btn-pause').text($('.btn-pause').data('caption'));
    } else {
        clearTimeout(saveTimeout);
    }
  });
     
  MyVoiceCloud.on('record-is-started',function(){
    $('#transcript').attr('scrollamount',1);
    document.getElementById('transcript').start(); //Go start the scrolling of the transcript
  }); 
     
  MyVoiceCloud.on('record-is-stopped',function(){
    $('#transcript').attr('scrollamount',0);
    document.getElementById('transcript').stop();     
  });

//Listener to pause record button:
//__________________________________

  $('.btn-pause').click(function(){
    MyVoiceCloud.pauseRecording();
    var caption = $('.btn-pause').data('caption');
    if(!pauseInterval) {
        $('#transcript').attr('scrollamount',0);
        var secondsCount = 250;
        pauseInterval = setInterval(function () {
            if (secondsCount < 0) {
                clearInterval(pauseInterval);
                pauseInterval = null;
            } else {
                $('.btn-pause').text(caption + '('+secondsCount+'s.)');
                secondsCount--;
            }
        }, 1000);
    }
  });
 
//Listener to stop recording button:
//___________________________________

  $('.btn-stop').click(function () {
    MyVoiceCloud.stopRecording({
        title: 'product_{{$product->title}}',
        tags: 'product_{{$product->category_tag}}'
  }); // < - THIS LINE STOPS THE RECORDING and names the recorded file
    //Options title and tags are REQUIRED.
    //"title" can be anything. We use it to store the product title in this example.
    //"tags" is needed to be fetched from the products category tag which is set in MyVoiceCloud admin for the chosen product. This is used to mix the products audio track correctly.
    document.getElementById('transcript').stop(); 
    $('#transcript').attr('scrollamount',1);
    clearInterval(pauseInterval);
    pauseInterval = null;
    $('.btn-pause').text($('.btn-pause').data('caption'));
  });
       
  MyVoiceCloud.on('export-is-started',function(){
    console.log('export has started');
    $('.btn-stop').html($('btn-stop').data('export'));
  });

  MyVoiceCloud.on('file_recorded', function (data) {
    $('.btn-save').removeAttr('disabled');
    $('.btn-stop').html($('btn-stop').data('stop'));
  });
  document.getElementById('transcript').stop(); //Lets stop the scrolling of the transcript
  });

//Great stuff to monitor the ongoing recording:
//____________________________________

  MyVoiceCloud.onRecording(function(e){
    console.log(e); 									//Log the event to the console
    $('.levels').html(e.levels[0]); 					//Microphone input level from channel 0 (MONO)
    $('.timing').html(e.recordingTime); 				//How long you've been recording
    $('.ar-sound-now').css('width', e.levels[0] + '%');	//Updating the level meter
  });

LIST RECORDINGS PAGE

//Code snippets for MyVoiceCloud List Recordings page:  

	var recorder = MyVoiceCloud.init({
                targetSelectorId: '#audio-player', 		//Put your own id here for your customized player
                clientId: 1, 							//Your MyVoiceCloud clientId
                apiUrl: 'https://api.myvoicecloud.com',
                hideFrontend: false, 					//Set to true/false to show/hide the player
                clientEntity: {{Auth::user()->id}}, 	// Your members unique id
				hideRecorder: true,
    		});
 
       
//Make a call for getPlayList, respond with object containing the list of records
 
            recorder.clientAPI.getPlayList(function(response){
                console.log(response); //Log the response to the console
                response.data = response.data.reverse();
                for(var i in response.data){
                    var item = response.data[i];
                    var newItm = $('#player_donor').clone(true);
                    newItm.find('.title').html('#'+item.id+' '+item.name_of_file);
                    newItm.find('.tags').html(item.tags.replace('_',' '));
                    newItm.find('audio source').attr('src','https://api.myvoicecloud.com/storage/'+item.path);
                    newItm.find('.created_at').html(item.created_at);
                    $('.records').append(newItm);
                }
            });