Skip to content

Commit 94ed2df

Browse files
authored
Merge pull request #44 from core-player/mobile
Mobile Browser Support
2 parents a473482 + 56a1dc3 commit 94ed2df

File tree

14 files changed

+301
-40
lines changed

14 files changed

+301
-40
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-core-video-player",
3-
"version": "0.1.12",
3+
"version": "0.2.0",
44
"scripts": {
55
"dev": "vue-cli-service serve",
66
"build": "vue-cli-service build --target lib ./src/index.js",

src/App.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,11 @@ export default {
7979
position: relative;
8080
margin: 80px auto;
8181
}
82+
83+
@media all and (max-width: 768px) {
84+
#app .test-player-wrap {
85+
width: 100%;
86+
height: auto;
87+
}
88+
}
8289
</style>

src/core/base.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,18 @@ class BaseVideoCore {
9292
this.checkSource(this.config.src)
9393
this._autoRegisterEvents()
9494
this._setVideoAttr()
95+
this.setContainer()
9596
this.setSize()
9697
this.emit(EVENTS.LIFECYCLE_INITED)
9798
this._autoplay()
9899
}
99100

101+
setContainer () {
102+
if (isMobile) {
103+
addClass(this.$el, 'mobile')
104+
}
105+
}
106+
100107
setSize () {
101108
const width = this.$el.offsetWidth
102109
let size = ''

src/dashboard/fullscreen.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div class="vue-core-video-player-control">
2+
<div v-if="!disable" class="vue-core-video-player-control">
33
<div v-if="!fullscreen" class="btn-control btn-fullscreen" @click="enterFullscreen">
44
<svg xmlns="http://www.w3.org/2000/svg" width="28" height="20" viewBox="0 0 28 20"><g fill="#fff"><g data-name="6 7"><g data-name="4 1"><path data-name="7" d="M16 0h10v2H16z"/><path data-name="8" d="M26 0h2v6h-2z"/></g><g data-name="5 1"><path data-name="9" d="M18 18h10v2H18z"/><path data-name="10" d="M26 14h2v6h-2z"/></g></g><g data-name="6 8"><g data-name="4 1"><path data-name="7" d="M12 20H2v-2h10z"/><path data-name="8" d="M2 20H0v-6h2z"/></g><g data-name="5 1"><path data-name="9" d="M10 2H0V0h10z"/><path data-name="10" d="M2 6H0V0h2z"/></g></g></g></svg>
55
<div class="tips">{{$t('dashboard.btn.fullscreen')}}</div>
@@ -14,12 +14,18 @@
1414
<script>
1515
// import EVENTS from '../constants/EVENTS'
1616
import coreMixins from '../mixins'
17+
import { isMobile, isApple } from '../helper/util'
1718
1819
export default {
1920
name: 'Fullscreen',
2021
mixins: [coreMixins],
2122
props: {
2223
visible: Boolean
24+
},
25+
data () {
26+
return {
27+
disable: (isMobile && isApple)
28+
}
2329
}
2430
}
2531
</script>

src/dashboard/mobile-controls.vue

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<template>
2+
<div class="vcp-controls">
3+
<div class="playback-control">
4+
<time-span />
5+
</div>
6+
<div class="setting-control">
7+
<picture-in-picture />
8+
<settings-control />
9+
<fullscreen-control />
10+
</div>
11+
</div>
12+
</template>
13+
14+
<script>
15+
import TimeSpan from './time-span'
16+
import Fullscreen from './fullscreen'
17+
import Settings from './settings'
18+
import PictureInPicture from './picture-in-picture'
19+
20+
export default {
21+
name: 'Controls',
22+
components: {
23+
'time-span': TimeSpan,
24+
'fullscreen-control': Fullscreen,
25+
'settings-control': Settings,
26+
'picture-in-picture': PictureInPicture
27+
},
28+
props: {
29+
visible: Boolean,
30+
muted: Boolean
31+
}
32+
}
33+
</script>
34+
35+
<style land="less">
36+
.vcp-controls {
37+
z-index: 10;
38+
position: absolute;
39+
left: 0;
40+
bottom: 5px;
41+
width: 100%;
42+
height: 50px;
43+
text-align: left;
44+
}
45+
46+
.playback-control,
47+
.setting-control{
48+
display: flex;
49+
position: absolute;
50+
top: 0;
51+
height: 100%;
52+
text-align: center;
53+
justify-content: center;
54+
align-items: center;
55+
}
56+
.playback-control {
57+
left: 0;
58+
}
59+
.setting-control{
60+
right: 0;
61+
}
62+
</style>

src/dashboard/mobile-dashboard.vue

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
<template>
2+
<div class="vcp-m-dashboard" autoplay v-show="show" ref="dashboard">
3+
<MobileControls :muted="muted" />
4+
<Progress />
5+
</div>
6+
</template>
7+
8+
<script>
9+
import { DEFAULT_CONFIG, EVENTS } from '../constants'
10+
import { isDescendant } from '../helper/dom'
11+
import { isMobile } from '../helper/util'
12+
import Progress from './progress'
13+
import MobileControls from './mobile-controls'
14+
import coreMixins from '../mixins'
15+
16+
const pageCoor = {
17+
x: null,
18+
y: null
19+
}
20+
21+
export default {
22+
name: 'MobileDashboard',
23+
components: {
24+
Progress,
25+
MobileControls
26+
},
27+
props: {
28+
controls: [Boolean, String],
29+
muted: Boolean
30+
},
31+
data () {
32+
return {
33+
show: true
34+
}
35+
},
36+
mixins: [coreMixins],
37+
methods: {
38+
showDashboard (delay) {
39+
window.clearTimeout(this._hideTimeout)
40+
this.show = true
41+
this.emit(EVENTS.UI_DASHBOARD_SHOW)
42+
if (delay === 0) {
43+
// TODO handle force show
44+
} else {
45+
this._hideTimeout = setTimeout(() => {
46+
this.hideDashboard()
47+
}, delay || DEFAULT_CONFIG.dashboardHideDelay)
48+
}
49+
},
50+
hideDashboard () {
51+
this.show = false
52+
this.emit(EVENTS.UI_DASHBOARD_HIDE)
53+
},
54+
_initAutoMode () {
55+
const $parent = this.$refs['dashboard'].parentNode
56+
if (isMobile) {
57+
$parent.addEventListener('touchend', this._onTouchend.bind(this), true)
58+
} else {
59+
$parent.addEventListener('mousemove', this._onMousemove.bind(this))
60+
$parent.addEventListener('mouseleave', this._onMouseleave.bind(this))
61+
$parent.addEventListener('mouseover', this._onMouseover.bind(this), true)
62+
}
63+
// first render delay
64+
this.showDashboard(4000)
65+
},
66+
_onMousemove (e) {
67+
if (e.pageX === pageCoor.x && e.pageY === pageCoor.y) {
68+
pageCoor.x = e.pageX
69+
pageCoor.y = e.pageY
70+
return
71+
}
72+
pageCoor.x = e.pageX
73+
pageCoor.y = e.pageY
74+
if (isDescendant(this._el, e.target)) {
75+
return this.showDashboard(0)
76+
}
77+
this.showDashboard()
78+
},
79+
80+
_onMouseleave () {
81+
this.showDashboard()
82+
},
83+
_onMouseover () {
84+
this.showDashboard(0)
85+
},
86+
_onTouchend () {
87+
this.showDashboard()
88+
}
89+
},
90+
mounted () {
91+
const { controls } = this
92+
if (!controls) {
93+
this.show = false
94+
} else if (controls === 'fixed') {
95+
this.show = true
96+
} else {
97+
this._initAutoMode()
98+
}
99+
}
100+
}
101+
</script>
102+
103+
<style>
104+
.vcp-m-dashboard {
105+
z-index: 11;
106+
position: absolute;
107+
left: 0;
108+
bottom: 0;
109+
width: 100%;
110+
height: 59px;
111+
background: linear-gradient(to top ,rgba(0,0,0, .7), rgba(0,0,0, 0));
112+
}
113+
.fullscreen .vcp-m-dashboard {
114+
bottom: 12px;
115+
}
116+
.small .vcp-m-dashboard{
117+
height: 49px;
118+
}
119+
.settings-open .vcp-m-dashboard {
120+
display: block !important;
121+
}
122+
.small .vcp-m-dashboard .vcp-controls {
123+
height: 40px;
124+
}
125+
</style>

src/dashboard/progress.vue

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,19 @@ export default {
191191
}
192192
}
193193
}
194+
.vcp-m-dashboard .vcp-progress-hover {
195+
bottom: 0px;
196+
.vcp-progress {
197+
height: 3px;
198+
}
199+
.vcp-progress-played{
200+
.thumb-drag{
201+
background-color: #ff6060;
202+
&:before{
203+
background-color: #ff6060;
204+
opacity: 0.25;
205+
}
206+
}
207+
}
208+
}
194209
</style>

src/dashboard/settings.vue

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,20 @@ export default {
195195
}
196196
}
197197
}
198+
.vcp-m-dashboard .settings-control .btn-control-panel {
199+
z-index: 20000;
200+
position: fixed;
201+
left: 0px;
202+
right: 0px;
203+
bottom: 0px;
204+
.current-panel {
205+
width: 100%;
206+
}
207+
.speed-list {
208+
margin-left: 20px;
209+
}
210+
.resolution-list {
211+
margin-left: 20px;
212+
}
213+
}
198214
</style>

src/helper/dom.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function toggle (el, className) {
1515
}
1616
};
1717

18-
export function swichChildClass (el, childSelector, className, tellFunc) {
18+
export function switchChildClass (el, childSelector, className, tellFunc) {
1919
const children = el.querySelectorAll(childSelector)
2020
for (let i = 0; i < children.length; i++) {
2121
const item = children[i]

src/helper/util.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,23 +198,23 @@ export const isMSESupported = () => {
198198
}
199199

200200
export function isDebug () {
201-
return localStorage.__vrplayer_core
201+
return localStorage._vcpDebug
202202
}
203203

204204
export function setDebug (value) {
205205
if (value) {
206-
localStorage.__vrplayer_debug = true
206+
localStorage._vcpDebug = true
207207
} else {
208-
localStorage.__vrplayer_debug = ''
208+
localStorage._vcpDebug = ''
209209
}
210210
}
211211
export const isNodeEnv = () => {
212212
return typeof localStorage !== 'object' && typeof navigator !== 'object'
213213
}
214214

215-
export const isMobile = isMobileJS.any
216-
export const isAndroid = isMobileJS.android
217-
export const isApple = isMobileJS.apple && isMobileJS.apple.device
215+
export const isMobile = isMobileJS(ua).any
216+
export const isAndroid = isMobileJS(ua).android
217+
export const isApple = isMobileJS(ua).apple && isMobileJS(ua).apple.device
218218
export const isSafari = isApple && _isSafari()
219219
export const isTencentGroup = /MQQBrowser/i.test(ua)
220220
export const isUC = /ucbrowser/i.test(ua)

0 commit comments

Comments
 (0)