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

推荐订阅源

钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
云风的 BLOG
云风的 BLOG
IT之家
IT之家
C
Check Point Blog
T
The Blog of Author Tim Ferriss
S
SegmentFault 最新的问题
人人都是产品经理
人人都是产品经理
H
Hackread – Cybersecurity News, Data Breaches, AI and More
美团技术团队
M
MIT News - Artificial intelligence
Jina AI
Jina AI
Blog — PlanetScale
Blog — PlanetScale
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Microsoft Security Blog
Microsoft Security Blog
G
Google Developers Blog
F
Fortinet All Blogs
V
Visual Studio Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
T
Tailwind CSS Blog
Hugging Face - Blog
Hugging Face - Blog
MyScale Blog
MyScale Blog
爱范儿
爱范儿
The Cloudflare Blog
博客园 - 三生石上(FineUI控件)

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