12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- import H265webjsModule from './h265/index'
- const durationFormmat = (val) => {
- val = val.toString()
- if (val.length < 2) return '0' + val
- return val
- }
- const setDurationText = (duration) => {
- if (duration < 0) return 'Player'
- const randDuration = Math.round(duration)
- return (
- durationFormmat(Math.floor(randDuration / 3600)) +
- ':' +
- durationFormmat(Math.floor((randDuration % 3600) / 60)) +
- ':' +
- durationFormmat(Math.floor(randDuration % 60))
- )
- }
- export const createPlayerServer = (videoUrl, config) => {
- return H265webjsModule.createPlayer(videoUrl, config)
- }
- export const executePlayerServer = (player, timelineEl) => {
- // todo....
- let mediaInfo = null
- player.onLoadFinish = () => {
- mediaInfo = player.mediaInfo()
- if (mediaInfo.videoType === 'vod') {
- timelineEl.textContent =
- setDurationText(0) +
- '/' +
- setDurationText(mediaInfo.meta.durationMs / 1000)
- }
- }
- player.onPlayTime = (pts) => {
- if (mediaInfo.videoType === 'vod') {
- timelineEl.textContent =
- setDurationText(pts) +
- '/' +
- setDurationText(mediaInfo.meta.durationMs / 1000)
- }
- }
- console.log(player)
- player.do()
- }
- /**
- *
- * @param {ReturnType<typeof H265webjsModule.createPlayer>} playerInstance
- */
- export const destoryPlayerServer = (playerInstance) => {
- // release playerInstance & forece Gc
- playerInstance.release()
- playerInstance = null
- }
|