Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/timesegment #1604

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
820f36b
feat(playback): 增加放大镜插件
hongqx Aug 8, 2024
73c2608
feat(xgplayer):timesegments 增加偏移时间和实际时间的换算`
hongqx Jul 30, 2024
722f6eb
feat(xgplayer):
hongqx Jul 30, 2024
b54c7e1
feat(xgplayer): format offsetCurrentTime 和 offsetDuration
hongqx Jul 30, 2024
9c47af1
release: [email protected]
hongqx Jul 30, 2024
f41d1d3
fix(xgplayer): 分段 播放增加loop处理,并修复offsetCurrentTime获取异常问题
hongqx Aug 5, 2024
fe76b51
release: [email protected]
hongqx Aug 5, 2024
5823af5
feat(xgplayer): 进度条故事点打点增加segment偏移处理
hongqx Aug 7, 2024
0df2e83
release: [email protected]
hongqx Aug 7, 2024
b631b96
feat(xgplayer): 伪切片兼容故事点打点
hongqx Aug 8, 2024
d352cb0
release: [email protected]
hongqx Aug 8, 2024
b752ec4
feat(xgplayer): 增加偏移量计算的进度条打点
hongqx Aug 12, 2024
9904295
feat(xgplayer): 增加timesegments_change事件触发
hongqx Aug 12, 2024
dc1e56c
release: [email protected]
hongqx Aug 13, 2024
d5bd813
feat(xgplayer): 增加放大镜能力导出
hongqx Aug 15, 2024
819022c
release: [email protected]
hongqx Aug 15, 2024
83bcb1f
feat(xgplayer): export tool apis from progressPreview
hongqx Aug 16, 2024
f56fbb5
release: [email protected]
hongqx Aug 16, 2024
36df210
feat(xgplayer): plugin poster add autoLoad
hongqx Aug 21, 2024
844883a
release: [email protected]
hongqx Aug 21, 2024
f05704c
fix(timesegments): 修复durationchange重复触发异常问题
hongqx Aug 27, 2024
c6e60b1
release: [email protected]
hongqx Aug 27, 2024
89180d1
feat(xgplayer):timesegments 增加偏移时间和实际时间的换算`
hongqx Jul 30, 2024
2403997
feat(xgplayer):
hongqx Jul 30, 2024
714bdf2
feat(xgplayer): format offsetCurrentTime 和 offsetDuration
hongqx Jul 30, 2024
7692e68
release: [email protected]
hongqx Jul 30, 2024
fc34760
fix(xgplayer): 分段 播放增加loop处理,并修复offsetCurrentTime获取异常问题
hongqx Aug 5, 2024
a54b3b7
feat(xgplayer): merge
hongqiongxing-b Sep 11, 2024
84d2896
feat(xgplayer): merge
hongqiongxing-b Sep 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fixtures/xgplayer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
</head>

<body>
<div id="video0" style="margin: 0 auto"></div>
<div id="video0" style="margin: 0 auto; overflow: visible;"></div>
<div class="pannel">
<div class="tool">
<button type="submit" class="btn" id="js-destroy0" onclick="window.destroy(0)">
Expand Down
62 changes: 51 additions & 11 deletions fixtures/xgplayer/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Player, { SimplePlayer, Util } from '../../packages/xgplayer/src/index'
import { TextTrack } from '../../packages/xgplayer/src/index'
import Magnifier from '../../packages/xgplayer/src/plugins/magnifier'
import HlsPlayer from '../../packages/xgplayer-hls/src/index'
import Poster from '../../packages/xgplayer/src/plugins/poster'
// import HeatMap from '../../packages/xgplayer/src/plugins/heatmap'
import { I18N } from '../../packages/xgplayer/src'
// import DynamicBg from '../../packages/xgplayer/src/plugins/dynamicBg'
Expand Down Expand Up @@ -299,9 +301,8 @@ function init(index = 0, config = {}) {
autoplayMuted: true,
videoInit: true,
preloadTime: 20,
width: '96%',
ignores:[],
plugins: [],
plugins: [HlsPlayer],
rotate: false,
heatmap: {
data: headmapData,
Expand Down Expand Up @@ -341,17 +342,38 @@ function init(index = 0, config = {}) {
// gestureX: false
},
// timeSegments: ,
// timeSegmentsControls:{
// disable: false,
// segments: [{start: 0, end: 10}]
// },
timeSegmentsControls:{
disable: false,
segments: [{start: 35, end: 60}]
},
keyboard: {
seekStep: 2
},
progresspreview: {
// width: 88.23,
// height: 50,
mode: 'short'
mode: 'short',
ispots: [{
time: 20,
duration: 10,
text: '1111',
id: 1
},{
time: 40,
duration: 165,
text: '2222',
id: 2
},{
time: 170,
duration: 20,
text: '3333',
id: 3
},{
time: 250,
duration: 400,
text: '4444',
id: 3
}]
},
seekedStatus: 'auto',
texttrack: {
Expand Down Expand Up @@ -385,7 +407,8 @@ function init(index = 0, config = {}) {
defaultDefinition: '360p',
isItemClickHide: false
},
height: 300,
width: 700,
height: 337.5,
miniprogress: true,
...config
})
Expand All @@ -396,11 +419,28 @@ function init(index = 0, config = {}) {
// setTimeout(() => {
// window[p].registerPlugin(Poster)
// }, 10)
window[p].once('canplay',() => {
console.log('>>>>>canplay seek', window[p].media.seekable.end(0))
window[p].on('seeking',() => {
console.log('>>>>>canplay seek', window[p].media.currentTime)
// window[p].seek(30)
// window[p].play()
})
window[p].on('timeupdate',() => {
console.log('>>>>>timeupdate', window[p].media.currentTime)
})

window[p].on('loadeddata',() => {
console.log('>>>>>loadeddata', window[p].media.duration)
})
window[p].on('durationchange',() => {
console.log('>>>>>durationchange', window[p].media.duration)
})
window[p].on('poster_load',(data) => {
console.log('>>>>>poster_load', data)
})

window[p].once('timesegments_change', (data) => {
console.log('>>>timesegments_change', data.timeSegments)
})

window[p].on('source_error', (data) => {
console.error('source_error', data)
Expand Down
4 changes: 2 additions & 2 deletions packages/xgplayer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xgplayer",
"version": "3.0.21-rc.2",
"version": "3.0.21-alpha.8",
"description": "video player",
"main": "dist/index.min.js",
"module": "es/index.js",
Expand All @@ -16,7 +16,7 @@
"publishConfig": {
"registry": "https://registry.npmjs.org/",
"access": "public",
"tag": "rc"
"tag": "alpha"
},
"files": [
"dist",
Expand Down
3 changes: 3 additions & 0 deletions packages/xgplayer/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ export { default as CssFullscreenIcon } from './plugins/cssFullScreen'
export { default as Danmu } from './plugins/danmu'
export { DanmuIcon, DanmuPanel } from './plugins/danmu'
export { default as TextTrack } from './plugins/track'
export { default as Magnifier } from './plugins/magnifier'
export { default as HeatMap } from './plugins/heatmap'
export * from './plugins/progressPreview'
export { default as TimeSegmentsControls } from './plugins/time/timesegments'


/**
Expand Down
6 changes: 3 additions & 3 deletions packages/xgplayer/src/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ class Player extends MediaProxy {
*/
this._offsetInfo = {
currentTime: -1,
duration: 0
duration: -1
}

/**
Expand Down Expand Up @@ -2592,15 +2592,15 @@ class Player extends MediaProxy {
}

get offsetCurrentTime () {
return this._offsetInfo.currentTime || 0
return this._offsetInfo.currentTime > -1 ? this._offsetInfo.currentTime : this.currentTime
}

set offsetCurrentTime (val) {
this._offsetInfo.currentTime = val
}

get offsetDuration () {
return this._offsetInfo.duration || 0
return this._offsetInfo.duration > -1 ? this._offsetInfo.duration : this.duration
}

set offsetDuration (val) {
Expand Down
174 changes: 174 additions & 0 deletions packages/xgplayer/src/plugins/magnifier/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
import Plugin, { Util, Events } from '../../plugin'
import IntervalTimer from './intervalTimer'
import './index.scss'

const TAG = 'Magnifier'
export default class Magnifier extends Plugin {
static get pluginName () {
return 'magnifier'
}

/**
* @type IControlsConfig
*/
static get defaultConfig () {
return {
disable: true,
magnifierWidth: 200,
magnifierHeight: 200,
magnifierRatio: 2,
interval: 100,
index: 1
}
}

afterCreate () {
const { config } = this
this.canvas = document.createElement('canvas')
this.root.appendChild(this.canvas)
Util.addClass(this.canvas, 'magnifier-canvas')
this.canvasCtx = this.canvas.getContext('2d')
this.canvas.width = config.magnifierWidth || 200
this.canvas.height = config.magnifierHeight || 120
console.log(TAG, 'afterCreate', this.canvas.width , this.canvas.height, config)
this.ratio = config.magnifierRatio || 1
this.isOpen = false
this.isEnter = false
this.contentY = 0
this.contentX = 0
this.bindEvents()
// this.switchMagnifier()
// this.startRender()
}

bindEvents () {
console.log(TAG, 'bindEvents')
const playerRoot = this.player.root
playerRoot.addEventListener('mousemove', this.onMouseMove)
// playerRoot.addEventListener('mouseenter', this.onEnterPlayer)
this.player.on(Events.ENTER_PLAYER, this.onEnterPlayer)
this.player.on(Events.LEAVE_PLAYER, this.onLeavePlayer)
}

unbindEvents () {
const playerRoot = this.player.root
playerRoot.removeEventListener('mousemove', this.onMouseMove)
}

onMouseMove = (e) => {
if (this.isOpen) {
this.position(e)
}
}

onLeavePlayer = (e) => {
console.log('>>>onLeavePlayer')
this.isEnter = false
this.hide()
}

onEnterPlayer = (e) => {
console.log('>>>onEnterPlayer')
this.isEnter = true
this.isOpen && this.show()
}

position (e) {
const { player } = this
const playerRect = player.root.getBoundingClientRect()
const rootRect = playerRect // this.root.getBoundingClientRect()
const mWidth = this.canvas.width
const mHeight = this.canvas.height
const offsetX = e.pageX - playerRect.left
const offsetY = e.pageY - playerRect.top
const playerWidth = playerRect.width
const playerHeight = playerRect.height
const canvasLeft = offsetX - mWidth / 2
const canvasTop = offsetY - mHeight / 2
this.canvas.style.left = `${(offsetX > 0 ? (offsetX < playerWidth ? canvasLeft : playerWidth - mWidth / 2) : -mWidth / 2) + playerRect.left - rootRect.left}px`
this.canvas.style.top = `${(offsetY > 0 ? (offsetY < playerHeight ? canvasTop : playerHeight - mHeight / 2) : - mHeight / 2) + playerRect.top - rootRect.top}px`

this.contentX = offsetX
this.contentY = offsetY
}

switchMagnifier () {
if (this.isOpen) {
this.stopRender()
this.hide()
} else {
this.isEnter && this.show()
this.startRender()
}
this.isOpen = !this.isOpen
}

startRender () {
const { magnifierWidth, magnifierHeight, interval } = this.config
const { canvas } = this
canvas.width = magnifierWidth
canvas.height = magnifierHeight
if (this.videoTimer) {
return
}
this.videoTimer = new IntervalTimer()
this.videoTimer.repeat(() => {
this.update()
}, interval)
}

stopRender () {
if (this.videoTimer) {
this.videoTimer.clear()
this.videoTimer = null
}
}

update () {
const { player } = this
const { videoWidth, videoHeight } = player.media
const mWidth = this.canvas.width
const mHeight = this.canvas.height
this.canvasCtx.fillRect(0, 0, mWidth, mHeight)
const playerRect = player.root.getBoundingClientRect()
const left = (this.contentX - mWidth / 2 / this.ratio) * videoWidth / playerRect.width
const top = (this.contentY - mHeight / 2 / this.ratio) * videoHeight / playerRect.height
const width = mWidth / this.ratio * videoWidth / playerRect.width
const height = mHeight / this.ratio * videoHeight / playerRect.height
const sx = left > 0 ? left : 0
const sy = top > 0 ? top : 0
let swidth = left > 0 ? width : width + left
let sheight = top > 0 ? height : height + top
if (playerRect.width < (this.contentX + mWidth / 4 / this.ratio)) {
swidth = width - (this.contentX + mWidth / 4 / this.ratio - playerRect.width) * videoWidth / playerRect.width
}
if (playerRect.height < (this.contentY + mHeight / 4 / this.ratio)) {
sheight = height - (this.contentY + mHeight / 4 / this.ratio - playerRect.height) * videoHeight / playerRect.height
}
const dx = left > 0 ? 0 : mWidth / 2 - this.contentX * this.ratio
const dy = top > 0 ? 0 : mWidth / 2 - this.contentY * this.ratio

const dwidth = left > 0 ? mWidth : mWidth - (mWidth / 2 - this.contentX * this.ratio)
const dheight = top > 0 ? mHeight : mHeight - (mHeight / 2 - this.contentY * this.ratio)
this.canvasCtx.drawImage(player.media,
sx,
sy,
swidth,
sheight,
dx < 0 ? 0 : dx,
dy < 0 ? 0 : dy,
dwidth > 0 ? dwidth : 0,
dheight > 0 ? dheight : 0)
}

destroy () {
if (this.videoTimer) {
this.videoTimer.clear()
this.videoTimer = null
}
this.unbindEvents()
}
render () {
return '<div class="magnifier-root"></div>'
}
}
5 changes: 5 additions & 0 deletions packages/xgplayer/src/plugins/magnifier/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.magnifier-canvas {
position: absolute;
z-index: 10;
pointer-events: none;
}
27 changes: 27 additions & 0 deletions packages/xgplayer/src/plugins/magnifier/intervalTimer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class IntervalTimer {
constructor () {
this.timeID = null
this.func = null
}

repeat (func, ms) {
if (this.func === null) {
this.func = func
}

if (this.func !== func) {
return
}

this.timeID = setTimeout(() => {
func()
this.repeat(func, ms)
}, ms)
}

clear () {
clearTimeout(this.timeID)
}
}

export default IntervalTimer
Loading