Sound not playing in iPad and iPhone

Viewed 28

I've done a website with Django where I record the audio, create an mp3 file and then use it on it. And I'm having a problem to play the sound in Apple devices. The sound plays correctly on Windows computers, Android devices and Mac computers.

But when you access the website with iPhone or iPad, the sound doesn't play.

I guess that the problem is on the way that I create the audio file in the Javascript.

$("#send_btn").click(function() {
    if(myFile != null){
      var csrf = $('input[name="csrfmiddlewaretoken"]').val();
      var url = "/xxxxxxxxxxx";
      var data = new FormData();
      data.append('recorded_audio', myFile);
      data.append('csrfmiddlewaretoken', csrf);
      $.ajax({
          url: url,
          method: 'post',
          data: data,
          success: function(data){
            setTimeout(function() {
              window.location.href ="xxxxxxxxxxx";
            }, 2000);
          },
          cache: false,
          contentType: false,
          processData: false
      });
    }
    else{
      if(myFile == null){
        alert('You should record an audio to continue.');
      }
    }
  });

  record_btn.onclick = () => {
    $('#stop_btn').removeClass('hidden');
    $('#record_btn').addClass('hidden');
    $('#voice-bars').removeClass('hidden');
    device = navigator.mediaDevices.getUserMedia({ audio: true});
    
    device.then(stream => {
      recorder = new MediaRecorder(stream);
      var items = [];
      recorder.start();

      recorder.addEventListener('dataavailable', e => {
        items.push(e.data);
      });

      recorder.addEventListener('stop', e => {
        blob = new Blob(items, { 'type': 'audio/mp3;' });
        myFile = new File([blob], 'audio.mp3');
        $('#source').attr("src", URL.createObjectURL(blob));
      });
    });
  }
1 Answers
Related