Added track selection to music player
This commit is contained in:
parent
3347ff8c77
commit
871bd3cd16
@ -1,5 +1,7 @@
|
|||||||
|
var player = '';
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
var player = new MediaElementPlayer('#music-player', {
|
player = new MediaElementPlayer('#music-player', {
|
||||||
// initial volume when the player starts
|
// initial volume when the player starts
|
||||||
startVolume: 0.5,
|
startVolume: 0.5,
|
||||||
// useful for <audio> player loops
|
// useful for <audio> player loops
|
||||||
@ -25,4 +27,31 @@ $(document).ready(function() {
|
|||||||
// when this player starts, it will pause other players
|
// when this player starts, it will pause other players
|
||||||
pauseOtherPlayers: true
|
pauseOtherPlayers: true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('.now-playing-list .music-track').on('click', function() {
|
||||||
|
// change the audio source
|
||||||
|
changeAudioSources(e);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function changeAudioSources(trackElem) {
|
||||||
|
trackElem = $(trackElem);
|
||||||
|
var playerSources = $('#music-player source');
|
||||||
|
|
||||||
|
// retrieve audio file path from selected element
|
||||||
|
var audioFilePath = trackElem.data('path');
|
||||||
|
|
||||||
|
// loop through the audio player source elements
|
||||||
|
playerSources.each(function(source) {
|
||||||
|
if (source.attr('type') == 'audio/ogg') {
|
||||||
|
// OGG source file
|
||||||
|
source.attr('src', audioFilePath + '.ogg');
|
||||||
|
} else if (source.attr('type') == 'audio/mpeg') {
|
||||||
|
// MP3 source file
|
||||||
|
source.attr('src', audioFilePath + '.mp3');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// reload music player
|
||||||
|
player.load();
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user