javascript - 在IE9中设置currentTime

标签 javascript html audio

我正在尝试从服务器流式传输音频src时设置currentTime。在其他所有浏览器上都可以正常运行,但是在IE9上,当我设置currentTime并调用play时,它会跳回到开头。

this.playAtTime = function(aTime) {
    Debug("play at time audio: " + aTime);
    Debug("this.mAudioPlayer.currentTime: " + this.mAudioPlayer.currentTime);

     this.startTime = aTime;

    if (this.mAudioPlayer.src != this.mAudioSrc) {
        this.mAudioPlayer = new Audio();
        this.mAudioPlayer.src = this.mAudioSrc;
        this.mAudioPlayer.load();
        this.mAudioPlayer.play();
        this.mAudioPlayer.addEventListener('loadedmetadata', function(){ this.currentTime = aTime / 1000.0; }, false );
    }
    else if ((isChrome() || isMobileSafari()) && aTime == 0) {
        this.mAudioPlayer.load();
        this.mAudioPlayer.currentTime = aTime / 1000.0;
        this.mAudioPlayer.play();
        Debug("Reloading audio");
    }else{

        this.mAudioPlayer.currentTime = aTime / 1000.0;
        this.mAudioPlayer.play();
    }       
};

这不是缓冲的问题,因为无论等待多长时间,它在设置时都不会成功。

最佳答案

尝试交换以下两行的位置:

this.mAudioPlayer.play();
this.mAudioPlayer.currentTime = aTime / 1000.0;

关于javascript - 在IE9中设置currentTime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12940852/

相关文章:

html - CSS 媒体查询层次结构 - 为什么 "Smaller"媒体查询不在浏览器/检查器中呈现?

Android chrome不会在html中播放本地声音文件

Javascript 三元运算

javascript - Angular 模态不随组件变量变化而更新

JavaScript——内联 switch 语句?

php - 编辑和删除按钮在php,ajax中添加到服务器端数据表

javascript - 如何更改 src 属性的一部分未知

更改边框折叠时html,css边框消失

从 DTS 转码到 AAC 时音频丢失

android - 在Android中检测哔声