Multiple videos autoplay in FullPage JS not working

I have already seen many answers on here and github (well addressed by Alvaro) on enabling video autoplay in FullPage.js

However I am having issues when I have several videos, each on a different slide, that need to autoplay by default. So far with this code I have been able to only auto start the first video:

afterRender: function () {
        //playing the video
        $('video').get(0).play();
    }

As far as I understand, this function needs to work in conjunction with afterSlideLoad for this to take place, but had no luck. Has anyone had experience with autoplaying several videos on different slides/pages?

Answers


If you have multiple videos you would need to loop through them to play them. Assumming you use jQuery in your page, this should do the trick:

afterRender: function () {
    $('video').each(function () {
        //playing the video
        $(this).get(0).play();
    });
}

If you want to play each of them disparately only when the slide loads, then you would need to use afterSlideLoad as you mention and probably assign an id tag to the video so you can play each of them whenever you want, for example:

<video autoplay loop muted controls="false" id="video1">
    <source src="http://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
</video>

Notice the id="video1" in the video element. And now in the jQuery code:

afterSlideLoad: function (anchorLink, index, slideAnchor, slideIndex) {
    //for section 2 slide 2
    if (index == 2 && slideIndex == 2) {

        //playing #video1
        $('#video1').each(function () {
            //playing the video
            $('video').get(0).play();
        });
    }
}

Need Your Help

Twitterizer - Exception while GetAccessToken()

c# api twitter oauth twitterizer

my twitterizer version is 2.3.3.21964 (donwloaded from nuget).

Unable to launch App built on Mavericks

java xcode osx osx-lion osx-mavericks

I have an app for my Java Application that build on another server machine. This server machine now upgraded with Mavericks + xcode 5.1. Earlier I was facing the issue of not signing my app on server

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.