Pulling data from Vimeo using RESTful API to gather information on seconds of video playback

Utilizing the Vimeo Player API within my Angular project, I have installed it via

npm i @vimeo/player.

This is specifically for privately playing videos (restricted to my website), and when embedding the URL into an iframe, everything works perfectly. I've also implemented code to capture events like pausing and ending from the player, which is functioning as expected.

However, my objective now is to incorporate an API call within the 'pause' event function to retrieve the number of seconds the video has been played for, and then store this information in a database. Additionally, if a user pauses the video, closes their browser, and returns to the website later on, the video should resume from where they left off (by retrieving the saved duration from the database and continuing playback). This functionality is similar to how YouTube operates.

import Player from '@vimeo/player';

export class CoursesComponent implements OnInit, AfterViewInit {

@ViewChildren('vidPlayer') vidPlayer;

ngAfterViewInit() {

let player

console.log(this.vidPlayer.length);

player = new Player(this.vidPlayer.first.nativeElement);

player.on('pause', function (paused) {

     console.log('pause', paused);
     //--paused.seconds, the no. of seconds played
     let duration = { duration: paused.seconds, status: false };
     //--the datas are static 
    this.courseService.updateLastPlayed('coursename', 'sec3', 'ch9', duration).subscribe((result) => {     
    console.log("LastPlayed chapter updated");
    }, (err) => {
      console.log(err);
    });
  });

}}

Answer №1

For my project in ReactJS, I have implemented the React Player. With this 3rd party library, I am able to utilize the onProgress callback feature that provides information about the amount of played seconds through the playedSeconds property.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What could be causing the excessive number of entries in my mapping results?

I am in need of mapping an array consisting of dates. Each date within this array is associated with a group of dates (formatted as an array). For instance: The format array looks like this: let format = [3, 3, 1, 5, 4, 4, 3, 5, 13, 10, 3, 5, 5, 2, 2, 10] ...

Gather information from a customizable Bootstrap table and store it in an array

Currently, I have a bootstrap table configured with react-bootstrap-table-next, enabling users to edit cells and input their desired values. After completing the editing process, individuals can click on the "Submit" button to save the table values, which ...

An issue with the validation service has been identified, specifically concerning the default value of null in

Using Angular 10 and Password Validator Service static password(control: AbstractControl) { // {6,100} - Check if password is between 6 and 100 characters // (?=.*[0-9]) - Ensure at least one number is present in the strin ...

Vuejs Countdown Timer Powered by Moment.js

Currently, I am working on a vuejs page and I am looking to incorporate a countdown timer that counts down from 5 minutes (e.g. 5:00, 4:59, and so on). Although I have never used momentjs before, I have gone through the moment docs but I am finding it ch ...

Utilize a variable beyond the scope of an ajax success callback

Within a single function, I have a series of timeout functions that execute asynchronously. function myFunction() { var data; setTimeout(function(){ $.ajax({ //My Ajax Stuff success: function(data) { var data = ...

removing duplicate items from an array in Vue.js

I created a Pokemon App where users can add Pokemon to their 'pokedex'. The app takes a pokemon object from this.$store.state.pokemon and adds it to this.$store.state.pokedex. However, users can add the same pokemon multiple times to the pokedex, ...

Angular 2 TypeScript: How to effectively sort an array

I’m currently exploring how to implement array filtering in Angular 2 with TypeScript. Specifically, I am trying to filter data for a search bar in Ionic 2. While the list in the template successfully displays the data, I am encountering difficulty getti ...

choose the li element that is located at the n-th position within

Need help with HTML code <div class="dotstyle"> <ul> <li class="current"><a href="javascript:void(0)"></a></li> <li><a href="javascript:void(0)"></a></li> <li><a href="javasc ...

Validating date inputs with ng-change in AngularJS

I am currently utilizing AngularJS along with AngularJS bootstrap within my webpage. One of the components I have is a date picker directive that is structured like this: <div class="form-group {{dateStatus.class}}"> <p class="input-g ...

Creating an embedded link to a website that adjusts to different screen sizes while also dynamically changing

I've been developing a personalized site builder that includes an iframe for previewing responsive websites. In order to make the site 'zoomed out' and not appear in mobile size, I'm utilizing CSS scale and transform origin as shown bel ...

Tips and tricks for selecting a specific element on a webpage using jQuery

How can I modify my AJAX form submission so that only the content within a span tag with the id "message" is alerted, instead of the entire response page? $.ajax({ url: '/accounts/login/', data: $(this).serialize(), success: function(ou ...

Issues with hover styles and transitions not being correctly applied to newly appended elements in Firefox

Utilizing an SVG as an interactive floor plan, I have implemented a feature where hovering over different areas on the floor plan (<g> elements) causes them to expand and float above other areas. The element scaling is triggered by CSS, but I use jQu ...

A little brain teaser for you: Why is this not functioning properly on Google Chrome?

Have you noticed that the code below works perfectly in Firefox, but fails in Chrome when trying to 'post' data? $("a").click(function() { $.post("ajax/update_count.php", {site: 'http://mysite.com'}); }); Hint: Make sure you are us ...

ReactJS: The uniqueness of [ this.props ] compared to [ props in this ] is incomprehensible

Inside the componentDidMount method, there is a continuous section of code: console.log('hv props'); for(var i = 0; i<20; i++){ console.log(this); console.log(this.props); } console.log('hv props end'); It is expected that ...

Displaying a text in a Django template as a JSON entity

I am currently facing a challenge with an angular app that sends JSON data to a Django backend. The Django application saves the JSON data into a database and later retrieves it to send it back to the angular app. However, I am struggling to get this entir ...

"Experience the magic of Datepicker jQuery with just a click

Does anyone know how to capture the click event when a day is selected using jQuery Datepicker? Is it possible, and if so, how can I achieve this? https://i.sstatic.net/ZG4r8.png Here is the HTML code snippet: Date From : <input type="text" ...

Determine the combined height of the initial group of elements using jQuery

Is there a way to calculate the total height of the first three elements with the "latest" class in my Angular directive using the Ticker jQuery plugin? <div class="myWrapper" ticker> <div> <div ng-repeat="latest in latests" class="late ...

Angular JS has the capability to toggle the visibility of elements on a per-item basis as well as

I have created a repeater that displays a headline and description for each item. I implemented a checkbox to hide all descriptions at once, which worked perfectly. However, I also wanted to allow users to hide or show each description individually. I almo ...

Error with Laravel and Vue template integration

I have recently started using Vue in Laravel 5.3 and I am able to retrieve data through a jQuery AJAX request within Vue. However, I am facing difficulties with displaying the data. Below is my current script in the view: <li> <!-- inner men ...

Adding a clickable button to execute code within a LeafletJS marker!

I'm currently experimenting with adding a button inside a pointer that will log a message to the console. This is simply a test to see if I can execute a method on the marker, but so far I haven't been able to display any text. const marker = L.m ...