Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 270 Vote(s) - 3.67 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Chromecast Audio stopped HTML 5 Web Audio API

#1
Ok so i had this class working and playing sound. It suddenly stopped playing sound. If I debug it in the chromecast debugger all the data members get fill when I create an istance of it and call the init() function.

var audioplayer = new cast.AudioPlayer();
audioplayer.init();

Then after I am sure the .wav files are loaded, I call my play method

audioplayer.play(cast.AudioPlayer.welcome);//pass index of buffer

Here is the class

var cast = window.cast || {};

(function() {
'use strict';
AudioPlayer.applause = 0;
AudioPlayer.ding = 1;
AudioPlayer.buzzer = 2;
AudioPlayer.sigh = 3;
AudioPlayer.welcome = 4;

function AudioPlayer() {
try {
// Fix up for prefixing
window.AudioContext = window.AudioContext
|| window.webkitAudioContext;
this.context = new AudioContext();
} catch (e) {
console.log('Web Audio API is not supported in this browser');
}
this.soundBuffer = [];
this.loaded = false;
this.sources = [];
}

AudioPlayer.prototype = {
play : function(index){
this.sources[index].start(0);//play then reload the buffer to reduce latency between user action and sound playing
this.sources[index] = this.context.createBufferSource();
this.sources[index].buffer = this.soundBuffer[index];
this.sources[index].connect(this.context.destination);
},

init : function() {
// Fix up prefixing
window.AudioContext = window.AudioContext
|| window.webkitAudioContext;
this.context = new AudioContext();

var bufferLoader = new BufferLoader(this.context, this, [
'./sounds/applause.wav',
'./sounds/ding.wav',
'./sounds/buzzer.wav',
'./sounds/sigh.wav',
'./sounds/welcome.wav',],
this.finishedLoading);

bufferLoader.load();
},

//buffer up the sounds so they are immediately ready to play
finishedLoading : function(bufferList) {
this.sources[0] = this.context.createBufferSource();
this.sources[1] = this.context.createBufferSource();
this.sources[2] = this.context.createBufferSource();
this.sources[3] = this.context.createBufferSource();
this.sources[4] = this.context.createBufferSource();
this.sources[0].buffer = bufferList[0];
this.sources[1].buffer = bufferList[1];
this.sources[2].buffer = bufferList[2];
this.sources[3].buffer = bufferList[3];
this.sources[4].buffer = bufferList[4];
this.sources[0].connect(this.context.destination);
this.sources[1].connect(this.context.destination);
this.sources[2].connect(this.context.destination);
this.sources[3].connect(this.context.destination);
this.sources[4].connect(this.context.destination);
this.soundBuffer = bufferList;

this.loaded = true;
console.log('Sounds Loaded!');
}
};

// Exposes public functions and APIs
cast.AudioPlayer = AudioPlayer;

})();

And here is the buffer loader, sorry about the two different types of encapsulation.

function BufferLoader(context, cbObj, urlList, callback) {
this.context = context;
this.urlList = urlList;
this.onload = callback;
this.bufferList = new Array();
this.loadCount = 0;
this.callBackObj = cbObj;
}

BufferLoader.prototype.loadBuffer = function(url, index) {
// Load buffer asynchronously
var request = new XMLHttpRequest();
request.open("GET", url, true);
request.responseType = "arraybuffer";

var loader = this;

request.onload = function() {
// Asynchronously decode the audio file data in request.response
loader.context.decodeAudioData(
request.response,
function(buffer) {
if (!buffer) {
console.log('error decoding file data: ' + url);
return;
}
loader.bufferList[index] = buffer;
if (++loader.loadCount == loader.urlList.length)
loader.onload.apply(loader.callBackObj, [loader.bufferList]);
},
function(error) {
console.error('decodeAudioData error', error);
}
);
}

request.onerror = function() {
console.log('BufferLoader: XHR error');
}

request.send();
}

BufferLoader.prototype.load = function() {
for (var i = 0; i < this.urlList.length; ++i)
this.loadBuffer(this.urlList[i], i);
}
I don't get it. I was playing audio fine. No errors are showing up in my debugger, just stopped working. I tested my chromecast with other apps as well. They all pass audio. Does anyone see any issues with this class?

I even step through it with the debugger, inspecting all variables as i go seem to have the data. The start() method just does not do anything.
Reply

#2
OK, this was something a miss with my chromecast device. I was getting audio from netflix so i started netflix and then launched my game to take over the chromecast. The audio just started working. Wasted about 48 hours on something that I cannot reproduce now. Any comments to why this can happen would be greatly appreciated.
Reply

#3
The final solution for my problem was to replace the lines

window.AudioContext = window.AudioContext
|| window.webkitAudioContext;
var context = new AudioContext();

with

var context = new window.AudioContext();

Seems the or (||) was favoring window.webkitAudioContext. This is a deprecated interface and does not work on my chromecast.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through