-
Notifications
You must be signed in to change notification settings - Fork 2
/
o.html
102 lines (91 loc) · 2.83 KB
/
o.html
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Custom Video Player</title>
<script src="https://cdn.jsdelivr.net/npm/@oplayer/core@latest/dist/index.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@oplayer/ui@latest/dist/index.min.js"></script>
<style>
/* Make the player fill the viewport */
body, html {
margin: 0;
padding: 0;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
background-color: #f0f0f0;
}
#oplayer {
width: 800px;
height: 450px;
max-width: 100%;
max-height: 100%;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
border-radius: 8px;
overflow: hidden;
}
</style>
</head>
<body>
<div id="oplayer"></div>
<script>
// Utility to get URL parameters
function getParam(param) {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get(param);
}
// Load video info from API using the ID from URL parameters
async function loadVideoData() {
const id = getParam('id');
const apiUrl = `https://api-p1xr.vercel.app/api/v2/stream/${id}`;
try {
const response = await fetch(apiUrl);
const data = await response.json();
if (data.code === 200 && data.info && data.stream) {
initializePlayer(data);
} else {
console.error("Failed to fetch video data.");
}
} catch (error) {
console.error("API error:", error);
}
}
// Initialize OPlayer with video data and resume position if available
function initializePlayer(data) {
const { title } = data.info;
const { url, isM3U8 } = data.stream.multi.main;
const thumbnailUrl = data.stream.tracks.file;
const player = OPlayer.make('#oplayer', {
source: {
title: title,
src: url,
type: isM3U8 ? 'application/x-mpegURL' : 'video/mp4',
poster: 'https://cdn.jsdelivr.net/gh/shiyiya/QI-ABSL@master/o/poster.png',
thumbnails: {
src: thumbnailUrl
}
},
})
.use([OUI()])
.create();
// Check local storage for saved time and resume if available
const savedTime = localStorage.getItem(`progress-${data.info.id}`);
if (savedTime) {
player.seek(Number(savedTime));
}
// Save progress every second
player.on('timeupdate', () => {
localStorage.setItem(`progress-${data.info.id}`, player.currentTime());
});
// Remove progress when video ends
player.on('ended', () => {
localStorage.removeItem(`progress-${data.info.id}`);
});
}
// Load video data and initialize player
loadVideoData();
</script>
</body>
</html>