-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from MAlshaik/main
Added timeline as well as updating video once the video has been cut
- Loading branch information
Showing
7 changed files
with
144 additions
and
123 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
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,52 +1,69 @@ | ||
// This function generates the timeline | ||
function generateTimeline(src) { | ||
|
||
$( "#defaultPlayer" ).mediaPlayer( { | ||
autoplay: false, | ||
src: src, | ||
controlBar: { | ||
sticky: true | ||
}, | ||
plugins: { | ||
dataServices: [ | ||
'/static/timeline/samples-data/examples/json/amalia01-events.json', | ||
'/static/timeline/samples-data/examples/json/amalia01-kf.json', | ||
'/static/timeline/samples-data/examples/json/amalia01-ball.json' | ||
], | ||
list: [ | ||
{ | ||
'className': 'fr.ina.amalia.player.plugins.TimelinePlugin', | ||
'container': '#amalia-timeline', | ||
'parameters': { | ||
listOfLines: [ | ||
/* | ||
{ | ||
title: 'Events', | ||
type: 'cuepoint', | ||
metadataId: 'events-amalia01', | ||
color: '#3CF', | ||
pointNav: true | ||
}, | ||
{ | ||
title: 'Ball moving up', | ||
type: 'segment', | ||
metadataId: 'ball-amalia01', | ||
color: '#F00' | ||
}, | ||
*/ | ||
{ | ||
title: 'Keyframes every 2s', | ||
type: 'image', | ||
metadataId: 'kf-amalia01', | ||
pointNav: true, | ||
editable: true | ||
} | ||
], | ||
editingMode: true | ||
} | ||
} | ||
] | ||
function generateTimeline() { | ||
const video = document.querySelector('#video'); | ||
const screenshotContainer = document.querySelector('#screenshotContainer'); | ||
const bar = document.querySelector('#bar'); | ||
let interval; | ||
let isDragging = false; | ||
|
||
video.playbackRate = 16; // play the video at 16x speed | ||
video.muted = true; // mute the videoWidth | ||
video.play(); | ||
|
||
video.addEventListener('play', () => { | ||
interval = setInterval(() => { | ||
const canvas = document.createElement('canvas'); | ||
canvas.width = video.videoWidth; | ||
canvas.height = video.videoHeight; | ||
|
||
canvas.getContext('2d').drawImage(video, 0, 0, canvas.width, canvas.height); | ||
const img = document.createElement('img'); | ||
img.src = canvas.toDataURL(); | ||
img.classList.add('screenshot'); | ||
img.addEventListener('click', (e) => { | ||
updateBarPosition(e.clientX); | ||
}); | ||
screenshotContainer.appendChild(img); | ||
}, 10000 / video.playbackRate); // take a screenshot every 10 seconds at normal speed (0.625 seconds at 16x speed) | ||
}); | ||
|
||
video.addEventListener('pause', () => { | ||
clearInterval(interval); | ||
}); | ||
|
||
video.addEventListener('ended', () => { | ||
clearInterval(interval); | ||
video.playbackRate = 1; // reset the playback rate to normal speed | ||
video.muted = false; // unmute the video | ||
video.currentTime = 0; | ||
}); | ||
|
||
bar.addEventListener('mousedown', (e) => { | ||
isDragging = true; | ||
updateBarPosition(e.clientX); | ||
}); | ||
|
||
document.addEventListener('mousemove', (e) => { | ||
if (isDragging) { | ||
updateBarPosition(e.clientX); | ||
} | ||
}); | ||
|
||
document.addEventListener('mouseup', () => { | ||
isDragging = false; | ||
}); | ||
|
||
function updateBarPosition(clientX) { | ||
const rect = screenshotContainer.getBoundingClientRect(); | ||
const x = clientX - rect.left + screenshotContainer.scrollLeft; | ||
const position = Math.max(0, Math.min(x / rect.width, 1)); | ||
bar.style.left = `${position * 100}%`; | ||
video.currentTime = position * video.duration; | ||
} | ||
|
||
screenshotContainer.addEventListener('wheel', (e) => { | ||
e.preventDefault(); | ||
screenshotContainer.scrollLeft += e.deltaY; | ||
}); | ||
} | ||
|
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
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