-
Notifications
You must be signed in to change notification settings - Fork 1
Playing Audio Files
The function that plays audio files is playPiece(volume, carryperformer, audioURL, currentPieceName, instrument)
This applet does not download any pieces upon loading a page. There is one single audio tag in the skeleton HTML which is left with a blank source. Instead, each time that playPiece is called, the source of this audio tagged is changed. Only then does the audio get downloaded.
This function also doubles as the performer/editor caption control (the name, portrait and blurb on the bottom left). This was done mainly out of convenience.
The if-statement that checks appMODE insures that if the applet is set to the public version with no audio, then the functionality to play audio is no longer present.
This function seems longer than it is simply because there is protection to ensure that A) it doesn't call for editors, B) calling the function on a piece that is playing will the pause the same piece, and C) the performer/editor caption doesnt fade out and back in if selecting another datapoint from the same performer/editor.
Here is the code that is called to play the piece in its entirety (without the overall if statement):
//Play Music button functionality
var playPiece = function (volume, carryperformer, audioURL, currentPieceName,
instrument) {
//Load audio tag into aPiece
aPiece = document.getElementById('audio');
if ($('.stopPlay').hasClass('menuclicked') === false) { // This has to be present because the Play function also holds the Performer Bio/Caption code
aPiece.src = audioURL;
aPiece.load();
if (currentPieceName === currentPiecePlaying) {
if (aPiece.paused === false) {
} else {
}
} else {
$('.caption').fadeOut(250);
$('.' + carryperformer).fadeIn(250);
}
} else {
if (instrument === "harpData" || instrument === "pianoData") {
if (currentPieceName === currentPiecePlaying) {
if (aPiece.paused === false) {
aPiece.pause();
aPiece.currentTime = 0;
$('.pauseDisplay').show();
$('.playDisplay').hide();
} else {
aPiece.volume = volume;
aPiece.play();
$('.pauseDisplay').hide();
$('.playDisplay').show();
}
} else {
currentPiecePlaying = currentPieceName;
aPiece.src = audioURL;
aPiece.load();
aPiece.volume = volume;
aPiece.play();
$('.caption').fadeOut(250);
$('.' + carryperformer).fadeIn(250);
$('.pauseDisplay').hide();
$('.playDisplay').show();
}
} else {
if (currentPieceName === currentPiecePlaying) {
if (aPiece.paused === false) {
} else {
}
} else {
$('.caption').fadeOut(250);
$('.' + carryperformer).fadeIn(250);
}
}
}
};
Written by Kyle Gauder
Development of this tool was funded by an NSERC Undergraduate Student Research Award Grant. Special thanks to Marsha Natadiria for crosschecking data for errors and collecting information on all performers and editors (and running participants)