我可以获取audio.currentTime但无法设置它(在Google Chrome中) [英] I can get audio.currentTime but not set it (in Google Chrome)

查看:372
本文介绍了我可以获取audio.currentTime但无法设置它(在Google Chrome中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这让我发疯.这是我用来设置当前时间的代码:

This is driving me crazy. Here is the code I use to set current time:

$("#audio").click(function(e) {
    e.preventDefault();
    mr_waveform_skip(e)
});

function mr_waveform_skip(event) {
    clientX = event.clientX;
    left = event.currentTarget.offsetLeft;
    clickoffset = clientX - left;
    percent = clickoffset/event.currentTarget.offsetWidth
    audio_duration = audio_element.duration;
    duration_seek = percent*audio_duration;
    audio_element.currentTime = duration_seek;
    // audio_element.currentTime = 10;
    console.log('CLICK: ' + duration_seek + ' Element: ' + audio_element + ' CurrentTime: ' + audio_element.currentTime);
}

我似乎不能设置 audio_element.currentTime获得它!

更糟糕的是,它在fireFox中有效!无论如何,Chrome都会从0重新启动.

And worse, it works in fireFox! Chrome restarts at 0, no matter what.

这是上面的代码在Firefox控制台中生成的:

This is what the above code produces in Firefox console:

CLICK: 63.82905432385121 Element: [object HTMLAudioElement] CurrentTime: 3.849546

在Chrome中:

CLICK: 63.82905432385121 Element: [object HTMLAudioElement] CurrentTime: 3.849546

看到了吗?一样的!我们可以看到Chrome浏览器看到了HTML音频元素(因为它可以获取值).如果执行audio_element.currentTime = 10;仍然不起作用(在Chrome中,则Firefox会在10时重新启动.).

See? The same one! We can see that Chromes sees the HTML audio element (since it can get the value). If I do audio_element.currentTime = 10; it still does not work (in Chrome, Firefox loyally restarts at 10)..

推荐答案

当我使用Wikipedia的Ogg文件对其进行测试时,您的代码可以正常工作.媒体文件中出现某种损坏或意外格式.

Your code works perfectly when I tested it with with an Ogg file from Wikipedia.. If that really is all of your code, then this problem appears to be caused by some kind of corruption or unexpected format in your media file.

您将无法使用代码解决此问题;您将需要产生一个新的媒体文件,您的浏览器可以正确处理该文件.也许尝试使用其他音频软件(或不同设置)来制作或重新处理媒体文件.

You will not be able to fix this problem with code; you will need to produce a new media file that your browser can process correctly. Perhaps try using a different piece of audio software (or different settings) to produce or re-process the media file.

这篇关于我可以获取audio.currentTime但无法设置它(在Google Chrome中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆