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
| import {
| invokeMethod,
| getCurrentPageVm
| } from '../../platform'
|
| const RATES = [0.5, 0.8, 1.0, 1.25, 1.5, 2.0]
|
| function operateVideoPlayer (videoId, pageVm, type, data) {
| invokeMethod('operateVideoPlayer', videoId, pageVm, type, data)
| }
|
| export class VideoContext {
| constructor (id, pageVm) {
| this.id = id
| this.pageVm = pageVm
| }
|
| play () {
| operateVideoPlayer(this.id, this.pageVm, 'play')
| }
|
| pause () {
| operateVideoPlayer(this.id, this.pageVm, 'pause')
| }
|
| stop () {
| operateVideoPlayer(this.id, this.pageVm, 'stop')
| }
|
| seek (position) {
| operateVideoPlayer(this.id, this.pageVm, 'seek', {
| position
| })
| }
|
| sendDanmu (args) {
| operateVideoPlayer(this.id, this.pageVm, 'sendDanmu', args)
| }
|
| playbackRate (rate) {
| if (!~RATES.indexOf(rate)) {
| rate = 1.0
| }
| operateVideoPlayer(this.id, this.pageVm, 'playbackRate', {
| rate
| })
| }
|
| requestFullScreen (args = {}) {
| operateVideoPlayer(this.id, this.pageVm, 'requestFullScreen', args)
| }
|
| exitFullScreen () {
| operateVideoPlayer(this.id, this.pageVm, 'exitFullScreen')
| }
|
| showStatusBar () {
| operateVideoPlayer(this.id, this.pageVm, 'showStatusBar')
| }
|
| hideStatusBar () {
| operateVideoPlayer(this.id, this.pageVm, 'hideStatusBar')
| }
| }
|
| export function createVideoContext (id, context) {
| if (context) {
| return new VideoContext(id, context)
| }
| return new VideoContext(id, getCurrentPageVm('createVideoContext'))
| }
|
|