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

推荐订阅源

腾讯CDC
The Cloudflare Blog
IT之家
IT之家
V
V2EX
雷峰网
雷峰网
MyScale Blog
MyScale Blog
P
Proofpoint News Feed
Stack Overflow Blog
Stack Overflow Blog
博客园 - Franky
Engineering at Meta
Engineering at Meta
S
SegmentFault 最新的问题
GbyAI
GbyAI
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 司徒正美
云风的 BLOG
云风的 BLOG
小众软件
小众软件
博客园 - 叶小钗
Blog — PlanetScale
Blog — PlanetScale
C
Check Point Blog
A
About on SuperTechFans
B
Blog
月光博客
月光博客
宝玉的分享
宝玉的分享
Last Week in AI
Last Week in AI

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);