-
Notifications
You must be signed in to change notification settings - Fork 0
/
vDetailjs.js
58 lines (51 loc) · 1.89 KB
/
vDetailjs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const songDataUrls = [
'songs.json',
'https://example.com/songs.json',
'https://backup.example.com/songs.json'
];
function loadSongsData(callback) {
const xhr = new XMLHttpRequest();
function tryNextUrl() {
if (songDataUrls.length > 0) {
const url = songDataUrls.shift();
xhr.open('GET', url, true);
xhr.send();
} else {
console.error('Failed to load song data from all provided URLs.');
}
}
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
try {
const songs = JSON.parse(xhr.responseText);
callback(songs);
} catch (error) {
console.error('Failed to parse song data:', error);
tryNextUrl();
}
} else {
tryNextUrl();
}
}
};
tryNextUrl();
}
// 为视频详情页面加载媒体
const urlParams = new URLSearchParams(window.location.search);
const songTitle = urlParams.get('song');
if (songTitle) {
loadSongsData(songs => {
const song = songs.find(s => s.title === decodeURIComponent(songTitle));
if (song && song.type === 'video') {
const songTitleElement = document.getElementById('songTitle');
const albumTitleElement = document.getElementById('albumTitle');
const mediaContainer = document.getElementById('mediaContainer');
songTitleElement.textContent = song.title;
albumTitleElement.textContent = `${song.album} - ${song.artist}`;
mediaContainer.innerHTML = `<iframe id="videoFrame" src="${song.source}" frameborder="0" allowfullscreen width="100%" height="500"></iframe>`;
} else {
console.error('Song data not found or invalid media type.');
}
});
}