/**
* TinyMusicPlayer
*
* Implements/holds functionality to create one (or more) web-based audio
* player(s) via JavaScript and HTML5 audio object.
*
* Author ...... : CI:A - Certus In Audio
* Contact ..... : http://certus.in/
* Copyright ... : CI:A - Certus In Audio
* Version ..... : 1.0.0
* Website ..... : http://certus.in/
*
* Overview:
*
* - public members ->
*
* {boolean} initialize : {void}
* {boolean} run : {void}
* {boolean} terminate : {void}
* {boolean} isAutoPlayTrusted : {void}
* {boolean} getAutoPlay : {void}
* {boolean} setAutoPlay : {boolean}
* {boolean} play : {void}
* {boolean} pause : {void}
* {boolean} stop : {void}
* {boolean} first : {void}
* {boolean} last : {void}
* {boolean} next : {void}
* {boolean} previous : {void}
* {number} getCurrentSongIndex : {void}
* {number} setCurrentSongIndex : {number}
* {number} getSongTimeFloat : {void}
* {number} getSongTimeInteger : {void}
* {string} getSongTimeString : {void}
* {number} getSongLengthFloat : {void}
* {number} getSongLengthInteger : {void}
* {string} getSongLengthString : {void}
* {string} formatPlayTime : {number}
* {boolean} seek : {number}
* {boolean} forward : {number}
* {boolean} back : {number}
* {number} getVolume : {void}
* {boolean} volume : {number}
* {boolean} volumeUp : {number}
* {boolean} volumeDown : {number}
* {boolean} isMuted : {void}
* {boolean} mute : {void}
* {number} getSpeed : {void}
* {boolean} speed : {number}
* {boolean} speedUp : {number}
* {boolean} speedDown : {number}
* {array} getSongInfo : {number}
* {array} getPlayListRawData : {void}
* {boolean} buildPlayListContainer : {void}
* {boolean} refreshPlayListContainer : {void}
* {string} getHashValue : {string}
* {string} getURLParameter : {string}
* {object} getAudioObject : {void}
* {string} getClassSeed : {void}
* {boolean} handleEvent : {object}
* {boolean} handleRun : {void}
*
* - private members ->
*
* {array} _arrConfiguration
* {array} _getSongInfo : {number} {array} {string}
* {array} _getPlayList : {string} {string} {string}
* {object} _createAudioObject : {void}
* {string} _createClassSeed : {void}
*/
/**
* @license
* Copyright CI:A - Certus In Audio
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
/**
* Implements/holds functionality to create one (or more) web-based audio
* player(s) via JavaScript and HTML5 audio object.
*
* @access public
* @author CI:A - Certus In Audio
* @class
* @copyright CI:A - Certus In Audio
* @kind class
* @name TinyMusicPlayer
* @see TinyMusicPlayer::initialize
* @see TinyMusicPlayer::run
* @see TinyMusicPlayer::terminate
* @since 1.0.0
* @version 1.0.0
*/
function TinyMusicPlayer()
{
/**
* Initializes this class.
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name initialize
* @param {void} -
* @returns {boolean} - Always 'true'
* @see TinyMusicPlayer::_arrConfiguration
* @since 1.0.0
* @version 1.0.0
*/
this.initialize = function()
{
if( typeof this._arrConfiguration !== 'object' )
{
this._arrConfiguration = new Array();
}
this._arrConfiguration[ 'album_class_name' ] =
'tmp_album';
this._arrConfiguration[ 'song_class_name' ] =
'tmp_song';
this._arrConfiguration[ 'control_class_name' ] =
'tmp_control';
this._arrConfiguration[ 'control_play_identifier' ] =
'tmp_play';
this._arrConfiguration[ 'control_pause_identifier' ] =
'tmp_pause';
this._arrConfiguration[ 'control_stop_identifier' ] =
'tmp_stop';
this._arrConfiguration[ 'control_next_identifier' ] =
'tmp_next';
this._arrConfiguration[ 'control_previous_identifier' ] =
'tmp_previous';
this._arrConfiguration[ 'control_forward_identifier' ] =
'tmp_forward';
this._arrConfiguration[ 'control_back_identifier' ] =
'tmp_back';
this._arrConfiguration[ 'control_goto_identifier' ] =
'tmp_goto';
this._arrConfiguration[ 'control_first_identifier' ] =
'tmp_first';
this._arrConfiguration[ 'control_last_identifier' ] =
'tmp_last';
this._arrConfiguration[ 'control_volumeup_identifier' ] =
'tmp_volumeup';
this._arrConfiguration[ 'control_volumedown_identifier' ] =
'tmp_volumedown';
this._arrConfiguration[ 'control_mute_identifier' ] =
'tmp_mute';
this._arrConfiguration[ 'control_speedup_identifier' ] =
'tmp_speedup';
this._arrConfiguration[ 'control_speeddown_identifier' ] =
'tmp_speeddown';
this._arrConfiguration[ 'cover_image_identifier' ] =
'tmp_cover';
this._arrConfiguration[ 'playlist_container_identifier' ] =
'tmp_playlist';
this._arrConfiguration[ 'playlist_container_header' ] =
'';
this._arrConfiguration[ 'playlist_container_entry' ] =
'%album_name% - %track%: %name%
';
this._arrConfiguration[ 'playlist_container_entry_current' ] =
'%album_name% - %track%: %name%
';
this._arrConfiguration[ 'playlist_container_footer' ] =
'';
this._arrConfiguration[ 'playlist_container_item_handler' ] =
'tmp_handleItem';
this._arrConfiguration[ 'callback_song' ] =
'tmp_handleSong';
this._arrConfiguration[ 'callback_run' ] =
'tmp_handleRun';
this._arrConfiguration[ 'default_forward_seconds' ] =
5;
this._arrConfiguration[ 'default_back_seconds' ] =
5;
this._arrConfiguration[ 'default_volume_up_units' ] =
10;
this._arrConfiguration[ 'default_volume_down_units' ] =
10;
this._arrConfiguration[ 'default_speed_up_units' ] =
10;
this._arrConfiguration[ 'default_speed_down_units' ] =
10;
this._arrConfiguration[ 'speed_minimum_percent' ] =
50;
this._arrConfiguration[ 'speed_maximum_percent' ] =
200;
this._arrConfiguration[ 'data_delimiter' ] =
'^';
this._arrConfiguration[ 'current_song_index' ] =
1;
this._arrConfiguration[ 'handle_run_interval' ] =
250;
this._arrConfiguration[ 'hash_parameter_track_name' ] =
'track';
this._arrConfiguration[ 'hash_parameter_command_name' ] =
'cmd';
this._arrConfiguration[ 'auto_play' ] =
true;
return true;
};
/**
* Builds the playlist, sets the first song, adds event handlers to
* controls and starts the runner-function.
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name run
* @param {void} -
* @returns {boolean} - Always 'true'
* @see TinyMusicPlayer::_arrConfiguration
* @see TinyMusicPlayer::_getPlayList
* @see TinyMusicPlayer::setCurrentSongIndex
* @see TinyMusicPlayer::buildPlayListContainer
* @see TinyMusicPlayer::play
* @see TinyMusicPlayer::handleRun
* @since 1.0.0
* @version 1.0.0
*/
this.run = function()
{
this._arrConfiguration[ 'current_playlist' ] =
this._getPlayList(
this._arrConfiguration[ 'album_class_name' ] ,
this._arrConfiguration[ 'song_class_name' ] ,
this._arrConfiguration[ 'data_delimiter' ] );
this.setCurrentSongIndex( 1 );
var objCO = document.getElementsByClassName(
this._arrConfiguration[ 'control_class_name' ] );
var intCO = objCO.length;
var intCCC = 0;
for( intCCC = 0 ; intCCC < intCO ; intCCC++ )
{
objCO[ intCCC ].addEventListener( 'click' , this , false );
}
this.buildPlayListContainer();
this.play();
this.handleRun();
return true;
};
/**
* Cleans up this class.
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name terminate
* @param {void} -
* @returns {boolean} - Always 'true'
* @see TinyMusicPlayer::_arrConfiguration
* @since 1.0.0
* @version 1.0.0
*/
this.terminate = function()
{
this._arrConfiguration = null;
return true;
};
/**
* Returns informations about trusted auto-play
* (auto-play supported/allowed by browser).
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name isAutoPlayTrusted
* @param {void} -
* @returns {boolean} - Returns 'true' if auto-play is available
* @see TinyMusicPlayer::_arrConfiguration
* @since 1.0.0
* @version 1.0.0
*/
this.isAutoPlayTrusted = function()
{
if( typeof this._arrConfiguration[ 'auto_play_trust' ] !== 'boolean' )
{
return true;
}
return this._arrConfiguration[ 'auto_play_trust' ];
};
/**
* Returns current auto-play setting.
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name getAutoPlay
* @param {void} -
* @returns {boolean} - Returns 'true' if auto-play is enabled
* @see TinyMusicPlayer::_arrConfiguration
* @since 1.0.0
* @version 1.0.0
*/
this.getAutoPlay = function()
{
return this._arrConfiguration[ 'auto_play' ];
};
/**
* Sets current auto-play setting.
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name setAutoPlay
* @param {boolean} [bAutoPlay] - Current auto-play setting
* @returns {boolean} - Returns 'true' if auto-play is enabled
* @see TinyMusicPlayer::_arrConfiguration
* @since 1.0.0
* @version 1.0.0
*/
this.setAutoPlay = function( bAutoPlay )
{
bAutoPlay = ( typeof bAutoPlay !== 'boolean' )
? this._arrConfiguration[ 'auto_play' ] : bAutoPlay;
this._arrConfiguration[ 'auto_play' ] = bAutoPlay;
return this._arrConfiguration[ 'auto_play' ];
};
/**
* Plays current song.
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name play
* @param {void} -
* @returns {boolean} - Returns 'true' on success
* @see TinyMusicPlayer::_arrConfiguration
* @see TinyMusicPlayer::getAudioObject
* @since 1.0.0
* @version 1.0.0
*/
this.play = function()
{
var objAO = this.getAudioObject();
if( typeof objAO !== 'object' )
{
return false;
}
if( this._arrConfiguration[ 'auto_play' ] )
{
var mxP = objAO.play();
if( typeof mxP !== 'undefined' )
{
var bIsSafari = /^((?!chrome|android).)*safari/i.test(
navigator.userAgent );
if( bIsSafari )
{
this._arrConfiguration[ 'auto_play_trust' ] = false;
}
}
}
return true;
};
/**
* Pauses playing current song.
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name pause
* @param {void} -
* @returns {boolean} - Returns 'true' on success
* @see TinyMusicPlayer::getAudioObject
* @since 1.0.0
* @version 1.0.0
*/
this.pause = function()
{
var objAO = this.getAudioObject();
if( typeof objAO !== 'object' )
{
return false;
}
objAO.pause();
return true;
};
/**
* Stops playing current song.
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name stop
* @param {void} -
* @returns {boolean} - Returns 'true' on success
* @see TinyMusicPlayer::getAudioObject
* @since 1.0.0
* @version 1.0.0
*/
this.stop = function()
{
var objAO = this.getAudioObject();
if( typeof objAO !== 'object' )
{
return false;
}
objAO.pause();
objAO.currentTime = 0;
return true;
};
/**
* Sets current song (first in playlist).
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name first
* @param {void} -
* @returns {boolean} - Returns 'true' on success
* @see TinyMusicPlayer::getAudioObject
* @see TinyMusicPlayer::stop
* @see TinyMusicPlayer::setCurrentSongIndex
* @see TinyMusicPlayer::play
* @since 1.0.0
* @version 1.0.0
*/
this.first = function()
{
var bIsPlaying = false;
var objAO = this.getAudioObject();
if( typeof objAO !== 'object' )
{
return false;
}
if( ! objAO.paused )
{
bIsPlaying = true;
}
this.stop();
this.setCurrentSongIndex( 1 );
if( bIsPlaying )
{
this.play();
}
return true;
};
/**
* Sets current song (last in playlist).
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name last
* @param {void} -
* @returns {boolean} - Returns 'true' on success
* @see TinyMusicPlayer::_arrConfiguration
* @see TinyMusicPlayer::getAudioObject
* @see TinyMusicPlayer::stop
* @see TinyMusicPlayer::setCurrentSongIndex
* @see TinyMusicPlayer::play
* @since 1.0.0
* @version 1.0.0
*/
this.last = function()
{
var bIsPlaying = false;
var objAO = this.getAudioObject();
if( typeof objAO !== 'object' )
{
return false;
}
if( ! objAO.paused )
{
bIsPlaying = true;
}
this.stop();
this.setCurrentSongIndex(
this._arrConfiguration[ 'current_playlist' ].length );
if( bIsPlaying )
{
this.play();
}
return true;
};
/**
* Sets current song (next in playlist).
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name next
* @param {void} -
* @returns {boolean} - Returns 'true' on success
* @see TinyMusicPlayer::getAudioObject
* @see TinyMusicPlayer::stop
* @see TinyMusicPlayer::getCurrentSongIndex
* @see TinyMusicPlayer::setCurrentSongIndex
* @see TinyMusicPlayer::play
* @since 1.0.0
* @version 1.0.0
*/
this.next = function()
{
var bIsPlaying = false;
var objAO = this.getAudioObject();
if( typeof objAO !== 'object' )
{
return false;
}
if( ! objAO.paused )
{
bIsPlaying = true;
}
this.stop();
var intCSI = this.getCurrentSongIndex();
intCSI++;
this.setCurrentSongIndex( intCSI );
if( bIsPlaying )
{
this.play();
}
return true;
};
/**
* Sets current song (previous in playlist).
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name previous
* @param {void} -
* @returns {boolean} - Returns 'true' on success
* @see TinyMusicPlayer::getAudioObject
* @see TinyMusicPlayer::stop
* @see TinyMusicPlayer::getCurrentSongIndex
* @see TinyMusicPlayer::setCurrentSongIndex
* @see TinyMusicPlayer::play
* @since 1.0.0
* @version 1.0.0
*/
this.previous = function()
{
var bIsPlaying = false;
var objAO = this.getAudioObject();
if( typeof objAO !== 'object' )
{
return false;
}
if( ! objAO.paused )
{
bIsPlaying = true;
}
this.stop();
var intCSI = this.getCurrentSongIndex();
intCSI--;
this.setCurrentSongIndex( intCSI );
if( bIsPlaying )
{
this.play();
}
return true;
};
/**
* Returns current song index.
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name getCurrentSongIndex
* @param {void} -
* @returns {number} - Current song index
* @see TinyMusicPlayer::_arrConfiguration
* @since 1.0.0
* @version 1.0.0
*/
this.getCurrentSongIndex = function()
{
return this._arrConfiguration[ 'current_song_index' ];
};
/**
* Sets current song index.
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name setCurrentSongIndex
* @param {number} [intIndex] - Current song index
* @returns {number} - Current song index
* @see TinyMusicPlayer::_arrConfiguration
* @see TinyMusicPlayer::getAudioObject
* @see TinyMusicPlayer::getSongInfo
* @since 1.0.0
* @version 1.0.0
*/
this.setCurrentSongIndex = function( intIndex )
{
intIndex = ( typeof intIndex !== 'number' ) ? 1 : intIndex;
if( intIndex < 1 )
{
intIndex = this._arrConfiguration[ 'current_playlist' ].length;
}
if( intIndex > this._arrConfiguration[ 'current_playlist' ].length )
{
intIndex = 1;
}
this._arrConfiguration[ 'current_song_index' ] = intIndex;
var objAO = this.getAudioObject();
var arrSI = this.getSongInfo();
objAO.src = arrSI[ 'url' ];
var objCI = document.getElementById(
this._arrConfiguration[ 'cover_image_identifier' ] );
if( ( objCI !== null ) && ( typeof objCI === 'object' ) )
{
objCI.src = arrSI[ 'cover' ];
}
if( ( window[ this._arrConfiguration[ 'callback_song' ] ] !== null ) &&
( typeof window[ this._arrConfiguration[ 'callback_song' ] ] ===
'function' ) )
{
window[ this._arrConfiguration[ 'callback_song' ] ]();
}
return this._arrConfiguration[ 'current_song_index' ];
};
/**
* Returns played time of current song (float).
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name getSongTimeFloat
* @param {void} -
* @returns {number} - Played time of current song (float)
* @see TinyMusicPlayer::getAudioObject
* @since 1.0.0
* @version 1.0.0
*/
this.getSongTimeFloat = function()
{
var objAO = this.getAudioObject();
return objAO.currentTime;
};
/**
* Returns played time of current song (integer).
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name getSongTimeInteger
* @param {void} -
* @returns {number} - Played time of current song (integer)
* @see TinyMusicPlayer::getSongTimeFloat
* @since 1.0.0
* @version 1.0.0
*/
this.getSongTimeInteger = function()
{
return parseInt( this.getSongTimeFloat() );
};
/**
* Returns played time of current song (string).
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name getSongTimeString
* @param {void} -
* @returns {string} - Played time of current song (string)
* @see TinyMusicPlayer::formatPlayTime
* @see TinyMusicPlayer::getSongTimeInteger
* @since 1.0.0
* @version 1.0.0
*/
this.getSongTimeString = function()
{
return this.formatPlayTime( this.getSongTimeInteger() );
};
/**
* Returns length of current song (float).
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name getSongLengthFloat
* @param {void} -
* @returns {number} - Length of current song (float)
* @see TinyMusicPlayer::getAudioObject
* @since 1.0.0
* @version 1.0.0
*/
this.getSongLengthFloat = function()
{
var objAO = this.getAudioObject();
return objAO.duration;
};
/**
* Returns length of current song (integer).
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name getSongLengthInteger
* @param {void} -
* @returns {number} - Length of current song (integer)
* @see TinyMusicPlayer::getSongLengthFloat
* @since 1.0.0
* @version 1.0.0
*/
this.getSongLengthInteger = function()
{
return parseInt( this.getSongLengthFloat() );
};
/**
* Returns length of current song (string).
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name getSongLengthString
* @param {void} -
* @returns {string} - Length of current song (string)
* @see TinyMusicPlayer::formatPlayTime
* @see TinyMusicPlayer::getSongLengthInteger
* @since 1.0.0
* @version 1.0.0
*/
this.getSongLengthString = function()
{
return this.formatPlayTime( this.getSongLengthInteger() );
};
/**
* Returns a formatted (play-)time string.
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name formatPlayTime
* @param {number} [intSeconds] - Time in seconds
* @returns {string} - The formatted (play-)time string
* @since 1.0.0
* @version 1.0.0
*/
this.formatPlayTime = function( intSeconds )
{
intSeconds = ( typeof intSeconds !== 'number' ) ? 0 : intSeconds;
var intMinutes = Math.floor( intSeconds / 60 );
intMinutes = ( intMinutes >= 10 ) ? intMinutes : '0' + intMinutes;
intSeconds = Math.floor( intSeconds % 60 );
intSeconds = ( intSeconds >= 10 ) ? intSeconds : '0' + intSeconds;
intMinutes = ( isNaN( intMinutes ) ) ? '00' : intMinutes;
intSeconds = ( isNaN( intSeconds ) ) ? '00' : intSeconds;
return intMinutes + ':' + intSeconds;
};
/**
* Sets current play position (seconds).
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name seek
* @param {number} [intSeconds] - Time in seconds
* @returns {boolean} - Returns 'true' on success
* @see TinyMusicPlayer::getAudioObject
* @see TinyMusicPlayer::previous
* @see TinyMusicPlayer::next
* @since 1.0.0
* @version 1.0.0
*/
this.seek = function( intSeconds )
{
intSeconds = ( ( typeof intSeconds !== 'number' ) &&
( typeof intSeconds !== 'string' ) )
? 0
: intSeconds;
if( typeof intSeconds === 'string' )
{
intSeconds = parseInt( intSeconds );
}
var objAO = this.getAudioObject();
if( typeof objAO !== 'object' )
{
return false;
}
if( intSeconds < 0 )
{
return this.previous();
}
if( intSeconds > objAO.duration )
{
return this.next();
}
objAO.currentTime = intSeconds;
return true;
};
/**
* Moves forward (current play position / seconds).
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name forward
* @param {number} [intSeconds] - Time in seconds
* @returns {boolean} - Returns 'true' on success
* @see TinyMusicPlayer::_arrConfiguration
* @see TinyMusicPlayer::getAudioObject
* @see TinyMusicPlayer::next
* @since 1.0.0
* @version 1.0.0
*/
this.forward = function( intSeconds )
{
intSeconds = ( ( typeof intSeconds !== 'number' ) &&
( typeof intSeconds !== 'string' ) )
? this._arrConfiguration[ 'default_forward_seconds' ]
: intSeconds;
if( typeof intSeconds === 'string' )
{
intSeconds = parseInt( intSeconds );
}
var objAO = this.getAudioObject();
if( typeof objAO !== 'object' )
{
return false;
}
var intXI = objAO.currentTime + intSeconds;
if( intXI > objAO.duration )
{
return this.next();
}
objAO.currentTime = intXI;
return true;
};
/**
* Moves back (current play position / seconds).
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name back
* @param {number} [intSeconds] - Time in seconds
* @returns {boolean} - Returns 'true' on success
* @see TinyMusicPlayer::_arrConfiguration
* @see TinyMusicPlayer::getAudioObject
* @see TinyMusicPlayer::previous
* @since 1.0.0
* @version 1.0.0
*/
this.back = function( intSeconds )
{
intSeconds = ( ( typeof intSeconds !== 'number' ) &&
( typeof intSeconds !== 'string' ) )
? this._arrConfiguration[ 'default_back_seconds' ]
: intSeconds;
if( typeof intSeconds === 'string' )
{
intSeconds = parseInt( intSeconds );
}
var objAO = this.getAudioObject();
if( typeof objAO !== 'object' )
{
return false;
}
var intXI = objAO.currentTime - intSeconds;
if( intXI < 0 )
{
return this.previous();
}
objAO.currentTime = intXI;
return true;
};
/**
* Returns current volume (in percent).
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name getVolume
* @param {void} -
* @returns {number} - Current volume (in percent)
* @see TinyMusicPlayer::getAudioObject
* @since 1.0.0
* @version 1.0.0
*/
this.getVolume = function()
{
var objAO = this.getAudioObject();
return parseInt( objAO.volume * 100 );
};
/**
* Sets current volume (in percent).
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name volume
* @param {number} [intPercent] - Volume value (percent)
* @returns {boolean} - Returns 'true' on success
* @see TinyMusicPlayer::_arrConfiguration
* @see TinyMusicPlayer::getAudioObject
* @since 1.0.0
* @version 1.0.0
*/
this.volume = function( intPercent )
{
intPercent = ( typeof intPercent !== 'number' ) ? 100 : intPercent;
if( intPercent < 0 )
{
intPercent = 0;
}
if( intPercent > 100 )
{
intPercent = 100;
}
var objAO = this.getAudioObject();
if( typeof objAO !== 'object' )
{
return false;
}
var intPTF = intPercent;
if( intPercent === 100 )
{
intPTF = 1.0;
}
else if( intPercent === 0 )
{
intPTF = 0.0;
}
else
{
intPTF = parseFloat( intPercent / 100 );
}
objAO.volume = intPTF;
return true;
};
/**
* Increases current volume (by percent units).
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name volumeUp
* @param {number} [intUnits] - Units value (percent)
* @returns {boolean} - Returns 'true' on success
* @see TinyMusicPlayer::_arrConfiguration
* @see TinyMusicPlayer::volume
* @see TinyMusicPlayer::getVolume
* @since 1.0.0
* @version 1.0.0
*/
this.volumeUp = function( intUnits )
{
intUnits = ( ( typeof intUnits !== 'number' ) &&
( typeof intUnits !== 'string' ) )
? this._arrConfiguration[ 'default_volume_up_units' ]
: intUnits;
if( typeof intUnits === 'string' )
{
intUnits = parseInt( intUnits );
}
return this.volume( this.getVolume() + intUnits );
};
/**
* Decreases current volume (by percent units).
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name volumeDown
* @param {number} [intUnits] - Units value (percent)
* @returns {boolean} - Returns 'true' on success
* @see TinyMusicPlayer::_arrConfiguration
* @see TinyMusicPlayer::volume
* @see TinyMusicPlayer::getVolume
* @since 1.0.0
* @version 1.0.0
*/
this.volumeDown = function( intUnits )
{
intUnits = ( ( typeof intUnits !== 'number' ) &&
( typeof intUnits !== 'string' ) )
? this._arrConfiguration[ 'default_volume_down_units' ]
: intUnits;
if( typeof intUnits === 'string' )
{
intUnits = parseInt( intUnits );
}
return this.volume( this.getVolume() - intUnits );
};
/**
* Returns current mute status.
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name isMuted
* @param {void} -
* @returns {boolean} - Returns 'true' if audio is muted
* @see TinyMusicPlayer::getAudioObject
* @since 1.0.0
* @version 1.0.0
*/
this.isMuted = function()
{
var objAO = this.getAudioObject();
return objAO.muted;
};
/**
* Toggles current mute status.
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name mute
* @param {void} -
* @returns {boolean} - Returns 'true' if audio is muted
* @see TinyMusicPlayer::getAudioObject
* @since 1.0.0
* @version 1.0.0
*/
this.mute = function()
{
var objAO = this.getAudioObject();
objAO.muted = ( objAO.muted ) ? false : true;
return objAO.muted;
};
/**
* Returns current playback speed (in percent).
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name getSpeed
* @param {void} -
* @returns {number} - Current playback speed (in percent)
* @see TinyMusicPlayer::getAudioObject
* @since 1.0.0
* @version 1.0.0
*/
this.getSpeed = function()
{
var objAO = this.getAudioObject();
return parseInt( objAO.playbackRate * 100 );
};
/**
* Sets current playback speed (in percent).
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name speed
* @param {number} [intPercent] - Speed value (percent)
* @returns {boolean} - Returns 'true' on success
* @see TinyMusicPlayer::_arrConfiguration
* @see TinyMusicPlayer::getAudioObject
* @since 1.0.0
* @version 1.0.0
*/
this.speed = function( intPercent )
{
intPercent = ( typeof intPercent !== 'number' )
? 100
: intPercent;
if( intPercent < this._arrConfiguration[ 'speed_minimum_percent' ] )
{
intPercent = this._arrConfiguration[ 'speed_minimum_percent' ];
}
if( intPercent > this._arrConfiguration[ 'speed_maximum_percent' ] )
{
intPercent = this._arrConfiguration[ 'speed_maximum_percent' ];
}
var objAO = this.getAudioObject();
if( typeof objAO !== 'object' )
{
return false;
}
var intPTF = intPercent;
if( intPercent === 100 )
{
intPTF = 1.0;
}
else if( intPercent === 0 )
{
intPTF = 0.0;
}
else
{
intPTF = parseFloat( intPercent / 100 );
}
objAO.playbackRate = intPTF;
return true;
};
/**
* Increases current playback speed (by percent units).
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name speedUp
* @param {number} [intUnits] - Units value (percent)
* @returns {boolean} - Returns 'true' on success
* @see TinyMusicPlayer::_arrConfiguration
* @see TinyMusicPlayer::speed
* @see TinyMusicPlayer::getSpeed
* @since 1.0.0
* @version 1.0.0
*/
this.speedUp = function( intUnits )
{
intUnits = ( ( typeof intUnits !== 'number' ) &&
( typeof intUnits !== 'string' ) )
? this._arrConfiguration[ 'default_speed_up_units' ]
: intUnits;
if( typeof intUnits === 'string' )
{
intUnits = parseInt( intUnits );
}
return this.speed( this.getSpeed() + intUnits );
};
/**
* Decreases current playback speed (by percent units).
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name speedDown
* @param {number} [intUnits] - Units value (percent)
* @returns {boolean} - Returns 'true' on success
* @see TinyMusicPlayer::_arrConfiguration
* @see TinyMusicPlayer::speed
* @see TinyMusicPlayer::getSpeed
* @since 1.0.0
* @version 1.0.0
*/
this.speedDown = function( intUnits )
{
intUnits = ( ( typeof intUnits !== 'number' ) &&
( typeof intUnits !== 'string' ) )
? this._arrConfiguration[ 'default_speed_down_units' ]
: intUnits;
if( typeof intUnits === 'string' )
{
intUnits = parseInt( intUnits );
}
return this.speed( this.getSpeed() - intUnits );
};
/**
* Returns informations about a song.
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name getSongInfo
* @param {number} [intSongIndex] - Song index
* @returns {array} - Informations about a song
* @see TinyMusicPlayer::_arrConfiguration
* @see TinyMusicPlayer::_getSongInfo
* @since 1.0.0
* @version 1.0.0
*/
this.getSongInfo = function( intSongIndex )
{
intSongIndex = ( typeof intSongIndex !== 'number' )
? this._arrConfiguration[ 'current_song_index' ]
: intSongIndex;
return this._getSongInfo(
intSongIndex ,
this._arrConfiguration[ 'current_playlist' ] ,
this._arrConfiguration[ 'data_delimiter' ] );
};
/**
* Returns raw data of current playlist.
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name getPlayListRawData
* @param {void} -
* @returns {array} - Raw data of current playlist
* @see TinyMusicPlayer::_arrConfiguration
* @since 1.0.0
* @version 1.0.0
*/
this.getPlayListRawData = function()
{
return this._arrConfiguration[ 'current_playlist' ];
};
/**
* Builds/fills up the playlist container element.
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name buildPlayListContainer
* @param {void} -
* @returns {boolean} - Returns 'true' on success
* @see TinyMusicPlayer::_arrConfiguration
* @see TinyMusicPlayer::getPlayListRawData
* @see TinyMusicPlayer::getSongInfo
* @see TinyMusicPlayer::getCurrentSongIndex
* @since 1.0.0
* @version 1.0.0
*/
this.buildPlayListContainer = function()
{
var objPC = document.getElementById(
this._arrConfiguration[ 'playlist_container_identifier' ] );
if( ( objPC === null ) || ( typeof objPC !== 'object' ) )
{
return false;
}
var arrPL = this.getPlayListRawData();
if( typeof arrPL !== 'object' )
{
return false;
}
var intPL = arrPL.length;
var arrSI = null;
var intI = 0;
var strPC = '';
objPC.innerHTML =
this._arrConfiguration[ 'playlist_container_header' ];
for( intI = 0 ; intI < intPL ; intI++ )
{
arrSI = this.getSongInfo( ( intI + 1 ) );
if( this.getCurrentSongIndex() === ( intI + 1 ) )
{
strPC =
this._arrConfiguration[
'playlist_container_entry_current' ];
}
else
{
strPC =
this._arrConfiguration[
'playlist_container_entry' ];
}
strPC = strPC.replace(
'%handler%' ,
this._arrConfiguration[ 'playlist_container_item_handler' ] );
strPC = strPC.replace( /%index%/g , ( intI + 1 ) );
strPC = strPC.replace( /%album_name%/g , arrSI[ 'album_name' ] );
strPC = strPC.replace( /%album_info%/g , arrSI[ 'album_info' ] );
strPC = strPC.replace( /%track%/g , arrSI[ 'track' ] );
strPC = strPC.replace( /%name%/g , arrSI[ 'name' ] );
strPC = strPC.replace( /%info%/g , arrSI[ 'info' ] );
strPC = strPC.replace( /%url%/g , arrSI[ 'url' ] );
strPC = strPC.replace( /%cover%/g , arrSI[ 'cover' ] );
objPC.innerHTML += strPC;
}
objPC.innerHTML +=
this._arrConfiguration[ 'playlist_container_footer' ];
return true;
};
/**
* Refreshes the playlist container element.
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name refreshPlayListContainer
* @param {void} -
* @returns {boolean} - Returns 'true' on success
* @see TinyMusicPlayer::_arrConfiguration
* @see TinyMusicPlayer::getPlayListRawData
* @see TinyMusicPlayer::getCurrentSongIndex
* @since 1.0.0
* @version 1.0.0
*/
this.refreshPlayListContainer = function()
{
var arrPL = this.getPlayListRawData();
if( typeof arrPL !== 'object' )
{
return false;
}
var intPL = arrPL.length;
var intI = 0;
var objPI = null;
for( intI = 0 ; intI < intPL ; intI++ )
{
objPI = document.getElementById(
this._arrConfiguration[ 'playlist_container_identifier' ] +
'_item_number_' +
( intI + 1 ) );
if( ( objPI !== null ) && ( typeof objPI === 'object' ) )
{
if( ( intI + 1 ) === this.getCurrentSongIndex() )
{
objPI.setAttribute(
'class' ,
this._arrConfiguration[
'playlist_container_identifier' ] +
'_container_item_current' );
}
else
{
objPI.setAttribute(
'class' ,
this._arrConfiguration[
'playlist_container_identifier' ] +
'_container_item' );
}
}
}
return true;
};
/**
* Returns a hash value from current location.
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name getHashValue
* @param {string} [strKey] - A key name
* @returns {string|boolean} - A hash value or 'false'
* @since 1.0.0
* @version 1.0.0
*/
this.getHashValue = function( strKey )
{
strKey = ( typeof strKey !== 'string' ) ? '' : strKey;
if( strKey === '' )
{
return false;
}
var mxM = location.hash.match( new RegExp( strKey + '=([^&]*)' ) );
return mxM ? mxM[ 1 ] : false;
};
/**
* Returns a parameter value from current location.
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name getURLParameter
* @param {string} [strKey] - A key name
* @returns {string|boolean} - A parameter value or 'false'
* @see TinyMusicPlayer::getHashValue
* @since 1.0.0
* @version 1.0.0
*/
this.getURLParameter = function( strKey )
{
strKey = ( typeof strKey !== 'string' ) ? '' : strKey;
if( strKey === '' )
{
return false;
}
var strRV = decodeURIComponent(
( RegExp( strKey + '=' + '(.+?)(&|$)' ).exec(
location.search ) || [, ""] )[ 1 ] );
return ( strRV !== null ) ? strRV : this.getHashValue( strKey );
};
/**
* Returns the current audio object (HTML5 element).
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name getAudioObject
* @param {void} -
* @returns {object} - The current audio object (HTML5 element)
* @see TinyMusicPlayer::_createAudioObject
* @since 1.0.0
* @version 1.0.0
*/
this.getAudioObject = function()
{
return this._createAudioObject();
};
/**
* Returns an unique ID of the current class object.
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name getClassSeed
* @param {void} -
* @returns {string} - An unique ID of the current class object
* @see TinyMusicPlayer::_createClassSeed
* @since 1.0.0
* @version 1.0.0
*/
this.getClassSeed = function()
{
return this._createClassSeed();
};
/**
* Handles controls events.
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name handleEvent
* @param {object} [objEvent] - Source event object
* @returns {boolean} - Always 'true'
* @see TinyMusicPlayer::_arrConfiguration
* @see TinyMusicPlayer::play
* @see TinyMusicPlayer::pause
* @see TinyMusicPlayer::stop
* @see TinyMusicPlayer::next
* @see TinyMusicPlayer::previous
* @see TinyMusicPlayer::forward
* @see TinyMusicPlayer::back
* @see TinyMusicPlayer::getAudioObject
* @see TinyMusicPlayer::seek
* @see TinyMusicPlayer::first
* @see TinyMusicPlayer::last
* @see TinyMusicPlayer::volumeUp
* @see TinyMusicPlayer::volumeDown
* @see TinyMusicPlayer::mute
* @see TinyMusicPlayer::speedUp
* @see TinyMusicPlayer::speedDown
* @since 1.0.0
* @version 1.0.0
*/
this.handleEvent = function( objEvent )
{
var objE = objEvent.target || objEvent.srcElement;
switch( objE.id )
{
case this._arrConfiguration[ 'control_play_identifier' ]:
this.play();
break;
case this._arrConfiguration[ 'control_pause_identifier' ]:
this.pause();
break;
case this._arrConfiguration[ 'control_stop_identifier' ]:
this.stop();
break;
case this._arrConfiguration[ 'control_next_identifier' ]:
this.next();
break;
case this._arrConfiguration[ 'control_previous_identifier' ]:
this.previous();
break;
case this._arrConfiguration[ 'control_forward_identifier' ]:
this.forward( objE.dataset.seconds );
break;
case this._arrConfiguration[ 'control_back_identifier' ]:
this.back( objE.dataset.seconds );
break;
case this._arrConfiguration[ 'control_goto_identifier' ]:
var strGTS = objE.dataset.text;
var strGTD = objE.dataset.default;
if( typeof strGTS !== 'string' )
{
strGTS = '';
}
if( ( strGTD === '' ) || ( strGTD === '*' ) )
{
var objGTAO = this.getAudioObject();
strGTD = parseInt( objGTAO.currentTime );
}
var strURV = prompt( strGTS , strGTD );
this.seek( strURV );
break;
case this._arrConfiguration[ 'control_first_identifier' ]:
this.first();
break;
case this._arrConfiguration[ 'control_last_identifier' ]:
this.last();
break;
case this._arrConfiguration[ 'control_volumeup_identifier' ]:
this.volumeUp( objE.dataset.units );
break;
case this._arrConfiguration[ 'control_volumedown_identifier' ]:
this.volumeDown( objE.dataset.units );
break;
case this._arrConfiguration[ 'control_mute_identifier' ]:
this.mute();
break;
case this._arrConfiguration[ 'control_speedup_identifier' ]:
this.speedUp( objE.dataset.units );
break;
case this._arrConfiguration[ 'control_speeddown_identifier' ]:
this.speedDown( objE.dataset.units );
break;
default:
break;
}
return true;
};
/**
* Handles run event.
*
* @access public
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name handleRun
* @param {void} -
* @returns {boolean} - Always 'true'
* @see TinyMusicPlayer::_arrConfiguration
* @see TinyMusicPlayer::getHashValue
* @see TinyMusicPlayer::setCurrentSongIndex
* @see TinyMusicPlayer::play
* @see TinyMusicPlayer::pause
* @see TinyMusicPlayer::stop
* @see TinyMusicPlayer::next
* @see TinyMusicPlayer::previous
* @see TinyMusicPlayer::forward
* @see TinyMusicPlayer::back
* @see TinyMusicPlayer::getAudioObject
* @see TinyMusicPlayer::seek
* @see TinyMusicPlayer::first
* @see TinyMusicPlayer::last
* @see TinyMusicPlayer::volumeUp
* @see TinyMusicPlayer::volumeDown
* @see TinyMusicPlayer::mute
* @see TinyMusicPlayer::speedUp
* @see TinyMusicPlayer::speedDown
* @see TinyMusicPlayer::refreshPlayListContainer
* @since 1.0.0
* @version 1.0.0
*/
this.handleRun = function()
{
var strPT = this.getHashValue(
this._arrConfiguration[ 'hash_parameter_track_name' ] );
if( ( typeof strPT === 'string' ) && ( strPT !== '' ) )
{
location.hash = '#' +
this._arrConfiguration[ 'hash_parameter_track_name' ] + '=';
this.setCurrentSongIndex( parseInt( strPT ) );
this.play();
}
strPT = this.getHashValue(
this._arrConfiguration[ 'hash_parameter_command_name' ] );
if( ( typeof strPT === 'string' ) && ( strPT !== '' ) )
{
location.hash = '#' +
this._arrConfiguration[ 'hash_parameter_command_name' ] + '=';
switch( strPT )
{
case this._arrConfiguration[ 'control_play_identifier' ]:
this.play();
break;
case this._arrConfiguration[ 'control_pause_identifier' ]:
this.pause();
break;
case this._arrConfiguration[ 'control_stop_identifier' ]:
this.stop();
break;
case this._arrConfiguration[ 'control_next_identifier' ]:
this.next();
break;
case this._arrConfiguration[ 'control_previous_identifier' ]:
this.previous();
break;
case this._arrConfiguration[ 'control_forward_identifier' ]:
this.forward();
break;
case this._arrConfiguration[ 'control_back_identifier' ]:
this.back();
break;
case this._arrConfiguration[ 'control_goto_identifier' ]:
var strGTS = '';
var strGTD = '0';
if( typeof strGTS !== 'string' )
{
strGTS = '';
}
if( ( strGTD === '' ) || ( strGTD === '*' ) )
{
var objGTAO = this.getAudioObject();
strGTD = parseInt( objGTAO.currentTime );
}
var strURV = prompt( strGTS , strGTD );
this.seek( strURV );
break;
case this._arrConfiguration[ 'control_first_identifier' ]:
this.first();
break;
case this._arrConfiguration[ 'control_last_identifier' ]:
this.last();
break;
case this._arrConfiguration[ 'control_volumeup_identifier' ]:
this.volumeUp();
break;
case this._arrConfiguration[ 'control_volumedown_identifier' ]:
this.volumeDown();
break;
case this._arrConfiguration[ 'control_mute_identifier' ]:
this.mute();
break;
case this._arrConfiguration[ 'control_speedup_identifier' ]:
this.speedUp();
break;
case this._arrConfiguration[ 'control_speeddown_identifier' ]:
this.speedDown();
break;
default:
break;
}
}
this.refreshPlayListContainer();
var objAO = this.getAudioObject();
if( objAO.ended )
{
this.next();
}
if( objAO.currentTime > ( objAO.duration - 1 ) )
{
this.next();
}
if( ( window[ this._arrConfiguration[ 'callback_run' ] ] !== null ) &&
( typeof window[ this._arrConfiguration[ 'callback_run' ] ] ===
'function' ) )
{
window[ this._arrConfiguration[ 'callback_run' ] ]();
}
window.setTimeout( this.handleRun.bind( this ) ,
this._arrConfiguration[ 'handle_run_interval' ] );
return true;
};
/**
* Returns informations about a song.
*
* @access private
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name _getSongInfo
* @param {number} [intSongIndex] - Song index
* @param {array} [arrPlayListData] - Raw playlist data
* @param {string} [strDataDelimiter] - Playlist data item delimiter
* @returns {array} - Informations about a song
* @since 1.0.0
* @version 1.0.0
*/
this._getSongInfo = function( intSongIndex ,
arrPlayListData ,
strDataDelimiter )
{
intSongIndex = ( typeof intSongIndex !== 'number' )
? -1 : intSongIndex;
arrPlayListData = ( typeof arrPlayListData !== 'object' )
? new Array() : arrPlayListData;
strDataDelimiter = ( typeof strDataDelimiter !== 'string' )
? '' : strDataDelimiter;
intSongIndex--;
if( ( intSongIndex === -1 ) ||
( arrPlayListData.length < 1 ) ||
( strDataDelimiter === '' ) )
{
return null;
}
if( typeof arrPlayListData[ intSongIndex ] === 'string' )
{
var strTMP = arrPlayListData[ intSongIndex ];
var arrTMP = strTMP.split( strDataDelimiter );
var arrRV = new Array();
arrRV[ 'album_name' ] = arrTMP[ 0 ];
arrRV[ 'album_info' ] = arrTMP[ 1 ];
arrRV[ 'track' ] = arrTMP[ 2 ];
arrRV[ 'name' ] = arrTMP[ 3 ];
arrRV[ 'info' ] = arrTMP[ 4 ];
arrRV[ 'url' ] = arrTMP[ 5 ];
arrRV[ 'cover' ] = arrTMP[ 6 ];
return arrRV;
}
return null;
};
/**
* Generates raw playlist data.
*
* @access private
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name _getPlayList
* @param {string} [strAlbumClassName] - Class name of 'album' element
* @param {string} [strSongClassName] - Class name of 'song' element
* @param {string} [strDataDelimiter] - Playlist data item delimiter
* @returns {array} - Raw playlist data
* @since 1.0.0
* @version 1.0.0
*/
this._getPlayList = function( strAlbumClassName ,
strSongClassName ,
strDataDelimiter )
{
strAlbumClassName = ( typeof strAlbumClassName !== 'string' )
? '' : strAlbumClassName;
strSongClassName = ( typeof strSongClassName !== 'string' )
? '' : strSongClassName;
strDataDelimiter = ( typeof strDataDelimiter !== 'string' )
? '' : strDataDelimiter;
if( ( strAlbumClassName === '' ) ||
( strSongClassName === '' ) ||
( strDataDelimiter === '' ) )
{
return null;
}
var arrPL = new Array();
var objAL = document.getElementsByClassName( strAlbumClassName );
var intAL = objAL.length;
var intCAC = 0;
var objSL = null;
var intSL = null;
var intCSC = null;
var strTMP = null;
for( intCAC = 0 ; intCAC < intAL ; intCAC++ )
{
objAL[ intCAC ].style.display = 'none';
objSL = objAL[ intCAC ].childNodes;
intSL = objSL.length;
for( intCSC = 0 ; intCSC < intSL ; intCSC++ )
{
if( objSL[ intCSC ].className === strSongClassName )
{
strTMP = '';
if( objAL[ intCAC ].hasAttribute( 'data-name' ) )
{
strTMP += objAL[ intCAC ].dataset.name.replace(
strDataDelimiter , '' ).replace( /['"]/g , '' );
}
strTMP += strDataDelimiter;
if( objAL[ intCAC ].hasAttribute( 'data-info' ) )
{
strTMP += objAL[ intCAC ].dataset.info.replace(
strDataDelimiter , '' ).replace( /['"]/g , '' );
}
strTMP += strDataDelimiter;
if( objSL[ intCSC ].hasAttribute( 'data-track' ) )
{
strTMP += objSL[ intCSC ].dataset.track.replace(
strDataDelimiter , '' ).replace( /['"]/g , '' );
}
strTMP += strDataDelimiter;
if( objSL[ intCSC ].hasAttribute( 'data-name' ) )
{
strTMP += objSL[ intCSC ].dataset.name.replace(
strDataDelimiter , '' ).replace( /['"]/g , '' );
}
strTMP += strDataDelimiter;
if( objSL[ intCSC ].hasAttribute( 'data-info' ) )
{
strTMP += objSL[ intCSC ].dataset.info.replace(
strDataDelimiter , '' ).replace( /['"]/g , '' );
}
strTMP += strDataDelimiter;
if( objSL[ intCSC ].hasAttribute( 'data-url' ) )
{
strTMP += objSL[ intCSC ].dataset.url.replace(
strDataDelimiter , '' ).replace( /['"]/g , '' );
}
strTMP += strDataDelimiter;
if( objSL[ intCSC ].hasAttribute( 'data-cover' ) )
{
strTMP += objSL[ intCSC ].dataset.cover.replace(
strDataDelimiter , '' ).replace( /['"]/g , '' );
}
arrPL.push( strTMP );
}
}
}
return arrPL;
};
/**
* Initializes a new or returns the current audio object (HTML5 element).
*
* @access private
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name _createAudioObject
* @param {void} -
* @returns {object} - An audio object (HTML5 element)
* @see TinyMusicPlayer::_arrConfiguration
* @see TinyMusicPlayer::_createClassSeed
* @since 1.0.0
* @version 1.0.0
*/
this._createAudioObject = function()
{
if( typeof this._arrConfiguration[ 'audio_object' ] === 'object' )
{
return this._arrConfiguration[ 'audio_object' ];
}
var objRV = document.createElement( 'AUDIO' );
objRV.setAttribute( 'id' , this._createClassSeed() );
objRV.autoplay = false;
objRV.controls = false;
objRV.defaultMuted = false;
objRV.defaultPlaybackRate = 1.0;
objRV.loop = false;
objRV.muted = false;
objRV.playbackRate = 1.0;
objRV.preload = 'auto';
objRV.volume = 1.0;
this._arrConfiguration[ 'audio_object' ] = objRV;
return this._arrConfiguration[ 'audio_object' ];
};
/**
* Generates an unique ID of the current class object.
*
* @access private
* @author CI:A - Certus In Audio
* @copyright CI:A - Certus In Audio
* @kind function
* @name _createClassSeed
* @param {void} -
* @returns {string} - An unique ID of the current class object
* @see TinyMusicPlayer::_arrConfiguration
* @since 1.0.0
* @version 1.0.0
*/
this._createClassSeed = function()
{
if( typeof this._arrConfiguration[ 'class_seed' ] === 'string' )
{
return this._arrConfiguration[ 'class_seed' ];
}
if( typeof this.constructor.name === 'string' )
{
this._arrConfiguration[ 'class_seed' ] =
this.constructor.name.toLowerCase() +
Math.floor( ( Math.random() * 89999 ) + 10000 );
}
else
{
this._arrConfiguration[ 'class_seed' ] =
'tinymusicplayer' +
Math.floor( ( Math.random() * 89999 ) + 10000 );
}
return this._arrConfiguration[ 'class_seed' ];
};
}