相關技能
HTML5+CSS3
(實作頁面佈局與動態效果)
Iconfont
(使用向量圖示庫新增播放器相關圖示)
LESS
(動態CSS編寫)
jQuery
(快速編寫js腳本)
gulp+webpack
(自動化建置工具,實作LESS,CSS,JS等編譯和壓縮程式碼)
實現的功能
audio標籤使用
autoplay
自動播放
loop
循環播放
#volume
音量設定
#currentTime
目前播放位置
######## ##duration### 音訊的長度###############pause### 暫停###############play### 播放# ##############ended### 返回音訊是否已結束#############播放和暫停代碼###
1 2 3 4 5 6 7 8 9 | _Music.prototype.playMusic = function (){ var _this = this;this.play.on('click', function (){ if (_this.audio.paused) {
_this.audio.play();
$(this).html('');
} else {
_this.audio.pause();
$(this).html('')
}
});
}
|
登入後複製
###音樂進度條碼###
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | _Music.prototype.volumeDrag = function (){ var _this = this;this.btn.on('mousedown', function (){
_this.clicking = true;
_this.audio.pause();
})this.btn.on('mouseup', function (){
_this.clicking = false;
_this.audio.play();
})this.progress.on('mousemove click', function (e){ if (_this.clicking || e.type === 'click'){ var len = $(this).width(),
left = e.pageX - $(this).offset().left,
volume = left / len; if (volume <= 1 || volume >= 0){
_this.audio.currentTime = volume * _this.audio.duration;
_this.progressLine.css('width', volume *100 +'%');
}
}
});
}
|
登入後複製
###歌詞添加程式碼###
1 2 3 4 5 6 7 | _Music.prototype.readyLyric = function (lyric){this.lyricBox. empty (); var lyricLength = 0; var html = '<div class = "lyric-ani" data-height= "20" >';
lyric.forEach( function (element,index) { var ele = element[1] === undefined ? '^_^歌词错误^_^' : element[1];
html += '<p class = "lyric-line" data-id= "'+index+'" data-time= "' + element[0] + '" > ' + ele + ' </p>';
lyricLength++;
});
html += '</div>';this.lyricBox.append(html);this.onTimeUpdate(lyricLength);
}
|
登入後複製
###程式碼還有很多就不一一添加了,覺得還行的話可以點下喜歡(也可以在我的GitHub給個Star),你的喜歡和Star是我繼續創作的動力,非常感謝! ! !源碼加群###
以上是音樂播放器的製作實例(html5)的詳細內容。更多資訊請關注PHP中文網其他相關文章!