JavaScript Looping through Video Sources slows Chrome loop through video output,loop through video,python loop through

I have two video sources that are outputted to my page via ajax (the second is hidden). I play the first one and bind an event onto it so that when it has ended the next video is played and shown whilst the first is then paused, rewinded back to 0, and the process continues.

here is my code.

function queueVideos(num, amount) {

    if (num < amount) {
        document.getElementById('video-element-'+num).addEventListener('ended', playNextClip, false);
        function playNextClip() {
            var nextVid = num + 1;
            $( '#video-element-' + nextVid ).show().get(0).play();
            $( '#video-element-' + num ).hide();
            document.getElementById( 'video-element-' + num ).pause();
            document.getElementById( 'video-element-' + num ).currentTime = 0;
            queueVideos(nextVid, amount)
        }
    }

    if (num == amount) {
        document.getElementById('video-element-'+num).addEventListener('ended', playFirst, false);
        function playFirst() {
            $( '#video-element-1' ).show().get(0).play();
            $( '#video-element-' + num ).hide();
            document.getElementById( 'video-element-' + num ).pause();
            document.getElementById( 'video-element-' + num ).currentTime = 0;
            queueVideos(1, amount);
        }
    }

}

The code is called within an ajax function that feeds it the num and amount from data i get elsewhere, for arguments sake let's say i'm running it like so:

queueVideos(1, 2);

My problem is that after around 1 minute the transitions between the clips get laggy, the clips pause unexpectedly, and ultimately the browser (chrome) performs slowly.

How can I fix this?

Thanks!

Answer:1

I have an array with this loop: var arr = [5, 4, 9, 6, 4]; var sum = 0; arr.forEach(function(item) { sum += parseInt(item); console.log(sum) }); At the moment, I get ...

I have an array with this loop: var arr = [5, 4, 9, 6, 4]; var sum = 0; arr.forEach(function(item) { sum += parseInt(item); console.log(sum) }); At the moment, I get ...

  1. execute loop in postgresql
  2. execute loop in sql
  3. execute loop in cmd
  4. execute loop in shell script
  5. execute loop in oracle
  6. execute loop in r
  7. execute loop in jmeter
  8. execute for loop with delay javascript
  9. execute for loop only once python
  10. execute for loop only once
  11. execute for loop via ssh
  12. execute for loop once
  13. execute for loop
  14. execute for loop python
  15. execute in loop java
  16. execute immediate with loop

I've built a page with 3 elements, each of which looks like this: <div class="col-md-4 event-type"> <a href="{{ pathFor 'step2' }}" id="eventchoice" name="eventchoice" value="corporate"> &...

I've built a page with 3 elements, each of which looks like this: <div class="col-md-4 event-type"> <a href="{{ pathFor 'step2' }}" id="eventchoice" name="eventchoice" value="corporate"> &...

is there an elegant way to determine, whether an array like this: [ {id: 1, value: false}, {id: 2, value: true}, {id: 3, value: false}, {id: 4, value: true}, {id: 5, value: true} ] ...

is there an elegant way to determine, whether an array like this: [ {id: 1, value: false}, {id: 2, value: true}, {id: 3, value: false}, {id: 4, value: true}, {id: 5, value: true} ] ...

  1. check whether array a is a permutation
  2. check whether array is empty javascript
  3. check whether array is empty
  4. check whether array contains element javascript
  5. check whether array is empty java
  6. check whether array is empty python
  7. check whether array contains element java
  8. check whether array a is a permutation c#
  9. check whether array is sorted or not
  10. check whether array a is a permutation in java
  11. check whether array is palindrome or not
  12. check whether array contains duplicates
  13. check if array is empty javascript
  14. check if array is empty php
  15. check if array is empty
  16. check if array contains value javascript
  17. check if array is empty python
  18. check if array contains value
  19. check if array javascript
  20. check if array is empty java

I am having a problem where i'm trying to render pass an array's data to a card component but it doesn't appear on the page, the card component renders normally on its own: import React, { Component }...

I am having a problem where i'm trying to render pass an array's data to a card component but it doesn't appear on the page, the card component renders normally on its own: import React, { Component }...

  1. array does not contain
  2. array does not include javascript
  3. array does not contain javascript
  4. array does not name a type
  5. array does not contain java
  6. array does not contain a definition for cast
  7. array does not include ruby
  8. array does not contain python
  9. array does not contain a definition for empty c#
  10. array does not contain swift
  11. array does not name a type arduino
  12. array does not contain a definition for tolist
  13. array does not contain mongodb
  14. array does not name a type c++
  15. array does not contain powershell
  16. array does not contain c#
  17. array does not contain postgres
  18. array does not contain js
  19. array does not contain sql
  20. @array doesn't match its definition