Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hooke
/
mlaj
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
hookehuyr
2026-01-19 16:36:41 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
6b4e021a956f6eb268aa731f7e235424306886b3
6b4e021a
1 parent
be60c796
refactor(useVideoPlayer): 添加注释并重新组织视频播放器逻辑
为视频播放器逻辑添加清晰的注释标记 重新组织代码结构使其更易读
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
1 deletions
src/composables/useVideoPlayer.js
src/composables/useVideoPlayer.js
View file @
6b4e021
...
...
@@ -44,11 +44,13 @@ export function useVideoPlayer(props, emit, videoRef, nativeVideoRef) {
return
(
props
.
videoUrl
||
""
).
trim
();
});
// 3. HLS 支持判断
const
isM3U8
=
computed
(()
=>
{
const
url
=
videoUrlValue
.
value
.
toLowerCase
();
return
url
.
includes
(
'.m3u8'
);
});
// 4. 视频类型判断
const
getVideoMimeType
=
(
url
)
=>
{
const
urlText
=
(
url
||
""
).
toLowerCase
();
if
(
urlText
.
includes
(
".m3u8"
))
return
"application/x-mpegURL"
;
...
...
@@ -57,6 +59,7 @@ export function useVideoPlayer(props, emit, videoRef, nativeVideoRef) {
return
""
;
};
// 5. 视频源配置
const
videoSources
=
computed
(()
=>
{
const
type
=
getVideoMimeType
(
videoUrlValue
.
value
);
if
(
type
)
{
...
...
@@ -65,7 +68,7 @@ export function useVideoPlayer(props, emit, videoRef, nativeVideoRef) {
return
[{
src
:
videoUrlValue
.
value
}];
});
//
3
. 错误处理逻辑
//
6
. 错误处理逻辑
const
formatBytes
=
(
bytes
)
=>
{
const
size
=
Number
(
bytes
)
||
0
;
if
(
!
size
)
return
""
;
...
...
@@ -156,6 +159,7 @@ export function useVideoPlayer(props, emit, videoRef, nativeVideoRef) {
}
};
// 7. 错误处理逻辑
const
handleError
=
(
code
,
message
=
''
)
=>
{
showErrorOverlay
.
value
=
true
;
switch
(
code
)
{
...
...
@@ -281,6 +285,7 @@ export function useVideoPlayer(props, emit, videoRef, nativeVideoRef) {
...
props
.
options
,
}));
// 8. Video.js 挂载处理
const
handleVideoJsMounted
=
(
payload
)
=>
{
state
.
value
=
payload
.
state
;
player
.
value
=
payload
.
player
;
...
...
Please
register
or
login
to post a comment