-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathplayer.html
224 lines (194 loc) · 8.87 KB
/
player.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<!DOCTYPE html>
<html lang="en">
<head>
<title>飞鸟在线播放器</title>
<meta charset="UTF-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<link href="/static/css/app.css" rel="stylesheet">
<style>
</style>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4953648189792771"
crossorigin="anonymous"></script>
</head>
<body id="body">
<div class="header">
<div class="menu">
<a href="/" class="a-link menu-item">m3u8在线播放器</a>
<a href="/mpd-player.html" class="a-link menu-item">mpd在线播放器</a>
<a href="/iptv-list.html" class="a-link menu-item">IPTV 在线观看</a>
<!-- <a href="/cinema.html" class="a-link menu-item">简单私人影视站 DEMO</a> -->
<a href="/apply-code.html" class="a-link menu-item" >申请激活码</a>
</div>
</div>
<div>
<h1 id="videoName" style="text-align: center;">HLS(.m3u8), DASH(.mpd)视频 在线播放器</h1>
<div class="container">
<div class="input-group mb-3" style="display: flex; justify-content: center; margin: 5px;">
<form class="d-flex" role="search" id="search">
<input :v-model="mediaUrl" name="vodName" class="form-control me-2" id="NOwd" type="search"
placeholder="请输入视频地址, 支持.m3u8,.mpd,.mp4,.webm,.mov等格式" aria-label="Search"
style=" width: 600px; line-height: 1.5rem; max-width:98vw;">
<button class="btn btn-outline-success" type="button" style="width: 80px; line-height: 1.5rem;"
onclick="changeSrc()">播 放</button>
</form>
</div>
</div>
</div>
<main>
<div class="videoWrapper" style="margin-top: 20px; z-index: 99;">
<video src="" controls id="video" autoplay>
</video>
</div>
</main>
<!-- <div id="tip">
<div style="position: absolute; right: -10px; top: -18px;">
<div style="position: relative; " onclick="document.getElementById('tip').style.display='none'"> X </div>
</div>
<div id="checkRes"></div>
<div id="tip">
<div>
<button onclick="download()">下载本视频</button>
</div>
</div> -->
<div class="fooder">
<div style="margin: 5px;"> 飞鸟M3u8下载器 <a href="https://github.com/youwen21/flybird-m3u8downloader/releases"
target="_blank" style="color: #209CEE; text-decoration:underline;">下载</a></div>
<div style="margin: 5px;">QQ群:854313352 <a href="https://qm.qq.com/q/rL2UEWHnj2" target="_blank" style="color: #209CEE; text-decoration:underline;">【进群-下载|交流】</a> </div>
</div>
<!-- <script src="https://cdn.jsdelivr.net/npm/[email protected]"></script> -->
<!-- <script type="module">
import { Base64 } from 'https://cdn.jsdelivr.net/npm/[email protected]/base64.min.js';
</script> -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/base64.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/hls.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/dash.all.min.js"></script>
<script>
</script>
<script>
function checkCORS(mediaUrl) {
fetch('http://127.0.0.1:58123/api/proxy/checkCORS', {
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
method: "POST",
body: JSON.stringify({ media_url: mediaUrl }),
})
// fetch()接收到的response是一个 Stream 对象
// response.json()是一个异步操作,取出所有内容,并将其转为 JSON 对象
.then(response => response.json())
.then(json => {
if (json.code !== 200){
document.getElementById("checkRes").innerText = "检查错误:"+json.msg
return
}
if (json.code === 200 && json.data && json.data.length > 10) {
playMedia(json.data)
} else {
document.getElementById("checkRes").innerText = "此视频可跨域播放,如未正常播放,可尝试下载后观看"
}
})
.catch(err => {
// document.getElementById("checkRes").innerText = "如果视频未正常播放可安装飞鸟m3u8下载器, 尝试CORS跨域播放"
// document.getElementById("tip").style.display = "fixed"
});
}
function isM3u(mediaUrl) {
if (mediaUrl === undefined) {
return false
}
return mediaUrl.indexOf(".m3u") !== -1;
}
function isDash(mediaUrl) {
if (mediaUrl === undefined) {
return false
}
return mediaUrl.indexOf(".mpd") !== -1;
}
// https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8
// https://dash.akamaized.net/dash264/TestCases/1a/sony/SNE_DASH_SD_CASE1A_REVISED.mpd
// https://samplelib.com/lib/preview/mp4/sample-5s.mp4
function changeSrc() {
let mediaUrl = document.getElementById("NOwd").value
if (!mediaUrl) {
alert("请输入要播放的URL")
}
checkCORS(mediaUrl)
playMedia(mediaUrl)
}
function download() {
let mediaUrl = document.getElementById("NOwd").value
fetch('http://127.0.0.1:58123/api/download', {
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
method: "POST",
body: JSON.stringify({ media_url: mediaUrl }),
})
// fetch()接收到的response是一个 Stream 对象
// response.json()是一个异步操作,取出所有内容,并将其转为 JSON 对象
.then(response => response.json())
.then(json => {
console.log(json)
if (json.code == 200) {
document.getElementById("checkRes").innerText = "视频名称:" + json.data.name
return
}
if (json.code != 200) {
document.getElementById("checkRes").innerText = json.msg
}
})
.catch(err => {
document.getElementById("checkRes").innerText = "飞鸟m3u8下载器未启动, 请先启动飞鸟m3u8下载器"
// document.getElementById("tip").style.display="fixed"
});
}
function playMedia(mediaUrl) {
// checkCORS(Base64.encodeURI(mediaUrl))
var video = document.getElementById('video');
if (isM3u(mediaUrl)) {
//
// First check for native browser HLS support
//
if (video.canPlayType('application/vnd.apple.mpegurl')) {
video.src = mediaUrl;
//
// If no native HLS support, check if HLS.js is supported
//
} else if (Hls.isSupported()) {
var hls = new Hls();
hls.loadSource(mediaUrl);
hls.attachMedia(video);
}
video.play()
return
} else if (isDash(mediaUrl)) {
var player = dashjs.MediaPlayer().create();
player.initialize(video, mediaUrl, true);
return
} else {
// https://stackoverflow.com/questions/5235145/changing-source-on-html5-video-tag
video.src = mediaUrl;
video.play();
return
}
}
// let searchParams = new URL(document.location).searchParams;
// https://medium.com/@dtkatz/3-ways-to-fix-the-cors-error-and-how-access-control-allow-origin-works-d97d55946d9
let searchParams = new URL(document.location).searchParams;
let name = searchParams.get("name");
if (name) {
document.getElementById('videoName').innerText = Base64.decode(name);
}
let safeMediaUrl = searchParams.get("media_url");
if (safeMediaUrl){
let mediaUrl = Base64.decode(safeMediaUrl)
document.getElementById("NOwd").value = mediaUrl
checkCORS(mediaUrl)
playMedia(mediaUrl)
}
</script>
</body>
</html>