View Sidebar

A Million Little Pieces Of My Mind

Step 3: The OrganicaAudioTrack Constructor

By: Paul S. Cilwa Viewed: 7/22/2024
Posted: 11/17/2017
Page Views: 825
Topics: #Computers #Programming #Projects #WebAudioAPI #JavaScript #MusicPlayer #Cross-fadingMusicPlayer #OrganicaAudio
Representing a single music track for the Web Audio API.

It's now time to open the empty OrganicaAudio.js file and create the constructor for the object that will encapsulate the Web Audio API. We can start by typing in some preliminary lines:

/* OrganicaAudioTrack

function OrganicaAudioTrack(aSource)
	this.Context = MyOrganicaAudio.Context; // For convenience
	this.Filename = aSource;

	this.StartCrossFade = 0;
	this.Loaded = false;
	this.Loading = false;
	this.Playing = false;

Note the use of the this keyword. It represents the object being created; statements such as

this.Loaded = false;

simultaneously create an object property and assign it a value.

The property names I made up—"Filename", "Loading"—are guesses as to what I'll need to implement my player. I may add more properties as I discover I need them, or remove any I find unneccessary.

Obviously this was a small step. The next one will require more of us, however; as it requires us to learn another new JavaScript feature: Promises.