开发者

Changing YT video on jQuery timer expiration. How to change if page is refreshed

I'm trying to have a timer count down to a certain time. At that time I want the YouTube video to switch. This much I've gotten. The problem is when you refresh after the expiretime the page loads the original video instead of the new video.

My Current html looks like this

Pastebin Link This countsdown to +8 seconds and works fine. If I change that to a certain time it also works.. but then is when the refresh problem occurs.

$(function () {
        $('#switchtimer').countdown({
                alwaysExpire: true,         // run "change_video" if time has already expired when you load
                until: expire_date,             // timer counts down to expire_date
                onExpiry: change_video,         // when timer hits 0; run "change_video"
                });
});

The issue seems to be with the alwaysExpire: true,

As per the documentation:

On expiry a callback is made to allow you to action the countdown. You can force this event to fire even if the countdown starts after the target time by setting alwaysExpire to true.

and:

Name - alwaysExpire

Type - boolean

Default - false

Comment - If true, the onExpiry event is triggered even when the counter starts after the target time. If false, the event only triggers if the counter actively times out.

I've tried rearranging the order it doesn't matter. I've tried true and false no luck. I've triple checked my spelling, I even tried replacing alwaysExpire: true, with alwaysExpire = true and still nothing. well actually that last one broke everything all together.

it also occurs to me to wonder if the problem might be my switching code but as I said that actually works.. as long as the page is actually loaded when the timer expires.

      function change_video() {
       开发者_StackOverflow     ytid = next_vid
            player.cueVideoById(ytid);
        }

Ref: Timer by Keith Wood


Well looking at your HTML it is pretty normal that you having that issue since you are not giving it a way to remember what was the last video played. At load time the page always get initiated with this video: var ytid = "CD2LRROpph0"; and you also have nextvid hardcoded. A way to approach this is to store the current video being played in a cookie, when page loads read from that cookie first the value of the video, if it is empty (the user has never been on this page) then feed it the default value. You could also store all your videos ids in an array for future scalability. Let me know if you need help with the actual cookie code, but this should get you going. Hope it helps. Cheers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜