<commit_before>E2.plugins["audio_player"] = function(core, node) {
	var self = this;
	
	this.desc = 'Play an audio stream. Playback loops.';
	this.input_slots = [ 
		{ name: 'audio', dt: core.datatypes.AUDIO, desc: 'The audio stream to play.' },
		{ name: 'play', dt: core.datatypes.BOOL, desc: 'Send true to start playback and false to stop.' }
	];
	
	this.output_slots = [];
	
	this.audio = null;
	this.playing = false;
	this.should_play = false;
		
	this.reset = function()
	{
		if(self.audio && self.playing)
		{
			self.playing = self.should_play = false;
			self.audio.pause();
			self.currentTime = 0;
		}
	};
	
	this.update_input = function(slot, data)
	{
		if(slot.index === 0)
			self.audio = data;
		else
			self.should_play = data;
	};

	this.update_state = function(delta_t)
	{
		if(self.playing !== self.should_play)
		{
			if(self.audio)
			{
				if(self.should_play)
					self.audio.play();
				else
					self.audio.pause();			
			}
			
			self.playing = self.should_play;
		}
	};
};<commit_msg>Refactored the audio loader plugin to use prototype. Added note about fixing silent load errors later.<commit_after>E2.p = E2.plugins["audio_player"] = function(core, node)
{
	this.desc = 'Play an audio stream. Playback loops.';
	
	this.input_slots = [ 
		{ name: 'audio', dt: core.datatypes.AUDIO, desc: 'The audio stream to play.' },
		{ name: 'play', dt: core.datatypes.BOOL, desc: 'Send true to start playback and false to stop.' }
	];
	
	this.output_slots = [];
	
	this.audio = null;
	this.playing = false;
	this.should_play = false;
};

E2.p.prototype.reset = function()
{
	if(this.audio && this.playing)
	{
		this.playing = this.should_play = false;
		this.audio.pause();
		this.audio.currentTime = 0;
	}
};

E2.p.prototype.update_input = function(slot, data)
{
	if(slot.index === 0)
		this.audio = data;
	else
		this.should_play = data;
};

E2.p.prototype.update_state = function(delta_t)
{
	if(this.playing !== this.should_play)
	{
		if(this.audio)
		{
			if(this.should_play)
				this.audio.play();
			else
				this.audio.pause();			
		}
		
		this.playing = this.should_play;
	}
};
{'fraction_non_alphanumeric': 0.15461465271170313, 'fraction_numerical': 0.004757373929590866, 'mean_word_length': 3.197604790419162, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4714640', 'n_tokens_mistral': 882, 'n_tokens_neox': 776, 'n_words': 165}