question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Requires two clicks to play on iOS

See original GitHub issue

Please advice what is the right way to unlock <audio> element on user gesture as required by iOS. I have the following in my code (shortened for brevity), works without a hitch on Android/Windows/MacOS, but on iOS requires two clicks.

    componentDidMount() {
        document.addEventListener('click', this.onPageClick);
    }

    componentWillUnmount() {
        document.removeEventListener('click', this.onPageClick);
    }

    onPageClick(e){
        const $el = $(e.target).closest('a[data-playable]');
        const url = $el.attr('href')
        
        if( $el.length ){ //check if a "playable" link was clicked
            e.preventDefault();
            this.play(url);
            return false;
        }
    }

    play(url) {
       const newState = {
            url,
            played: 0,
            loaded: 0,
            playing: true
        };
        this.setState(newState);
    }

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

3reactions
sarutolecommented, Oct 13, 2017

Adding autoplay="true" to <audio> element for iOS devices fixes the “two-clicks” issue. (By the way, currently the react-player demo also has this problem.)

fileConfig: {
     attributes: { autoPlay: /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream }
},
0reactions
sangroyacommented, Jan 31, 2022

I also face the same issue and it’s work for me by setting the volume =0 for iphone as in iphone volume can’t be control via js

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why/when do I have to tap twice to trigger click on iOS
In many cases, it seems I need to tap once to trigger a hover and then again to trigger a click. The Mobile...
Read more >
How to turn off Double Click to Install for apps on iPhone or iPad
Having trouble with the double click to install apps via the App Store ... Want another option that doesn't require two hands to...
Read more >
How To Disable Double Click To Install - macReports
Double Click to Install ... First of all, you cannot disable the need to verify your purchases. However, there is a way, instead...
Read more >
Adjust settings for the side or Home button on iPhone
Click Speed: Choose the speed required to double-click or triple-click the button—Default, Slow, or Slowest. Press and Hold to Speak: Choose whether Siri ......
Read more >
Double clicks required on Mobile devices to open links
There is a known bug on iOS that sometimes occurs when using the Delay JS. This bug causes links to not work until...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found