Skip to content

Commit

Permalink
Merge pull request #1 from luanraithz/master
Browse files Browse the repository at this point in the history
Docs and added new parameter
  • Loading branch information
Pedro Lacerda authored Oct 10, 2019
2 parents 58f05e2 + 21b9d48 commit 8e22fb3
Show file tree
Hide file tree
Showing 4 changed files with 4,348 additions and 6 deletions.
25 changes: 21 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,27 @@ Lazy-load (original loaded every image at once).
One image at a time (original showed just like a gallery).
Lazy-load thumbnail request url:

```
thumbnailPlugin: {
getThumbnailForTime: time => `https://mycdn.com/thumb/mylive/thumb-at-${Math.round(time * 1000)}.jpg`
}

## Parameters

`getThumbnailForTime` - Function that will be called once a thumbnail will be shown,
the function argument will be the time where the user has hovered (in milliseconds), and the function must return the url where it should look for the image

`roundBase` - (default is 5) Number to round the seconds to, example, if the `roundBase` is 5, once the user hovers `29 seconds`,
your function will be called as it was just `25 seconds`.

## Example
```javascript
var player = new Clappr.Player({
source: "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4",
parentId: "#player",
plugins: {
core: [ClapprThumbnailsPlugin],
},
thumbnailPlugin: {
getThumbnailForTime: time => `https://mycdn.com/my-awesome-video/thumb-at-${time}.jpg`
}
});
```


3 changes: 2 additions & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
core: [ClapprThumbnailsPlugin],
},
thumbnailPlugin: {
getThumbnailForTime: time => `https://vod-cdn.eventials.com/thumb/6bjevy2jnfu8owoq.json/thumb-${Math.round(time * 1000)}-w150-f1.jpg`
getThumbnailForTime: time => `https://vod-cdn.eventials.com/thumb/6bjevy2jnfu8owoq.json/thumb-${Math.round(time * 1000)}-w150-f1.jpg`,
roundBase: 10
}
});

Expand Down
8 changes: 7 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ export default class ScrubThumbnailsPlugin extends UICorePlugin {
return $container
}

getRoundBase() {
const { roundBase } = this.getOptions()
return roundBase || 5
}

// calculate how far along the carousel should currently be slid
// depending on where the user is hovering on the progress bar

Expand All @@ -98,7 +103,8 @@ export default class ScrubThumbnailsPlugin extends UICorePlugin {
const videoDuration = this.core.mediaControl.container.getDuration()
// the time into the video at the current hover position
const startTimeOffset = this.core.mediaControl.container.getStartTimeOffset()
const hoverTime = Math.floor((startTimeOffset + (videoDuration * hoverPosition)) / 5) * 5
const roundBase = this.getRoundBase()
const hoverTime = Math.floor((startTimeOffset + (videoDuration * hoverPosition)) / roundBase) * roundBase
const elWidth = this.$el.width()
const thumbWidth = $spotlight.width()

Expand Down
Loading

0 comments on commit 8e22fb3

Please sign in to comment.