Guest User

Untitled

a guest
Jun 12th, 2012
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. var position = 0;
  2. var playlist;
  3. var video;
  4. addClickHandlers();
  5.  
  6. window.onload = function() {
  7. video = document.getElementById('video');
  8. addClickHandlers();
  9. video.src = "video/" + getFormatExtension();
  10. video.load();
  11. video.play();
  12. }
  13.  
  14. function addClickHandlers() {
  15. var liElements = document.querySelectorAll("ul#videolist li");
  16. for (var i = 0; i < liElements.length; i++) {
  17. var li = liElements[i];
  18. li.onclick = handleVideoSelection;
  19. }
  20. }
  21.  
  22. function clearAllSelections() {
  23. var liElements = document.querySelectorAll("ul#videolist li");
  24. for (var i = 0; i < liElements.length; i++) {
  25. var li = liElements[i];
  26. li.setAttribute("class", null);
  27. }
  28. }
  29.  
  30. function handleVideoSelection(e) {
  31. clearAllSelections();
  32.  
  33. e.target.setAttribute("class", "selected");
  34.  
  35. var li = e.target;
  36. var src = li.getAttribute("data-src");
  37. var isSelected = li.getAttribute("class");
  38.  
  39. if (isSelected === "selected") {
  40. if (video.paused) {
  41. video.play();
  42. }
  43. else if (video.ended) {
  44. video.load();
  45. video.play();
  46. }
  47. else {
  48. video.pause();
  49. }
  50. }
  51. else {
  52. video.src = src + getFormatExtension();
  53. video.load();
  54. video.play();
  55. }
  56. }
  57.  
  58.  
  59. function getFormatExtension() {
  60. if (video.canPlayType("video/mp4") != "") {
  61. return ".mp4";
  62. } else if (video.canPlayType("video/ogg") != "") {
  63. return ".ogg";
  64. } else if (video.canPlayType("video/webm") != "") {
  65. return ".webm";
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment