Blame view

node_modules/videojs-contrib-hls/test/playback.test.js 1.79 KB
2a09d1a4   liuqimichale   添加宜春 天水 宣化
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
  import QUnit from 'qunit';
  import videojs from 'video.js';
  /* eslint-disable no-unused-vars */
  import { Hls } from '../src/videojs-contrib-hls';
  
  let when = function(element, type, cb, condition) {
    element.on(type, function func() {
      if (condition()) {
        element.off(type, func);
        cb();
      }
    });
  };
  
  let playFor = function(player, time, cb) {
    let targetTime = player.currentTime() + time;
  
    when(player, 'timeupdate', cb, () => player.currentTime() >= targetTime);
  };
  
  QUnit.module('Playback', {
    beforeEach(assert) {
      let done = assert.async();
      let video = document.createElement('video');
  
      video.width = 600;
      video.height = 300;
      document.querySelector('#qunit-fixture').appendChild(video);
      this.player = videojs(video);
      this.player.muted(true);
      this.player.ready(done);
    }
  });
  
  QUnit.test('Advanced Bip Bop', function(assert) {
    let done = assert.async();
  
    assert.expect(2);
    let player = this.player;
  
    player.autoplay(true);
  
    playFor(player, 2, function() {
      assert.ok(true, 'played for at least two seconds');
      assert.equal(player.error(), null, 'has no player errors');
  
      done();
    });
  
    player.src({
      src: 'http://d2zihajmogu5jn.cloudfront.net/bipbop-advanced/bipbop_16x9_variant.m3u8',
      type: 'application/x-mpegURL'
    });
  });
  
  QUnit.test('Advanced Bip Bop preload=none', function(assert) {
    let done = assert.async();
  
    assert.expect(2);
    let player = this.player;
  
    player.autoplay(true);
    player.preload('none');
  
    playFor(player, 2, function() {
      assert.ok(true, 'played for at least two seconds');
      assert.equal(player.error(), null, 'has no player errors');
  
      done();
    });
  
    player.src({
      src: 'http://d2zihajmogu5jn.cloudfront.net/bipbop-advanced/bipbop_16x9_variant.m3u8',
      type: 'application/x-mpegURL'
    });
  });