小编Nea*_*lis的帖子

如何检查HTML5音频是否已达到不同的错误

具体来说,如果206个音频请求中的一个失败并且缓冲停止,是否有办法检测该状态?或者我是否应该通过比较缓冲的金额与过去的金额来检查缓冲是否停止?

另外,我如何检查指定的源是否失败,您是否可以将其指向另一个源?

html javascript audio html5

21
推荐指数
1
解决办法
2万
查看次数

HTML5音频 - 测试无效状态错误(或Dom异常11)

我正在动态创建音频文件并动态更改源.但是,在我更改src并尝试更改currentTime后,我总是会收到无效状态错误.你是如何进行测试的呢?或者更好地在事件准备好时触发事件,然后调用currentTime来改变其音频位置.

this.doneLoading = function(aTime){

    try{
        this.mAudioPlayer.currentTime = aTime / 1000.0;
    }catch(err){
        console.log( err );
    }
    this.mAudioPlayer.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('canplaythrough', this.doneLoading(aTime), 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(); …
Run Code Online (Sandbox Code Playgroud)

javascript audio html5

8
推荐指数
2
解决办法
1万
查看次数

在JavaScript中对PCM音频缓冲区进行下采样

我正在尝试对从audioContext获取的采样率进行下采样.我相信它是在44100,我希望它是11025.我想我可以平均每3个样本,它以正确的速率播放,但是音高太高,好像我们都在氦气.

在11025样本中将float32Array从44100下采样到int16Array的正确方法是什么?

var context = new Flash.audioContext();
var audioInput = context.createMediaStreamSource(stream);
var recorder = context.createScriptProcessor(null, 1, 1);
recorder.onaudioprocess = onAudio;
audioInput.connect(recorder);
recorder.connect(context.destination);

var onAudio = function (e) {
    var left = e.inputBuffer.getChannelData(0);
    bStream.write(Flash.convertFloat32ToInt16(left));
}

var convertFloat32ToInt16 = function(buffer) {
    var l = buffer.length;
    var point = Math.floor(l/3);
    var buf = new Int16Array(point);
    for (var x = l; x > 0;) {
        var average = (buffer[x] + buffer[x-1] +  buffer[x-2]) / 3;
        buf[point] = average*0x7FFF;
        point -= 1;
        x -= 3; …
Run Code Online (Sandbox Code Playgroud)

javascript audio html5 node.js webkitaudiocontext

7
推荐指数
1
解决办法
2474
查看次数

使用ajax设置html5媒体源

我需要为我从外部服务器抓取的音频文件提供身份验证标头.所以现在我试图使用ajax,我可以很好地抓取文件,但我不能将它们设置为我的播放器的媒体源.如何设置ajax加载文件作为音频源?

编辑

结束修复它以防有人以这种方式回来.

if (this.mAudioPlayer.canPlayType("audio/mpeg")) {
    this.mExtension = '.mp3';
}else if (this.mAudioPlayer.canPlayType("audio/ogg")) {
    this.mExtension = '.ogg';
} else if (this.mAudioPlayer.canPlayType("audio/mp4")) {
    this.mExtension = '.m4a'; 
}

this.CreateAudioData = function() {

    //downloading audio for use in data:uri
    $.ajax({
        url: aAudioSource + this.mExtension + '.txt',
        type: 'GET',
        context: this,
        async: false,
        beforeSend: function(xhr) {xhr.setRequestHeader('Authorization', window.userId);},
        success: this.EncodeAudioData,
        error: function(xhr, aStatus, aError) { HandleError('Audio Error: ' + aStatus); }
    });
};

this.EncodeAudioData = function(aData) {
    //this.mAudioData = base64_encode(aData);
    this.mAudioData = aData;

    if (this.mExtension == …
Run Code Online (Sandbox Code Playgroud)

javascript ajax html5

6
推荐指数
1
解决办法
4415
查看次数

标签 统计

html5 ×4

javascript ×4

audio ×3

ajax ×1

html ×1

node.js ×1

webkitaudiocontext ×1