You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Safari中Blob音频点击暂停后从头播放的问题求助

Safari中Blob音频点击暂停后从头播放的问题求助

各位好!我最近在做一个音频加载播放的功能:通过AJAX从指定URL下载音频文件,转成Blob URL后创建带控制栏的audio标签并自动播放。目前下载和自动播放都正常,但遇到一个诡异的问题——点击暂停按钮时,音频不是停在当前播放位置,而是直接跳回开头重新开始了!

我用的代码如下:

function load_Audio( contentID ) {

  var audioUrl = $( contentID ).text();
        
  $.ajax({
    url: audioUrl,
    method: 'GET',
    xhrFields: {
      responseType: 'blob'
    },
    success: function(data) {

      // Create a blob URL for the audio file
      var blobUrl = URL.createObjectURL(data);

      const audioElement = document.createElement('audio');
      audioElement.setAttribute('controls', true);
      audioElement.setAttribute('controlsList', 'nodownload');
      audioElement.setAttribute('autoplay', 'autoplay');
      document.body.appendChild(audioElement);

      const sourceElement = document.createElement('source');
      audioElement.appendChild(sourceElement);
      sourceElement.src = blobUrl;
      sourceElement.type = 'audio/mpeg';

      $('#audioholder').html(audioElement);
    },
    error: function() {
      $('#audioholder').html('Failed to load the audio file');
    }
  });

}

有没有大佬能帮我分析下问题出在哪?怎么解决这个暂停异常的问题呀?

备注:内容来源于stack exchange,提问作者Ali

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 15:52:56