By: Paul S. Cilwa | Viewed: 12/7/2023 Posted: 11/17/2017 |
Page Views: 614 | |
Topics: #Computers #Cross-fadingMusicPlayer #JavaScript #MusicPlayer #OrganicaAudio #Programming #Projects #WebAudioAPI | |||
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;
console.log(this.Filename);
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.