Browse Source

New API: play(time)

DIYgod 9 years ago
parent
commit
1bc11bd62e
5 changed files with 12 additions and 8 deletions
  1. 5 3
      README.md
  2. 0 0
      dist/DPlayer.min.js
  3. 0 0
      dist/DPlayer.min.js.map
  4. 1 1
      package.json
  5. 6 4
      src/DPlayer.js

+ 5 - 3
README.md

@@ -65,9 +65,11 @@ var option = {
 
 **API**
 
-+ `dp.init()`
-+ `dp.play()`
-+ `dp.pause()`
++ `dp.init()`                       // Load player
++ `dp.play()`                       // Resume play
++ `dp.play(time)`                   // Set currentTime
++ `dp.pause()`                      // Pause
++ `ap.on(event, handler)`           // Event binding
 
 **Event binding**
 

File diff suppressed because it is too large
+ 0 - 0
dist/DPlayer.min.js


File diff suppressed because it is too large
+ 0 - 0
dist/DPlayer.min.js.map


+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "dplayer",
-  "version": "1.0.1",
+  "version": "1.0.2",
   "description": "Wow, such a lovely HTML5 danmaku video player",
   "main": "dist/DPlayer.min.js",
   "scripts": {

+ 6 - 4
src/DPlayer.js

@@ -421,8 +421,7 @@ class DPlayer {
                     let item = this.dan[this.danIndex];
                     while (item && this.audio.currentTime >= parseFloat(item.time)) {
                         this.danmakuIn(item.text, item.color, item.type);
-                        this.danIndex++;
-                        item = this.dan[this.danIndex];
+                        item = this.dan[++this.danIndex];
                     }
                 }, 0);
             }
@@ -843,12 +842,12 @@ class DPlayer {
             item.classList.add(`dplayer-danmaku-${type}`);
             item.innerHTML = text;
             item.style.opacity = this.danOpacity;
+            item.style.color = color;
 
             // insert
             danContainer.appendChild(item);
 
             // adjust
-            item.style.color = color;
             switch (type) {
                 case 'right':
                     item.style.top = itemHeight * getTunnel(item, type) + 'px';
@@ -1176,7 +1175,10 @@ class DPlayer {
     /**
      * Play music
      */
-    play() {
+    play(time) {
+        if (Object.prototype.toString.call(time) === '[object Number]') {
+            this.audio.currentTime = time;
+        }
         if (this.audio.paused) {
             this.shouldpause = false;
 

Some files were not shown because too many files changed in this diff