fix: Next video link

This commit is contained in:
Yiannis Christodoulou 2025-07-22 02:07:01 +03:00
parent df2e168184
commit de520e9faa
2 changed files with 13 additions and 2 deletions

View File

@ -6,6 +6,7 @@ const Button = videojs.getComponent('Button');
class NextVideoButton extends Button { class NextVideoButton extends Button {
constructor(player, options) { constructor(player, options) {
super(player, options); super(player, options);
this.nextLink = options.nextLink || '';
} }
createEl() { createEl() {
@ -42,6 +43,7 @@ class NextVideoButton extends Button {
} }
handleClick() { handleClick() {
console.log('NextVideoButton handleClick', this.nextLink);
this.player().trigger('nextVideo'); this.player().trigger('nextVideo');
} }
} }

View File

@ -562,6 +562,7 @@ function VideoJSPlayer() {
}, },
siteUrl: '', siteUrl: '',
hasNextLink: true, hasNextLink: true,
nextLink: 'https://demo.mediacms.io/view?m=YjGJafibO',
}, },
[] []
); );
@ -588,6 +589,7 @@ function VideoJSPlayer() {
poster: mediaData.siteUrl + mediaData.data?.poster_url || '', poster: mediaData.siteUrl + mediaData.data?.poster_url || '',
previewSprite: mediaData?.previewSprite || {}, previewSprite: mediaData?.previewSprite || {},
related_media: mediaData.data?.related_media || [], related_media: mediaData.data?.related_media || [],
nextLink: mediaData.nextLink || '',
sources: mediaData.data?.original_media_url sources: mediaData.data?.original_media_url
? [ ? [
{ {
@ -1023,7 +1025,9 @@ function VideoJSPlayer() {
// BEGIN: Implement custom next video button // BEGIN: Implement custom next video button
if (mediaData.hasNextLink) { if (mediaData.hasNextLink) {
const nextVideoButton = new NextVideoButton(playerRef.current); const nextVideoButton = new NextVideoButton(playerRef.current, {
nextLink: mediaData.nextLink,
});
const playToggleIndex = controlBar.children().indexOf(playToggle); // Insert it after play button const playToggleIndex = controlBar.children().indexOf(playToggle); // Insert it after play button
controlBar.addChild(nextVideoButton, {}, playToggleIndex + 1); controlBar.addChild(nextVideoButton, {}, playToggleIndex + 1);
} }
@ -1659,7 +1663,12 @@ function VideoJSPlayer() {
}; };
}, []); }, []);
return <video ref={videoRef} className="video-js vjs-default-skin" tabIndex="0" />; return (
<>
<video ref={videoRef} className="video-js vjs-default-skin" tabIndex="0" />
<em>nextLink: {currentVideo.nextLink}</em>
</>
);
} }
export default VideoJSPlayer; export default VideoJSPlayer;