<video>.currentTIme doesn't want to be set

有些话、适合烂在心里 提交于 2019-12-02 02:46:56

问题


I'm trying to write a piece of Javascript that switches between two videos at timed intervals (don't ask). To make matters worse, each video has to start at specific place (about ten seconds, and again, don't ask.)

I got the basics working by just using the YUI Async library to fire to switch the videos at intervals:

YUI().use('async-queue', function (Y) {
                        // AsyncQueue is available and ready for use.

                        var cumulativeTime = 0;
                        var q = new Y.AsyncQueue()

                        for (var x = 0; x < settings.length; x++) {

                            cumulativeTime = cumulativeTime + (settings[x].step * 1000)

                            q.add( {

                                fn: runVideo,
                                args: settings[x].mainWindow,
                                timeout: cumulativeTime
                            })
                        }

                        q.run()
                    });

So far, so good. The problem is that I can't seem to get the video to start at ten seconds in.

I'm using this code to do it:

function runVideo(videoToPlay) {

    console.log('We are going to play -> ' + videoToPlay)

    var video = document.getElementById('mainWindow')
    video.src = '/video?id=' + videoToPlay

    video.addEventListener('loadedmetadata', function() {

        this.currentTime = 10 // <-- Offending line!
        this.play();

    })
}

The problem is that this.currentTime refuses to hold any value I set it to. I'm running it through Chrome (the file is served from Google Storage behind a Google App Engine Instance) and when the debugger goes past the line, the value is always zero.

Is there some trick I'm missing in order to set this value?

Thanks in advance.

来源:https://stackoverflow.com/questions/18105160/video-currenttime-doesnt-want-to-be-set

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!