1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743
| <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Video element</title>
<style type="text/css">
body {
background-color:gray;
}
#v1{
z-index:1;
display:block;
height:100%;
width:100%;
background:purple;
}
.bloc-interactif{
position:absolute;
z-index: 5;
background-color: blue;
opacity:0.5;
cursor:pointer;
}
#d_conteneur{
width:700px;
}
#d_conteneur:-webkit-full-screen{
height:100%;
width:100%;
}
#d_conteneur:-moz-full-screen{
height:100%;
width:100%;
}
#d_conteneur:-ms-fullscreen{
height:100%;
width:100%;
}
#d_conteneur:fullscreen{
height:100%;
width:100%;
}
#commande{
position:absolute;
bottom:0px;
height:50px;
width:100%;
background:#2C2B2B;
opacity:0;
}
#commande:hover{
opacity:1;
}
#commande input{
width:60px;
height:20px;
margin-left:10px;
color:white;
border:solid;
border-width:1px;
border-color:white;
border-radius:8px;
background-color:#56555A;
float:left;
}
#defile{
background-color:#6A665B;
width:100%;
margin:auto;
margin-bottom:12px;
}
#precharge{
background-color:#0D0D0D;;
width:0px;
height:12px;
}
#bar{
background-color:white;
width:12px;
height:12px;
margin-top:-12px;
}
.mt_le_son{
height:14px;
border-radius:7px;
width:60px;
background:white;
margin-right:30px;
margin-top:0px;
float:right;
cursor:pointer
}
.cur_son{
height:14px;
border-radius:5px;
width:100%;
background:#6A665B;
}
.bt_p_ecran{
height:20px;
width:20px;
background:blue;
float:right;
margin-top:0px;
margin-right:10px;
}
.tmp{
display:block;
margin-top:0px;
float:right;
margin-right:15px;
color:white;
}
#infos1{
width:40%;
margin-left: 50%;
height :30%;
bottom:10px;
font-size:35px;
position:absolute;
color:white;
opacity:1;
}
#infos2{
width: 95%;
margin-left:2.5%;
z-index:10;
bottom: 34px;
position: absolute;
opacity:0.8;
}
</style>
</head>
<body>
<div id='d_conteneur' style='position:relative;margin:auto;'>
<video id="v1"
onprogress="precharge(event)"
onclick="marchearret()">
<source src='mavideo.mp4' type="video/mp4">
</video>
<div id='commande'>
<div id='defile' onmousedown="ajoutevent(event)">
<div id='precharge'></div>
<div id='bar'></div>
</div>
<div style='margin:auto'>
<input type='button' value='play' onclick='marchearret(this)' id='ma'/>
<input type
<input type='button' value='mute' onclick='mute(this)'/>
<div class='bt_p_ecran' onclick='full()'></div>
<span class='tmp' id="temp" onclick='sens_t()'>00:00</span>
<div onmousedown='event_son(event)' id='mt_le_son' class='mt_le_son'>
<div class='cur_son'></div>
</div>
</div>
</div>
<div style='position:absolute;top:38%;left:10%;margin:auto;height:25%;width:80%;display:none;opacity:0.8' id='lien'>
<div style='display:inline-block;height:100%;width:20%;background:gray;margin-left:10%;text-align:center;'>video 1</div>
<div style='display:inline-block;height:100%;width:20%;background:gray;margin-left:10%;text-align:center'>video 2</div>
<div style='display:inline-block;height:100%;width:20%;background:gray;margin-left:10%;text-align:center;'>video 3</div>
</div>
</div>
<script>
var inter_video;
var sens_temp=0;
var etat_pause=0
var hauteurvideo=0;
var largeurvideo=0;
var ratiovideo=0;
var container = document.getElementById("d_conteneur");
var eleme=document.getElementById('v1');
var lui=document.getElementById('ma');
var time=0;
var hauteurbloc=0;
var i=0;
//récup des hauteurs largeurs d'origine du container
var hauteur=container.offsetHeight;
var largeur=container.offsetWidth;
//taille de l'écran
var hauteurecran=screen.height;
var largeurecran=screen.width;
//Attente du chargement et récupération taille de la vidéo
document.getElementById("v1").onloadeddata = function() {
hauteurvideo=document.getElementById("v1").videoHeight;
largeurvideo=document.getElementById("v1").videoWidth;
ratiovideo=largeurvideo/hauteurvideo;
}
// création de la div bloc
var bloc1 = document.createElement("div");
bloc1.id = 'bloc';
bloc1.style.border = '1px solid black';
bloc1.className = "bloc-interactif";
bloc1.style.top ='164'+"px";
bloc1.style.left ='215'+"px";
bloc1.style.height ='90'+"px";
bloc1.style.width ='320'+"px";
container.appendChild(bloc1);
// passage en variable des éléments de la div créée
var hauteurbloc=bloc1.offsetHeight;
var largeurbloc=bloc1.offsetWidth;
var ratiobloc=largeurbloc/hauteurbloc;
var pos_left=bloc1.offsetLeft;
var pos_top=bloc1.offsetTop;
var hauteurblocmouv=bloc1.offsetHeight;
var largeurblocmouv=bloc1.offsetWidth;
var pos_leftmouv=bloc1.offsetLeft;
var pos_topmouv=bloc1.offsetTop;
// calcul du ratio du bloc par rapport à la div container de la video
var ratiobloc_l=largeurbloc/largeur;
var infos1 = document.createElement("div");
infos1.id = 'infos1';
infos1.innerHTML = "infos";
var infos2 = document.createElement("div");
infos2.id = 'infos2';
infos2.innerHTML='<iframe id="myFrame" src="https://fr.wikipedia.org/" style="width:100%"></iframe>';
// Affichage d'un titre lors du paasge de la souris sur la zone sensible
bloc1.addEventListener("mouseover",function(){
container.appendChild(infos1);
container.style.cursor="help";
}
);
bloc1.addEventListener("mouseout",function(){
container.removeChild(infos1);
container.style.cursor="initial";
}
);
// mets la video en pause et crée la DIV d'inforamtion
bloc1.addEventListener("click",function(){
if(eleme.paused==true){
eleme.play();
lui.value="pause";
etat_pause=0;
inter_video=setInterval(posivi,100);
if(document.getElementById("infos2")!=null){
container.removeChild(infos2);
}}
else{
etat_pause=1;
eleme.pause();
lui.value="play";
clearInterval(inter_video);
container.appendChild(infos2);
}
container.style.cursor="initial";
}
);
// la fonction est appelée sans détection de redimensionnement
eleme.ontimeupdate = function() {defilement(); };
// si on resize la feneêtre
window.addEventListener("resize", function(){
resize();
eleme.ontimeupdate = function() { defilement(); };
});
// permet de lire la video avec la barre esapce
document.addEventListener("keydown", function(e) {
if (e.keyCode == 32) {
marchearret();
event.preventDefault()
}
}, false);
// ************************************************************************************
// FONCTIONS
// -***********************************************************************************
function defilement() {
// if (time>43){
// if(bloc1!=null)container.removeChild(bloc1);
// }
// else container.appendChild(bloc1);
if((time<12)&&(time>0)){
bloc1.style.height=100+"px";
bloc1.style.top=pos_top;
bloc1.style.left=pos_left;
bloc1.style.width=largeurbloc;
bloc1.style.backgroundColor="red";
resize();
}
if(time>=12){
i=1;
bloc1.style.left=226+"px";
bloc1.style.width=350+"px";
resize();
}
if(time>=19){
i=1
bloc1.style.width=420+"px";
bloc1.style.WebkitTransform ="rotate(3deg)";
resize();
}
if(time>=26){
bloc1.style.left=255+"px";
bloc1.style.width=500+"px";
bloc1.style.WebkitTransform ="rotate(3deg)";
resize();
}
if(time>=39){
bloc1.style.WebkitTransform ="rotate(10deg)";
resize();
}
// else{
// bloc1.style.WebkitTransform ="rotate(0deg)";
// }
hauteurblocmouv=bloc1.offsetHeight;
largeurblocmouv=bloc1.offsetWidth;
pos_leftmouv=bloc1.offsetLeft;
pos_topmouv=bloc1.offsetTop;
}
function resize(){
var nouvelle_hauteur_container=container.offsetHeight;
var nouvelle_largeur_container=container.offsetWidth;
// si on agrandit
if((nouvelle_hauteur_container>hauteur)){
// calcul du pourcentage d'agrandissement
var nouvoratio_l=nouvelle_largeur_container/largeur;
var nouvoratio_h=nouvelle_hauteur_container/hauteur;
// var nouvoratio_h=nouvelle_largeur_container/ratiobloc;
// calcul des dimensions du bloc
var nouvo_l_block=largeurblocmouv*nouvoratio_l;
var nouvo_h_block=nouvo_l_block/ratiobloc;// calcul par le ratio pour éviter une erreur si la vidéo n'occupe pas toute la hauteur
var nouvo_pos_top=(pos_topmouv*nouvoratio_h)-35;// affectation de -35 ?? pour caler
var nouvo_pos_left=pos_leftmouv*nouvoratio_l;
bloc1.style.width=(nouvo_l_block)+"px";
bloc1.style.height=(nouvo_h_block)+"px";
bloc1.style.top=nouvo_pos_top+"px";
bloc1.style.left=nouvo_pos_left+"px";
i++;
}
//si on diminue
else{
bloc1.style.top=pos_top+"px";
bloc1.style.left=pos_left+"px";
bloc1.style.width=largeurbloc+"px";
bloc1.style.height=hauteurbloc+"px";
}
}
function ajoutevent(e){
e.preventDefault() //evite la selection d'element dans le document
if(document.getElementById('v1').paused){
etat_pause=1
}
document.getElementById('v1').pause();
clearInterval(inter_video);
document.documentElement.addEventListener("mousemove", curent, false);
document.documentElement.addEventListener("mouseup", retireevent, false);
curent(e);
}
function retireevent(){
etat_pause==0 ? document.getElementById('v1').play() : null;
inter_video=setInterval(posivi,60);
document.documentElement.removeEventListener("mousemove", curent, false);
document.documentElement.removeEventListener("mouseup", retireevent, false);
}
function curent(e){
var setX =e.clientX;
var distance=document.getElementById("defile").offsetWidth-document.getElementById("bar").offsetWidth; //distance reel de la barre de defilement
var valeur=(setX-document.getElementById("defile").offsetLeft-document.getElementById("bar").offsetWidth-container.offsetLeft); //position du curseur de la sourie dans la barre de defilement
valeur=valeur/distance; //valeur comprise entre 0 et 1
if(valeur>=1){
document.getElementById('v1').currentTime=document.getElementById('v1').duration*0.99999; //conversion par rapport a la video
document.getElementById("bar").style.marginLeft=distance+"px";
}
else if(valeur<0){
document.getElementById('v1').currentTime=0; //conversion par rapport a la video
document.getElementById("bar").style.marginLeft=0+"px";
}
else{
document.getElementById('v1').currentTime=document.getElementById('v1').duration*valeur; //conversion par rapport a la video
document.getElementById("bar").style.marginLeft=(distance*valeur)+"px";
}
tmp();
}
function posivi(){
var valeur=(document.getElementById('v1').currentTime/document.getElementById('v1').duration).toFixed(6); //retourne une valeur compris entre 0 et 1
var distance=document.getElementById("defile").offsetWidth-document.getElementById("bar").offsetWidth; //la distance total a parcourir de la barre
document.getElementById("bar").style.marginLeft=(distance*valeur)+"px";
tmp();
if(valeur>=1){
document.getElementById('v1').pause();
document.getElementById('lien').style.display='block';
}
}
function tmp(){
var vivi=document.getElementById('v1');
var dura=(sens_temp==0 ? vivi.currentTime : vivi.duration-vivi.currentTime);
dura=dura*25
time=dura;
var sec = Math.floor(dura /25 );
if (sec < 10) {
sec = '0' + sec;
}
var fr = Math.floor(dura % 25);
if (fr < 10) {
fr = '0' + fr;
}
var min = Math.floor(sec / 60);
if (min < 10) {
min = '0' + min;
}
document.getElementById('temp').firstChild.nodeValue=min+ ':'+sec+ ':'+fr;
}
function sens_t(){
sens_temp=sens_temp==0 ? 1 : 0;
}
function precharge(evt){
var elem=evt.currentTarget;
if(evt.lengthComputable && evt.total) {
var valeur=(evt.loaded/evt.total); //retourne une valeur compris entre 0 et 1
}
else if(elem.buffered && elem.buffered.length>0){
var charge=elem.buffered.end(0);
var valeur=(charge/elem.duration).toFixed(2); //retourne une valeur compris entre 0 et 1
}
document.getElementById('precharge').style.width=(valeur*document.getElementById("defile").offsetWidth)+'px';
}
function marchearret(){
var elem=document.getElementById('v1');
var lui=document.getElementById('ma');
if(elem.paused==true){
elem.play();
lui.value="pause";
etat_pause=0;
inter_video=setInterval(posivi,100);
}
else{
etat_pause=1;
elem.pause();
lui.value="play";
clearInterval(inter_video);
}
document.getElementById('lien').style.display='none'
}
function mute(){
var elem=document.getElementById('v1');
elem.muted==true ? elem.muted=false : elem.muted=true;
}
function monte_le_son(e){
var elem=document.getElementById('mt_le_son');
var setX =e.clientX;
var taille=elem.offsetWidth
var position=elem.offsetLeft
var position=setX-position
var distance=position/taille
if(distance>1){
document.getElementById('v1').volume=1;
elem.getElementsByTagName('div')[0].style.width=taille+'px';
}
else if(distance<0){
document.getElementById('v1').volume=0;
elem.getElementsByTagName('div')[0].style.width=0+'px';
}
else{
elem.getElementsByTagName('div')[0].style.width=distance.toFixed(1)*taille+'px'
document.getElementById('v1').volume=distance.toFixed(1);
}
}
function event_son(e){
e.preventDefault(); //evite la selection d'element dans le document
monte_le_son(e)
document.documentElement.addEventListener("mousemove", monte_le_son, false);
document.documentElement.addEventListener("mouseup", no_event_son, false);
}
function no_event_son(){
document.documentElement.removeEventListener("mousemove", monte_le_son, false);
document.documentElement.removeEventListener("mouseup", no_event_son, false);
}
function full(){ //fonction pour le plein ecran
if (!document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFullScreenElement) {
if (container.mozRequestFullScreen) {
container.mozRequestFullScreen();
}
else if (container.webkitRequestFullscreen) {
container.webkitRequestFullScreen();
}
else if (container.msRequestFullscreen) {
container.msRequestFullscreen();
}
else if (container.requestFullScreen) {
container.requestFullScreen();
}
}
else {
if (document.webkitFullscreenElement) {
document.webkitCancelFullScreen();
}
if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
}
if (document.msExitFullscreen) {
document.msExitFullscreen();
}
if (document.fullscreenElement) {
document.cancelFullScreen();
}
if (document.exitFullscreen) {
document.exitFullscreen();
}
}
document.getElementById('precharge').style.width='100%';
}
</script>
</body>
</html> |
Partager