public/js/music_playlist.js
/**
 * Handles the video loading, playing and pausing.
 * 
 * @param {number} songIndex The index of the selected song in the songs json object.
 */
Handles the video loading, playing and pausing.

@param {number} songIndex The index of the selected song in the songs json object.
Handles the video loading playing and pausing . @param { number } songIndex The index of the selected song in the songs json object .
function loadVideo(songIndex) {
    if (previousSongIndex != songIndex || previousSongIndex == null) {
        var YouTubeCode = songs[songIndex]['youtube_code'];
        YouTubePlayer.loadVideoById(YouTubeCode); 
        YouTubePlayer.setPlaybackQuality("small"); 
        currentYouTubeCode = YouTubeCode;  
        isVideoPlaying = false; 
        window.clearInterval(timerInterval);
        timerInterval = setInterval(function () {
            updateTimerDisplay(songIndex);
        }, 1000);
        if (previousSongIndex != null) {
            document.getElementById('songTime' + previousSongIndex.toString()).innerHTML = '<p>00:00 / 00:00</p>';             
            document.getElementById('songTile' + previousSongIndex.toString()).style = "background-color:initial ";            
            document.getElementById('playbackButton'+ previousSongIndex.toString()).innerHTML = '<i class="fa fa-play"></i>';  
        }
        document.getElementById('songTile' + songIndex.toString()).style = "background-color:LightGrey";
        previousSongIndex = songIndex;
    }
    if (isVideoPlaying == false) {
        playVideo();
        document.getElementById('playbackButton'+ songIndex.toString()).innerHTML = '<i class="fa fa-pause"></i>';
        isVideoPlaying = true;
    }
    else {
        pauseVideo();
        document.getElementById('playbackButton'+ songIndex.toString()).innerHTML = '<i class="fa fa-play"></i>';
        isVideoPlaying = false;
    }
}
function loadVideo ( songIndex ) { if ( previousSongIndex != songIndex || previousSongIndex == null ) { var YouTubeCode = songs [ songIndex ] [ 'youtube_code' ] ; YouTubePlayer . loadVideoById ( YouTubeCode ) ; YouTubePlayer . setPlaybackQuality ( "small" ) ; currentYouTubeCode = YouTubeCode ; isVideoPlaying = false ; window . clearInterval ( timerInterval ) ; timerInterval = setInterval ( function ( ) { updateTimerDisplay ( songIndex ) ; } , 1000 ) ; if ( previousSongIndex != null ) { document . getElementById ( 'songTime' + previousSongIndex . toString ( ) ) . innerHTML = '<p>00:00 / 00:00</p>' ; document . getElementById ( 'songTile' + previousSongIndex . toString ( ) ) . style = "background-color:initial " ; document . getElementById ( 'playbackButton' + previousSongIndex . toString ( ) ) . innerHTML = '<i class="fa fa-play"></i>' ; } document . getElementById ( 'songTile' + songIndex . toString ( ) ) . style = "background-color:LightGrey" ; previousSongIndex = songIndex ; } if ( isVideoPlaying == false ) { playVideo ( ) ; document . getElementById ( 'playbackButton' + songIndex . toString ( ) ) . innerHTML = '<i class="fa fa-pause"></i>' ; isVideoPlaying = true ; } else { pauseVideo ( ) ; document . getElementById ( 'playbackButton' + songIndex . toString ( ) ) . innerHTML = '<i class="fa fa-play"></i>' ; isVideoPlaying = false ; } }
Handles the video loading, playing and pausing.
Handles the video loading playing and pausing .
// Load the new YouTube code. // Reset previous selected song. // Reset previous selected song. // Set new selected song.