Video background loop/change

This commit is contained in:
Jonathan Corwin 2010-09-11 22:40:14 +01:00
parent 02abcf24fc
commit 0d36cba0bb

View File

@ -81,17 +81,14 @@ body {
</style> </style>
<script language="javascript"> <script language="javascript">
var timer = null; var timer = null;
var video_timer = null;
var transition = %s; var transition = %s;
function show_video(state, path, volume, loop){ function show_video(state, path, volume, loop){
var vid = document.getElementById('video'); var vid = document.getElementById('video');
if(path != null) if(path != null){
vid.src = path; vid.src = path;
if(loop != null){ vid.load();
if(loop)
vid.loop = 'loop';
else
vid.loop = '';
} }
if(volume != null){ if(volume != null){
vid.volume = volume; vid.volume = volume;
@ -100,23 +97,55 @@ body {
case 'play': case 'play':
vid.play(); vid.play();
vid.style.display = 'block'; vid.style.display = 'block';
if(loop)
video_timer = setInterval('video_loop()', 200);
break; break;
case 'pause': case 'pause':
if(video_timer!=null){
clearInterval(video_timer);
video_timer = null;
}
vid.pause(); vid.pause();
vid.style.display = 'block'; vid.style.display = 'block';
break; break;
case 'stop': case 'stop':
if(video_timer!=null){
clearInterval(video_timer);
video_timer = null;
}
vid.pause(); vid.pause();
vid.style.display = 'none'; vid.style.display = 'none';
vid.load();
break; break;
case 'close': case 'close':
if(video_timer!=null){
clearInterval(video_timer);
video_timer = null;
}
vid.pause(); vid.pause();
vid.style.display = 'none'; vid.style.display = 'none';
vid.src = ''; vid.src = '';
break; break;
} }
} }
function video_loop(){
// The preferred method would be to use the video tag loop attribute
// But QtWebKit doesn't support this. Neither does it support the
// onended event, hence the setInterval()
// In addition, setting the currentTime attribute to zero to restart
// the video raises an INDEX_SIZE_ERROR: DOM Exception 1
// To complicate it further, sometimes vid.currentTime stops
// slightly short of vid.duration and vid.ended is intermittent!
//
// Note, currently the background may go black between loops. Not
// desirable. Need to investigate using two <video>'s, and hiding/
// preloading one, and toggle between the two when looping.
var vid = document.getElementById('video');
if(vid.ended||vid.currentTime+0.2>=vid.duration){
vid.load();
vid.play();
}
}
function show_image(src){ function show_image(src){
var img = document.getElementById('image'); var img = document.getElementById('image');
img.src = src; img.src = src;