Logo

External APIs

Vimeo (Video Player)

We use Vimeo as our video hosting and streaming provider. Our platform integrates with the Vimeo API to provide a seamless video experience with custom settings and event handling. This section will cover the Vimeo video settings, the Video model, event handling, and related attention controls (see docs for attention controls for more details).

Vimeo Video Settings

We have a preset saved on Vimeo to ensure consistent settings across our videos. These settings include hiding Vimeo branding and other platform-specific elements, so the videos appear clean and professional within our e-learning platform.

Video Model

In our database, we have a Video model, which stores the reference to a Vimeo video. The Video model can be managed through the admin panel, where administrators can add or update video references and informations. There we store also the current viewed timestamp based on the last passed attention control here, to init the video on the current timestamp.

Vimeo API and Event Handling

Our platform interacts with the Vimeo API to handle various events and customize the video playback experience. JavaScript event handlers are used to control video playback based on user interactions and assessment progress.

Attention Controls

We use the Vimeo API to enforce attention controls during video playback. For example, if a user fails an attention check, we use the Vimeo API to jump back to a specific point in the video. Forward jumping is also disabled to ensure that users watch the entire video content.

The component

The following snipped demonstrates how we use the Vimeo API to handle events and implement attention controls:

function videoPlayerComponent() {
            return {
                player: null,
                mouseHovered: false,
                playing: false,
                fullscreen: false,
                allowVideoFullscreen: @entangle('allowVideoFullscreen'),
                initVideo() {
                    var hasFinishedVideo = {{ json_encode($hasFinishedVideo) }};
                    var video_width = document.getElementById("video").offsetWidth;
                    var isIos = iOS();
                    var options = {
                        id: {{ $video->vimeo_id }},
                        width: video_width,
                        loop: false,
                        maxwidth: video_width,
                        speed: {{ ($freeView) ? 'true' : 'false' }},
                        controls: true,
                        responsive: true,
                        allowfullscreen: !isIos,
                        webkitallowfullscreen: true,
                        mozallowfullscreen: true,
                        frameborder: 0
                    };
                    var timeWatched = {{$videoLog->playback_position ?? 0}};
                    var player = new Vimeo.Player('video', options);
                    player.setCurrentTime(timeWatched);
                    player.on('play', function () {
                        var event = new CustomEvent('video-play');
                        window.dispatchEvent(event);
                        this.playing = true;
                    });
                    player.on('pause', function () {
                        var event = new CustomEvent('video-pause');
                        window.dispatchEvent(event);
                        this.playing = false;
                    });
                    player.on('timeupdate', function (data) {
                        if (data.seconds - 1 < timeWatched && data.seconds > timeWatched) {
                            timeWatched = data.seconds;
                            var event = new CustomEvent('video-time-updated', {detail: {timecode: data.seconds}});
                            window.dispatchEvent(event);
                        }
                        // @this.call('updatePlaybackPosition', data.seconds);
                    });
                    player.on('ended', function (data) {
                        player.exitFullscreen();
                        player.destroy();
                        @this.call('markCompleted');
                    });
                    @if(!$freeView)
                    player.on("seeked", function (data) {
                        if (timeWatched < data.seconds && !hasFinishedVideo) {
                            player.setCurrentTime(timeWatched);
                        }
                    });
                    @endif
                        this.player = player;
                    window.addEventListener('pause-video', function () {
                        player.pause();
                    })
                    window.addEventListener('unpause-video', function () {
                        player.play();
                    })
                    window.addEventListener('reset-video', function (event) {
                        var newTime = event.detail && event.detail.checkpoint ? event.detail.checkpoint : 0;
                        player.setCurrentTime(newTime);
                        timeWatched = newTime;
                        player.play();
                    })
                    window.addEventListener('exit-fullscreen', function () {
                        player.exitFullscreen();
                    });
                    document.getElementById('video-container').addEventListener('fullscreenchange', (event) => {
                        if (document.fullscreenElement) {
                            var oldWidth = document.querySelector('#video iframe').width;
                            var oldHeight = document.querySelector('#video iframe').height;
                            var newWidth = window.innerWidth;
                            var newHeight = (((newWidth - oldWidth) / oldWidth) + 1) * oldHeight;
                            document.querySelector('#video iframe').width = newWidth;
                            document.querySelector('#video iframe').height = newHeight;
                            window.initialVideoSize = {width: oldWidth, height: oldHeight};
                        } else {
                            document.querySelector('#video iframe').height = window.initialVideoSize.height;
                            document.querySelector('#video iframe').width = window.initialVideoSize.width;
                            // document.querySelector('#video iframe').height = newHeight;
                        }
                    });
                },
                startFullscreen() {
                    // on ios, use the native fullscreen
                    if (iOS()) {
                        if (!this.fullscreen) {
                            document.body.scrollTop = 0;
                            document.documentElement.scrollTop = 0;
                            document.body.style.backgroundColor = '#000000';
                            this.fullscreen = true;
                        } else {
                            document.body.style.backgroundColor = '#ffffff';
                            this.fullscreen = false;
                        }
                        return true;
                    }
                    enterFullscreen(document.getElementById('video-container'))
                },
            }
        }

Full-Screen

As you see in the code above, we have a custom full-screen mode for the videos, to make sure that the attention controls are shown also. Normally this wouldn't work with the default full-screen feature of the vimeo player.

Previous
Mollie (payments)