惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
Google Developers Blog
F
Fortinet All Blogs
Microsoft Azure Blog
Microsoft Azure Blog
腾讯CDC
Vercel News
Vercel News
Recent Announcements
Recent Announcements
博客园 - Franky
小众软件
小众软件
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The Cloudflare Blog
宝玉的分享
宝玉的分享
I
InfoQ
博客园 - 聂微东
Jina AI
Jina AI
J
Java Code Geeks
V
V2EX
U
Unit 42
Stack Overflow Blog
Stack Overflow Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
阮一峰的网络日志
阮一峰的网络日志
L
LangChain Blog
T
The Blog of Author Tim Ferriss
量子位

WordPress Plugin

How to Create an Audio Player Playlist from an XML File Copy Audio URL in Wonder Audio Player YouTube Error 153 | WordPress Plugin Wonder Lightbox JavaScript Events | WordPress Plugin How to Create a WordPress Gallery from an XML File How to Remove URL Query Parameters in Wonder Lightbox How to Dynamically Create a WordPress Image and Video Gallery Using WordPress Media Library IDs How to Add an Image to the Lightbox Gallery Without Showing It in the Grid Gallery How to Make the PDF Page Fit the Entire Lightbox Width When Opening a PDF File
Double Tap to Play or Pause the WordPress Audio Player on...
2024-06-05 · via WordPress Plugin

Plugin:

Wonder Audio Player

Tutorial:

In the tutorial Use the Space Key to Play or Pause the WordPress Audio Player, we learned how to use the space key to control the audio player. However, on touch devices, there isn't a keyboard available. This tutorial will guide you on how to play or pause the WordPress audio player on touch devices by double-tapping the webpage in mobile web browsers. This tutorial also provides code to support double-click on regular desktop and laptop computers.

An online demo is as follows:

To support double-tap on mobile touch devices, edit the player in the Wonder Audio Player plugin. Navigate to the 'Options' tab, then to 'Advanced Options,' and add the following code to the 'Custom JavaScript' input box:

(function($){
  $(document).ready(function() {
    var timeDiff = 500;
    var lastClick = 0;
    var startEvent = "touchstart";
    $(document).on(startEvent, function() {
      var clickTime = Date.now();
      var obj = $("#wonderpluginaudio-AUDIOPLAYERID").data("object");
      var eventFired = false;
      if (obj) { if (lastClick > 0) { if (clickTime < lastClick + timeDiff) {
        eventFired = true;
        lastClick = 0;
        if (obj.audioPlayer.isPlaying) {
          obj.pauseAudio();
        } else {
          obj.playAudio();
        }
      } } };
      if (!eventFired) {
        lastClick = clickTime;
      }
    });
  });
})(jQuery);

The number 500 in the code represents the time difference (500ms) between the two taps. You can change this value if you think the time difference is too long or too short.

If you want to support double-click on regular desktop or laptop computers as well, use the following code:

(function($){
  $(document).ready(function() {
    var timeDiff = 500;
    var lastClick = 0;
    var startEvent = ("ontouchstart" in window) ? "touchstart" : "mousedown";
    $(document).on(startEvent, function() {
      var clickTime = Date.now();
      var obj = $("#wonderpluginaudio-AUDIOPLAYERID").data("object");
      var eventFired = false;
      if (obj) { if (lastClick > 0) { if (clickTime < lastClick + timeDiff) {
        eventFired = true;
        lastClick = 0;
        if (obj.audioPlayer.isPlaying) {
          obj.pauseAudio();
        } else {
          obj.playAudio();
        }
      } } };
      if (!eventFired) {
        lastClick = clickTime;
      }
    });
  });
})(jQuery);