首页 > 其他分享 >How to get the exact duration of an audio file in js All In One

How to get the exact duration of an audio file in js All In One

时间:2024-09-22 18:03:15浏览次数:1  
标签:privacy resistFingerprinting currentTime get js How time duration audio

How to get the exact duration of an audio file in js All In One

errors

audio duration time precise bug

image

time 误差 bug ❌

Reduced time precision / 时间精度降低

To offer protection against timing attacks and fingerprinting, the precision of video.currentTime might get rounded depending on browser settings. In Firefox, the privacy.reduceTimerPrecision preference is enabled by default and defaults to 2ms. You can also enable privacy.resistFingerprinting, in which case the precision will be 100ms or the value of privacy.resistFingerprinting.reduceTimerPrecision.microseconds, whichever is larger.

For example, with reduced time precision, the result of video.currentTime will always be a multiple of 0.002, or a multiple of 0.1 (or privacy.resistFingerprinting.reduceTimerPrecision.microseconds) with privacy.resistFingerprinting enabled.

为了防止计时攻击指纹识别,video.currentTime 的精度可能会根据浏览器设置进行舍入。在 Firefox 中,privacy.reduceTimerPrecision 首选项默认启用,默认为 2 毫秒。您还可以启用 privacy.resistFingerprinting,在这种情况下精度将为 100 毫秒或 privacy.resistFingerprinting.reduceTimerPrecision.microseconds 的值,以较大者为准。例如,在降低时间精度的情况下,video.currentTime 的结果将始终是 0.002 的倍数,或者在启用 privacy.resistFingerprinting 的情况下是 0.1 的倍数(或 privacy.resistFingerprinting.reduceTimerPrecision.microseconds)。

The HTMLMediaElement interface's currentTime property specifies the current playback time in seconds. Changing the value of currentTime seeks the media to the new time.

HTMLMediaElement 接口的 currentTime 属性指定当前播放时间(以为单位)。 更改 currentTime 的值会寻找新时间的媒体。

A double-precision floating-point value indicating the current playback time in seconds.

指示当前播放时间(以秒为单位)的双精度浮点值。

https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/currentTime

The read-only HTMLMediaElement property duration indicates the length of the element's media in seconds.

只读 HTMLMediaElement 属性持续时间指示元素媒体的长度(以为单位)。

https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/duration

solutions

???

demos

    <!-- <audio
      id="audio"
      controls
      loop
      autoplay
      muted
      src="./000-xyz/《雅思考试官方指南》(第2版)_听力练习音频_06 Test Practice - Section 1.mp3">
    </audio> -->
  <figure>
    <figcaption>《雅思考试官方指南》(第2版)/听力练习音频/06 Test Practice - Section 1.mp3</figcaption>
    <audio
      id="audio"
      controls
      loop
      src="./000-xyz/《雅思考试官方指南》(第2版)_听力练习音频_06 Test Practice - Section 1.mp3">
    </audio>
  </figure>
  <!-- progress 进度条 -->
  <div>
    <span id="current-time">current</span>
    <span id="time-line">/</span>
    <span id="total-time">total</span>
  </div>
// time
const current = document.getElementById("current-time");
const total = document.getElementById("total-time");


// time
const autoUpdateTime = () => {
  // current.innerText = audio.currentTime;
  // total.innerText = audio.duration;
  current.innerText = (audio.currentTime / 60).toFixed(2);
  total.innerText = (audio.duration / 60).toFixed(2);
}

// let sid = setInterval(() => {
//   autoUpdateTime();
// }, 100);

audio.addEventListener("timeupdate", (event) => {
  console.log("The currentTime attribute has been updated. Again.");
  autoUpdateTime();
});

(

标签:privacy,resistFingerprinting,currentTime,get,js,How,time,duration,audio
From: https://www.cnblogs.com/xgqfrms/p/18425599

相关文章

  • WPF System.Windows.MessageBox.Show Dispatcher processing has been suspended, bu
    privatevoidSelectedCommandExecuted(objectobj){if(obj!=null&&objisDataGriddg){if(dg!=null){varselectedBks=dg.SelectedItems;if(selectedBks!=null&&selectedBk......
  • js逆向实战之烯牛数据请求参数加密和返回数据解密
    声明:本篇文章仅用于知识分享实战网址:https://www.xiniudata.com/industry/newest?from=data请求参数加密访问网址,往下翻翻,可以看到触发了如下的数据包,请求参数进行了加密。全局搜索list_industries_by_sort地址,有四处,都位于同一个文件中。随便点一个看看,可以看到有payload......
  • 初学者学node.js
    对于初学者来说,学习Node.js是一个很好的选择,因为它可以帮助你理解后端开发,并且由于其基于JavaScript,如果你已经有了一些前端开发的基础,那么学习曲线会相对平缓一些。以下是一些建议帮助你开始学习Node.js:1.**了解基础**:  -确保你已经熟悉了JavaScript的基本语法和概念。......
  • Go语言基础-常见编码(Json、Base64)
    编码jsonjson是go标准库里自带的序列化工具,使用了反射,效率比较低easyjson值针对预先定义好的json结构体对输入的json字符串进行纯字符串的截取,并将对应的json字段赋值给结构体easyjson-allxxx.go生成go文件中定义的结构体对应的解析xxx.go所在的package不能是mainfunce......
  • QT Widgets模块源码解析与实践
    QTWidgets模块源码解析与实践使用AI技术辅助生成QT界面美化视频课程QT性能优化视频课程QT原理与源码分析视频课程QTQMLC++扩展开发视频课程免费QT视频课程您可以看免费1000+个QT技术视频免费QT视频课程QT统计图和QT数据可视化视频免费看免费QT视频课程QT性能优化视......
  • QT Widgets模块源码解析与技巧
    QTWidgets模块源码解析与技巧使用AI技术辅助生成QT界面美化视频课程QT性能优化视频课程QT原理与源码分析视频课程QTQMLC++扩展开发视频课程免费QT视频课程您可以看免费1000+个QT技术视频免费QT视频课程QT统计图和QT数据可视化视频免费看免费QT视频课程QT性能优化视......
  • (免费送源码)Node.js网上购物商城 计算机毕业设计原创定制
    摘 要随着社会的发展,计算机的优势和普及使得网上购物商城的开发成为必需。网上购物商城主要是借助计算机,通过对首页、站点管理(轮播图、公告栏)用户管理(管理员、注册用户)内容管理(商城资讯、资讯分类)商城管理(商城中心、分类列表、订单列表)等信息进行管理。减少管理员的工作,......
  • 如何在Nextjs中添加RBAC授权
    基于角色的访问控制(rbac)是现代web应用程序中的一项重要功能,使管理员能够根据用户在系统中的角色来管理用户权限。在next.js应用程序中实现rbac涉及几个关键步骤:定义角色和权限、将其与身份验证集成以及在应用程序中实施访问控制。本指南将引导您完成向next.js应用程序......
  • 如何在Reactjs中制作动态进度条
    使用react和循环进度组件构建性能仪表板在本博客中,我们将探讨如何使用react构建性能指标仪表板。仪表板显示不同绩效指标(例如可访问性、seo和最佳实践)的循环进度指示器。进度指示器逐渐填满,模拟加载动画。该项目使用tailwindcss进行样式设计,并组合了多个组件来创建灵活且......
  • 如何解决 Nextjs 中的水合错误
    “水合失败,因为服务器渲染的html与客户端不匹配......”如果您一直使用next.js来构建应用程序,您一定遇到过上述错误或类似的错误。这称为水合错误。当我第一次开始使用next.js时,我曾经遇到过这个错误,但我不知道该怎么做,也从不去查找它,因为它当时并没有真正影响我的代码......