Browse Source

Add next/previous controls

Niemes 1 year ago
parent
commit
de0728b8cc
2 changed files with 14 additions and 4 deletions
  1. 1 1
      assets/css/main.css
  2. 13 3
      assets/js/player.js

+ 1 - 1
assets/css/main.css

@@ -1,4 +1,4 @@
-body {
+body , html{
     background-color: black;
     margin: 0;
     padding: 0;

+ 13 - 3
assets/js/player.js

@@ -8,6 +8,7 @@ class MainPlayer {
     constructor() {
 
         this.playlist = new Playlist()
+        this.playlistVideos = () => window.playlist.el.getElementsByTagName("li")
         this.config = {
             currentIndex: 0,
             loop: () => localStorage.getItem('loop'),
@@ -42,10 +43,19 @@ class MainPlayer {
                 }
             },
             previous: (elem) => {
-        
+                if(window.curVideo >= 0) {
+                    window.curVideo--
+                    window.videoPlayer.src = this.playlistVideos()[window.curVideo].getAttribute('path');
+                    window.videoPlayer.play()
+                }
+                
             },
             next: (elem) => {
-        
+                if(window.curVideo < this.playlistVideos().length - 1) {
+                    window.curVideo++
+                    window.videoPlayer.src = this.playlistVideos()[window.curVideo].getAttribute('path');
+                    window.videoPlayer.play()
+                }
             },
             loop: (elem, act) => {
                 let swap = act ? false : true
@@ -159,7 +169,7 @@ class MainPlayer {
             
             let self = this
             window.videoPlayer.onended = function () {
-                let playlistVideos = window.playlist.el.getElementsByTagName("li")
+                let playlistVideos = self.playlistVideos()
                 let looping = self.config.loop()
 
                 if (playlistVideos.length !== 0) {