Skip to content

Commit f46dcb4

Browse files
committed
1 parent c0595a2 commit f46dcb4

File tree

5 files changed

+36
-9
lines changed

5 files changed

+36
-9
lines changed

__tests__/dispatcher/plugin.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,13 @@ describe('dispatcher/plugin => $watch', () => {
810810
let index = 0;
811811
player.__dispatcher.videoConfig._realDomAttr.forEach(key => {
812812
if ([ 'src' ].indexOf(key) > -1) return;
813+
if (key === 'preload') {
814+
const origin = player[key];
815+
player[key] = '123';
816+
expect(fn).toHaveBeenCalledTimes(++index);
817+
expect(fn).lastCalledWith('none', origin);
818+
return;
819+
}
813820
if (isBoolean(player[key])) {
814821
player[key] = !player[key];
815822
expect(fn).toHaveBeenCalledTimes(++index);

__tests__/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,15 @@ describe('Chimee', () => {
316316
expect(player.preload).toBe('auto');
317317
expect(videoElement.preload).toBe('auto');
318318
player.preload = null;
319-
expect(player.preload).toBe('');
320-
expect(videoElement.preload).toBe('');
319+
expect(player.preload).toBe('none');
320+
expect(videoElement.preload).toBe('none');
321+
player.preload = 'metadata';
322+
expect(player.preload).toBe('metadata');
323+
expect(videoElement.preload).toBe('metadata');
324+
// need to run in browser
325+
// player.preload = '';
326+
// expect(player.preload).toBe('auto');
327+
// expect(videoElement.preload).toBe('auto');
321328
});
322329
describe('width', () => {
323330
test('player set', () => {

doc/zh-cn/chimee-api.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ const chimee = new Chimee({
221221
| crossOrigin | 是否跨域 | boolean | undefined | |
222222
| loop | 是否循环 | boolean | false | |
223223
| muted | 是否静音 | boolean | false | |
224-
| preload | 是否预加载 | boolean | undefined | |
224+
| preload | 是否预加载 | string | 'auto' | |
225225
| poster | 封面 | string | '' | |
226226
| playsInline | 是否内联 | boolean | false | 我们会为此添加 `playsinle webkit-playsinline x5-playsinline` |
227227
| xWebkitAirplay | 是否添加 `x-webkit-airplay` | boolean | false | |
@@ -683,9 +683,10 @@ const player = new Chimee({
683683
684684
### preload
685685
686-
- 类型:`string | void`
686+
- 类型:`string`
687687
- 含义:视频的预加载策略
688-
- 默认:`undefined`
688+
- 默认:`auto`
689+
- 可选项: `'auto'`, `'metadata'`, `'none'`, `''`
689690
690691
### poster
691692

doc/zh-cn/plugin-api.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -765,9 +765,10 @@ const player = new Chimee({
765765

766766
### preload
767767

768-
- 类型:`string | void`
768+
- 类型:`string`
769769
- 含义:视频的预加载策略
770-
- 默认:`undefined`
770+
- 默认:`auto`
771+
- 可选项: `'auto'`, `'metadata'`, `'none'`, `''`
771772

772773
### poster
773774

@@ -1271,7 +1272,7 @@ player.$del(test, 'bar'); // {foo: 2}, {foo: 2}
12711272
| crossOrigin | 是否跨域 | boolean | undefined | |
12721273
| loop | 是否循环 | boolean | false | |
12731274
| muted | 是否静音 | boolean | false | |
1274-
| preload | 是否预加载 | boolean | auto | |
1275+
| preload | 是否预加载 | string | auto | |
12751276
| poster | 封面 | string | '' | |
12761277
| playsInline | 是否内联 | boolean | false | 我们会为此添加 `playsinle webkit-playsinline x5-playsinline` |
12771278
| xWebkitAirplay | 是否添加 `x-webkit-airplay` | boolean | false | |

src/config/video.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ function accessorVideoAttribute(attribute: string | {set: string, get: string, i
4747
this.dom.setAttr('video', set, val);
4848
return value;
4949
},
50+
}, {
51+
preSet: false,
5052
});
5153
}
5254

@@ -151,7 +153,16 @@ const accessorMap = {
151153
accessorVideoProperty('muted'),
152154
],
153155
preload: [
154-
accessor({ set: stringOrVoid }),
156+
accessor({
157+
set(value) {
158+
const options = [ 'none', 'auto', 'metadata', '' ];
159+
return options.indexOf(value) > -1
160+
? value
161+
: 'none';
162+
},
163+
}, {
164+
preSet: true,
165+
}),
155166
accessorVideoAttribute('preload'),
156167
],
157168
poster: [

0 commit comments

Comments
 (0)