Skip to content

Commit

Permalink
[update] add startload
Browse files Browse the repository at this point in the history
  • Loading branch information
toxic-johann committed Jan 17, 2018
1 parent ce33fde commit 2c22f4a
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 16 deletions.
1 change: 0 additions & 1 deletion .flowconfig
Expand Up @@ -12,6 +12,5 @@ all=warn
untyped-type-import=error
sketchy-null-bool=off
[options]
unsafe.enable_getters_and_setters=true
esproposal.decorators=ignore
[strict]
19 changes: 18 additions & 1 deletion __tests__/index.js
Expand Up @@ -125,10 +125,27 @@ describe('chimee-kernel index.js', () => {
});

test('stopLoad', () => {
videoElement.src = 'http://cdn.toxicjohann.com/lostStar.mp4';
kernel.load();
expect(videoElement.src).toBe('http://cdn.toxicjohann.com/lostStar.mp4');
kernel.seek(10);
expect(kernel.videoElement.currentTime).toBe(10);
expect(kernel.currentTime).toBe(10);
kernel.stopLoad();
expect(videoElement.src).toBe('');
});

test('startLoad', () => {
kernel.load();
expect(videoElement.src).toBe('http://cdn.toxicjohann.com/lostStar.mp4');
kernel.seek(10);
expect(kernel.videoElement.currentTime).toBe(10);
expect(kernel.currentTime).toBe(10);
kernel.stopLoad();
expect(videoElement.src).toBe('');
kernel.startLoad();
expect(videoElement.src).toBe('http://cdn.toxicjohann.com/lostStar.mp4');
expect(kernel.videoElement.currentTime).toBe(10);
expect(kernel.currentTime).toBe(10);
});

test('event listener', () => {
Expand Down
2 changes: 1 addition & 1 deletion build/rollup.config.base.js
Expand Up @@ -6,7 +6,7 @@ const { version, name, author, license, dependencies } = require('../package.jso
const banner = `
/**
* ${name} v${version}
* (c) 2017 ${author}
* (c) 2017-${(new Date().getFullYear())} ${author}
* Released under ${license}
*/
`;
Expand Down
2 changes: 1 addition & 1 deletion demo/base.js
Expand Up @@ -32,7 +32,7 @@ window.start = function() {

document.body.appendChild(srcController);

const keys = [ 'play', 'pause', 'load', 'stopLoad', 'attachMedia', 'seek', 'refresh', 'destroy' ];
const keys = [ 'play', 'pause', 'load', 'startLoad', 'stopLoad', 'attachMedia', 'seek', 'refresh', 'destroy' ];
const controller = document.createElement('div');
keys.forEach(function(key) {
const button = document.createElement('button');
Expand Down
24 changes: 12 additions & 12 deletions package.json
Expand Up @@ -41,7 +41,7 @@
},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-eslint": "^8.0.3",
"babel-eslint": "^8.2.1",
"babel-plugin-external-helpers": "^6.22.0",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-runtime": "^6.23.0",
Expand All @@ -50,22 +50,22 @@
"babel-preset-flow": "^6.23.0",
"babel-preset-latest": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"chimee-kernel-flv": "^1.4.6",
"chimee-kernel-hls": "^1.0.7",
"eslint": "^4.13.1",
"eslint-config-egg": "^5.1.1",
"eslint-plugin-flowtype": "^2.40.1",
"eslint-plugin-jest": "^21.5.0",
"flow-bin": "^0.61.0",
"chimee-kernel-flv": "^1.4.7",
"chimee-kernel-hls": "^1.1.0",
"eslint": "^4.15.0",
"eslint-config-egg": "^6.0.0",
"eslint-plugin-flowtype": "^2.41.0",
"eslint-plugin-jest": "^21.6.2",
"flow-bin": "^0.63.1",
"husky": "^0.14.3",
"jest": "^21.2.1",
"jest": "^22.1.1",
"pkg-ok": "^1.1.0",
"rollup": "^0.52.2",
"rollup-plugin-babel": "^3.0.2",
"rollup": "^0.54.0",
"rollup-plugin-babel": "^3.0.3",
"rollup-plugin-commonjs": "^8.2.6",
"rollup-plugin-includepaths": "^0.2.2",
"rollup-plugin-livereload": "^0.6.0",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-plugin-node-resolve": "^3.0.2",
"rollup-plugin-replace": "^2.0.0",
"rollup-plugin-serve": "^0.4.0",
"rollup-plugin-uglify": "^2.0.1",
Expand Down
6 changes: 6 additions & 0 deletions src/index.js
Expand Up @@ -130,6 +130,12 @@ export default class ChimeeKernel extends CustEvent {
this.videoKernel.load(src);
}

startLoad() {
/* istanbul ignore if */
if (!isFunction(this.videoKernel.startLoad)) throw new Error('This video kernel do not support startLoad, please contact us on https://github.com/Chimeejs/chimee/issues');
this.videoKernel.startLoad(this.config.src);
}

stopLoad() {
/* istanbul ignore else */
if (isFunction(this.videoKernel.stopLoad)) this.videoKernel.stopLoad();
Expand Down
12 changes: 12 additions & 0 deletions src/native/index.js
@@ -1,5 +1,8 @@
// @flow
import { CustEvent, isElement } from 'chimee-helper';

let tempCurrentTime: number = 0;

export default class NativeVideoKernel extends CustEvent {
video: HTMLVideoElement;
config: KernelConfig;
Expand All @@ -18,10 +21,19 @@ export default class NativeVideoKernel extends CustEvent {

load(src: string) {
this.video.setAttribute('src', src);
this.video.src = src;
}

startLoad(src: string) {
/* istanbul ignore next */
const currentTime = this.video.currentTime || tempCurrentTime;
this.load(src);
this.seek(currentTime);
}

// https://developer.mozilla.org/de/docs/Web/HTML/Using_HTML5_audio_and_video#Stopping_the_download_of_media
stopLoad() {
tempCurrentTime = this.video.currentTime;
this.video.src = '';
this.video.removeAttribute('src');
}
Expand Down

0 comments on commit 2c22f4a

Please sign in to comment.