-
-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for dynamic thumbnails in Artplayer
The code changes introduce a new `art.thumbnails` property that allows for dynamic setting of thumbnails in Artplayer. This feature enhances the user experience by providing a visual preview of the video content.
- Loading branch information
1 parent
5655db4
commit 52d9064
Showing
10 changed files
with
260 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,8 @@ | ||
import { setStyle, isMobile } from '../utils'; | ||
|
||
export default function thumbnails(options) { | ||
return (art) => ({ | ||
...options, | ||
mounted: ($control) => { | ||
const { | ||
option, | ||
events: { loadImg }, | ||
template: { $progress, $video }, | ||
} = art; | ||
|
||
let timer = null; | ||
let image = null; | ||
let loading = false; | ||
let isLoad = false; | ||
|
||
function showThumbnails(posWidth) { | ||
const { url, number, column, width, height } = option.thumbnails; | ||
const width2 = width || image.naturalWidth / column; | ||
const height2 = height || width2 / ($video.videoWidth / $video.videoHeight); | ||
const perWidth = $progress.clientWidth / number; | ||
const perIndex = Math.floor(posWidth / perWidth); | ||
const yIndex = Math.ceil(perIndex / column) - 1; | ||
const xIndex = perIndex % column || column - 1; | ||
setStyle($control, 'backgroundImage', `url(${url})`); | ||
setStyle($control, 'height', `${height2}px`); | ||
setStyle($control, 'width', `${width2}px`); | ||
setStyle($control, 'backgroundPosition', `-${xIndex * width2}px -${yIndex * height2}px`); | ||
if (posWidth <= width2 / 2) { | ||
setStyle($control, 'left', 0); | ||
} else if (posWidth > $progress.clientWidth - width2 / 2) { | ||
setStyle($control, 'left', `${$progress.clientWidth - width2}px`); | ||
} else { | ||
setStyle($control, 'left', `${posWidth - width2 / 2}px`); | ||
} | ||
} | ||
|
||
art.on('setBar', async (type, percentage, event) => { | ||
const isMobileDroging = type === 'played' && event && isMobile; | ||
|
||
if (type === 'hover' || isMobileDroging) { | ||
if (!loading) { | ||
loading = true; | ||
image = await loadImg(option.thumbnails.url); | ||
isLoad = true; | ||
} | ||
|
||
if (!isLoad) return; | ||
|
||
const width = $progress.clientWidth * percentage; | ||
setStyle($control, 'display', 'flex'); | ||
|
||
if (width > 0 && width < $progress.clientWidth) { | ||
showThumbnails(width); | ||
} else { | ||
if (!isMobile) { | ||
setStyle($control, 'display', 'none'); | ||
} | ||
} | ||
|
||
if (isMobileDroging) { | ||
clearTimeout(timer); | ||
timer = setTimeout(() => { | ||
setStyle($control, 'display', 'none'); | ||
}, 500); | ||
} | ||
} | ||
}); | ||
mounted: () => { | ||
this.art.thumbnails = art.options.thumbnails; | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.