You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

audio tag auto-play not working

I have a webRTC voice calling application using javascript.

Whenever it receives a stream , it will dynamically create a audio tag and add stream to its srcObject then play it.


While trying to play it, it throws following error

The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission


Following is the source code:


      const audioElement = document.createElement("audio");
      audioElement.srcObject = stream;
      audioElement.id = socketid;
      audioElement.key = socketid;
      audioElement.muted = false;
      audioElement.autoplay = true;
      audioElement.playsInline = true;


      // Append the audio element to the parent div
      allAudioStreamBlockRef.current.appendChild(audioElement);
      audioElement.play().catch((error) => {
        
          window.alert("Audio playback error: " + error.message);
                 
      });


Based on research, i found that it was because of auto-play blocking policy


So i have added a button and tried to play it again


audioElementsRef.current.forEach((audioElement) => {
        audioElement.muted = false;
        audioElement.play().catch((error) => {
         
          console.log(
            `[INFO][CLIENT] Again getting error while playing: ${error.message}`
          );
        });
      });


But still getting same error. it is not able to play the audio even after getting user interaction (play using a button click)



audio is playing in iPadOS v15.7.8 safari Also tested in iphone (IOS v16.1, v16.1.1) everything was working


Issue occurred in iPadOS 16.2 safari browser only.



How to fix this ? what went wrong ?

iPad mini (5th generation)

Posted on Oct 11, 2023 9:26 PM

Reply
Question marked as Top-ranking reply

Posted on Oct 12, 2023 4:46 AM

You might be best advised to seek assistance from Apple's Developer Community.

Apple Developer Forums


1 reply

audio tag auto-play not working

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.