|
@@ -288,9 +288,9 @@ function handleSelectChange(objj) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (nameEn === 'music') {
|
|
if (nameEn === 'music') {
|
|
|
- $("#apis-quiet-content > audio").css("display", "block");
|
|
|
|
|
|
|
+ $("#audioDiv").css("display", "block");
|
|
|
|
|
|
|
|
- $("#apis-quiet-content > audio").on('ended', function () {
|
|
|
|
|
|
|
+ $("#audio").on('ended', function () {
|
|
|
let totalCount = $("div#apis-quiet-content").find("span.contentSPAN").text();
|
|
let totalCount = $("div#apis-quiet-content").find("span.contentSPAN").text();
|
|
|
if (totalCount === 0) {
|
|
if (totalCount === 0) {
|
|
|
return;
|
|
return;
|
|
@@ -367,9 +367,9 @@ function handleSelectChange(objj) {
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
} else {
|
|
} else {
|
|
|
- $("#apis-quiet-content > audio").css("display", "none");
|
|
|
|
|
- $("#apis-quiet-content > audio > source").attr("src", "");
|
|
|
|
|
- $("#apis-quiet-content > audio")[0].load();
|
|
|
|
|
|
|
+ $("#audioDiv").css("display", "none");
|
|
|
|
|
+ $("#audio > source").attr("src", "");
|
|
|
|
|
+ $("#audio")[0].load();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (nameEn === 'currentHolding') {
|
|
if (nameEn === 'currentHolding') {
|
|
@@ -882,16 +882,80 @@ function initContentEvent(nameEn) {
|
|
|
symbol = symbol2;
|
|
symbol = symbol2;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- var currentSrc = $("#apis-quiet-content > audio > source").attr("src");
|
|
|
|
|
|
|
+ var currentSrc = $("#audio > source").attr("src");
|
|
|
|
|
+
|
|
|
|
|
+ // 歌词展示
|
|
|
|
|
+ const audio = $("#audio")[0];
|
|
|
|
|
+ // 清除 ontimeupdate 事件处理函数
|
|
|
|
|
+ audio.ontimeupdate = null;
|
|
|
|
|
+ //$(audio).unbind("timeupdate");
|
|
|
|
|
+ const lyricsContainer = $('#lyrics');
|
|
|
|
|
+ lyricsContainer.text('');
|
|
|
|
|
+ $.ajax({
|
|
|
|
|
+ url: "musicInfo/requestFile", // 替换为实际的 LRC 文件 URL
|
|
|
|
|
+ data: {
|
|
|
|
|
+ "url": symbol.replace('mp3', 'lrc')
|
|
|
|
|
+ },
|
|
|
|
|
+ type: "post", //请求方式
|
|
|
|
|
+ async: false, //请求是否异步,默认为异步,这也是ajax重要特性
|
|
|
|
|
+ success: function (data) {
|
|
|
|
|
+ if (data == null || $.trim(data) == "" || !data.success) {
|
|
|
|
|
+ lyricsContainer.text("未获取到歌词!");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const lrc = data.data;
|
|
|
|
|
+ if (lrc === '') {
|
|
|
|
|
+ lyricsContainer.text("未获取到歌词!");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 将 LRC 歌词解析为数组
|
|
|
|
|
+ const lyrics = lrc.trim().split('\n').filter(line => {
|
|
|
|
|
+ // 使用正则检查是否符合 [mm:ss.xx] 或 [mm:ss.xxx] 格式
|
|
|
|
|
+ return /^\[\d{2}:\d{2}(\.\d{2,3})?\]/.test(line) && line !== null;
|
|
|
|
|
+ }).map(function (line) {
|
|
|
|
|
+ let indexOf = line.lastIndexOf("]");
|
|
|
|
|
+ const time = line.substring(1, indexOf).split(":");
|
|
|
|
|
+ const text = line.substring(indexOf + 1).trim();
|
|
|
|
|
+ const seconds = parseInt(time[0]) * 60 + parseFloat(time[1]);
|
|
|
|
|
+ return {time: seconds, text: text};
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // 实时更新歌词
|
|
|
|
|
+ $(audio).on('timeupdate', function () {
|
|
|
|
|
+ const currentTime = audio.currentTime;
|
|
|
|
|
+ let currentLyric = null;
|
|
|
|
|
+
|
|
|
|
|
+ // 查找当前播放时间对应的歌词
|
|
|
|
|
+ for (let i = 0; i < lyrics.length; i++) {
|
|
|
|
|
+ if (currentTime >= lyrics[i].time) {
|
|
|
|
|
+ currentLyric = lyrics[i];
|
|
|
|
|
+ } else {
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (currentLyric) {
|
|
|
|
|
+ // 更新歌词内容
|
|
|
|
|
+ lyricsContainer.text(currentLyric.text);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ },
|
|
|
|
|
+ error: function () {
|
|
|
|
|
+ lyricsContainer.text("未获取到歌词!");
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
if (currentSrc === symbol) {
|
|
if (currentSrc === symbol) {
|
|
|
- $("#apis-quiet-content > audio")[0].play();
|
|
|
|
|
|
|
+ $("#audio")[0].play();
|
|
|
} else {
|
|
} else {
|
|
|
- $("#apis-quiet-content > audio > source").attr("src", symbol);
|
|
|
|
|
- $("#apis-quiet-content > audio")[0].load();
|
|
|
|
|
- $("#apis-quiet-content > audio")[0].play();
|
|
|
|
|
|
|
+ $("#audio > source").attr("src", symbol);
|
|
|
|
|
+ $("#audio")[0].load();
|
|
|
|
|
+ $("#audio")[0].play();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $("#apis-quiet-content > audio")[0].volume = $("#apis-quiet-div-music-playVolumeField").val();
|
|
|
|
|
|
|
+ $("#audio")[0].volume = $("#apis-quiet-div-music-playVolumeField").val();
|
|
|
|
|
|
|
|
$("#apis-quiet-content").find(".contentTD > tr").find('td:nth-child(2)').removeClass("music_highlight");
|
|
$("#apis-quiet-content").find(".contentTD > tr").find('td:nth-child(2)').removeClass("music_highlight");
|
|
|
$(this).parent("td").parent("tr").find('td:nth-child(2)').addClass("music_highlight");
|
|
$(this).parent("td").parent("tr").find('td:nth-child(2)').addClass("music_highlight");
|