提交 0c627102 编写于 作者: fxy060608's avatar fxy060608

refactor(v3): createVideoContext

上级 efa1fd3d
......@@ -7757,74 +7757,28 @@ var serviceContext = (function () {
this.pageVm = pageVm;
}
getCenterLocation ({
success,
fail,
complete
}) {
operateMapPlayer(this.id, this.pageVm, 'getCenterLocation', {
success,
fail,
complete
});
getCenterLocation (args) {
operateMapPlayer(this.id, this.pageVm, 'getCenterLocation', args);
}
moveToLocation () {
operateMapPlayer(this.id, this.pageVm, 'moveToLocation');
}
translateMarker ({
markerId,
destination,
autoRotate,
rotate,
duration,
animationEnd,
fail
}) {
operateMapPlayer(this.id, this.pageVm, 'translateMarker', {
markerId,
destination,
autoRotate,
rotate,
duration,
animationEnd,
fail
});
translateMarker (args) {
operateMapPlayer(this.id, this.pageVm, 'translateMarker', args);
}
includePoints ({
points,
padding
}) {
operateMapPlayer(this.id, this.pageVm, 'includePoints', {
points,
padding
});
includePoints (args) {
operateMapPlayer(this.id, this.pageVm, 'includePoints', args);
}
getRegion ({
success,
fail,
complete
}) {
operateMapPlayer(this.id, this.pageVm, 'getRegion', {
success,
fail,
complete
});
getRegion (args) {
operateMapPlayer(this.id, this.pageVm, 'getRegion', args);
}
getScale ({
success,
fail,
complete
}) {
operateMapPlayer(this.id, this.pageVm, 'getScale', {
success,
fail,
complete
});
getScale (args) {
operateMapPlayer(this.id, this.pageVm, 'getScale', args);
}
}
......@@ -7839,6 +7793,68 @@ var serviceContext = (function () {
createMapContext: createMapContext$1
});
const RATES = [0.5, 0.8, 1.0, 1.25, 1.5];
function operateVideoPlayer (videoId, pageVm, type, data) {
invokeMethod('operateVideoPlayer', videoId, pageVm, type, data);
}
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 () {
operateVideoPlayer(this.id, this.pageVm, 'requestFullScreen');
}
exitFullScreen () {
operateVideoPlayer(this.id, this.pageVm, 'exitFullScreen');
}
showStatusBar () {
operateVideoPlayer(this.id, this.pageVm, 'showStatusBar');
}
hideStatusBar () {
operateVideoPlayer(this.id, this.pageVm, 'hideStatusBar');
}
}
function createVideoContext$1 (id, context) {
if (context) {
return new VideoContext(id, context)
}
return new VideoContext(id, getCurrentPageVm('createVideoContext'))
}
var require_context_module_1_7 = /*#__PURE__*/Object.freeze({
createVideoContext: createVideoContext$1
});
const callbacks$3 = [];
onMethod('onAccelerometerChange', function (res) {
......@@ -7879,7 +7895,7 @@ var serviceContext = (function () {
})
}
var require_context_module_1_7 = /*#__PURE__*/Object.freeze({
var require_context_module_1_8 = /*#__PURE__*/Object.freeze({
onAccelerometerChange: onAccelerometerChange,
startAccelerometer: startAccelerometer,
stopAccelerometer: stopAccelerometer
......@@ -7902,7 +7918,7 @@ var serviceContext = (function () {
const onBLEConnectionStateChange$1 = on('onBLEConnectionStateChange');
const onBLECharacteristicValueChange$1 = on('onBLECharacteristicValueChange');
var require_context_module_1_8 = /*#__PURE__*/Object.freeze({
var require_context_module_1_9 = /*#__PURE__*/Object.freeze({
onBluetoothDeviceFound: onBluetoothDeviceFound$1,
onBluetoothAdapterStateChange: onBluetoothAdapterStateChange$1,
onBLEConnectionStateChange: onBLEConnectionStateChange$1,
......@@ -7949,7 +7965,7 @@ var serviceContext = (function () {
})
}
var require_context_module_1_9 = /*#__PURE__*/Object.freeze({
var require_context_module_1_10 = /*#__PURE__*/Object.freeze({
onCompassChange: onCompassChange,
startCompass: startCompass,
stopCompass: stopCompass
......@@ -7967,7 +7983,7 @@ var serviceContext = (function () {
callbacks$5.push(callbackId);
}
var require_context_module_1_10 = /*#__PURE__*/Object.freeze({
var require_context_module_1_11 = /*#__PURE__*/Object.freeze({
onNetworkStatusChange: onNetworkStatusChange
});
......@@ -8044,7 +8060,7 @@ var serviceContext = (function () {
return recorderManager || (recorderManager = new RecorderManager())
}
var require_context_module_1_11 = /*#__PURE__*/Object.freeze({
var require_context_module_1_12 = /*#__PURE__*/Object.freeze({
getRecorderManager: getRecorderManager
});
......@@ -8132,7 +8148,7 @@ var serviceContext = (function () {
return task
}
var require_context_module_1_12 = /*#__PURE__*/Object.freeze({
var require_context_module_1_13 = /*#__PURE__*/Object.freeze({
downloadFile: downloadFile$1
});
......@@ -8237,7 +8253,7 @@ var serviceContext = (function () {
return new RequestTask(requestTaskId)
}
var require_context_module_1_13 = /*#__PURE__*/Object.freeze({
var require_context_module_1_14 = /*#__PURE__*/Object.freeze({
request: request$1
});
......@@ -8411,7 +8427,7 @@ var serviceContext = (function () {
callbacks$7.close = callbackId;
}
var require_context_module_1_14 = /*#__PURE__*/Object.freeze({
var require_context_module_1_15 = /*#__PURE__*/Object.freeze({
connectSocket: connectSocket$1,
sendSocketMessage: sendSocketMessage$1,
closeSocket: closeSocket$1,
......@@ -8505,7 +8521,7 @@ var serviceContext = (function () {
return task
}
var require_context_module_1_15 = /*#__PURE__*/Object.freeze({
var require_context_module_1_16 = /*#__PURE__*/Object.freeze({
uploadFile: uploadFile$1
});
......@@ -8614,7 +8630,7 @@ var serviceContext = (function () {
return res
}
var require_context_module_1_16 = /*#__PURE__*/Object.freeze({
var require_context_module_1_17 = /*#__PURE__*/Object.freeze({
setStorage: setStorage$1,
setStorageSync: setStorageSync$1,
getStorage: getStorage$1,
......@@ -8705,7 +8721,7 @@ var serviceContext = (function () {
return new MPAnimation(option)
}
var require_context_module_1_17 = /*#__PURE__*/Object.freeze({
var require_context_module_1_18 = /*#__PURE__*/Object.freeze({
createAnimation: createAnimation
});
......@@ -8769,7 +8785,7 @@ var serviceContext = (function () {
return new ServiceIntersectionObserver(getCurrentPageVm('createIntersectionObserver'), options)
}
var require_context_module_1_18 = /*#__PURE__*/Object.freeze({
var require_context_module_1_19 = /*#__PURE__*/Object.freeze({
createIntersectionObserver: createIntersectionObserver
});
......@@ -8877,7 +8893,7 @@ var serviceContext = (function () {
return new SelectorQuery(getCurrentPageVm('createSelectorQuery'))
}
var require_context_module_1_19 = /*#__PURE__*/Object.freeze({
var require_context_module_1_20 = /*#__PURE__*/Object.freeze({
createSelectorQuery: createSelectorQuery
});
......@@ -8893,7 +8909,7 @@ var serviceContext = (function () {
callbacks$8.push(callbackId);
}
var require_context_module_1_20 = /*#__PURE__*/Object.freeze({
var require_context_module_1_21 = /*#__PURE__*/Object.freeze({
onKeyboardHeightChange: onKeyboardHeightChange
});
......@@ -8905,7 +8921,7 @@ var serviceContext = (function () {
return {}
}
var require_context_module_1_21 = /*#__PURE__*/Object.freeze({
var require_context_module_1_22 = /*#__PURE__*/Object.freeze({
pageScrollTo: pageScrollTo$1
});
......@@ -8941,7 +8957,7 @@ var serviceContext = (function () {
callbacks$9.push(callbackId);
}
var require_context_module_1_22 = /*#__PURE__*/Object.freeze({
var require_context_module_1_23 = /*#__PURE__*/Object.freeze({
removeTabBarBadge: removeTabBarBadge$1,
showTabBarRedDot: showTabBarRedDot$1,
hideTabBarRedDot: hideTabBarRedDot$1,
......@@ -8964,7 +8980,7 @@ var serviceContext = (function () {
callbacks$a.splice(callbacks$a.indexOf(callbackId), 1);
}
var require_context_module_1_23 = /*#__PURE__*/Object.freeze({
var require_context_module_1_24 = /*#__PURE__*/Object.freeze({
onWindowResize: onWindowResize,
offWindowResize: offWindowResize
});
......@@ -8981,23 +8997,24 @@ var serviceContext = (function () {
'./context/audio.js': require_context_module_1_4,
'./context/background-audio.js': require_context_module_1_5,
'./context/create-map-context.js': require_context_module_1_6,
'./device/accelerometer.js': require_context_module_1_7,
'./device/bluetooth.js': require_context_module_1_8,
'./device/compass.js': require_context_module_1_9,
'./device/network.js': require_context_module_1_10,
'./media/recorder.js': require_context_module_1_11,
'./network/download-file.js': require_context_module_1_12,
'./network/request.js': require_context_module_1_13,
'./network/socket.js': require_context_module_1_14,
'./network/upload-file.js': require_context_module_1_15,
'./storage/storage.js': require_context_module_1_16,
'./ui/create-animation.js': require_context_module_1_17,
'./ui/create-intersection-observer.js': require_context_module_1_18,
'./ui/create-selector-query.js': require_context_module_1_19,
'./ui/keyboard.js': require_context_module_1_20,
'./ui/page-scroll-to.js': require_context_module_1_21,
'./ui/tab-bar.js': require_context_module_1_22,
'./ui/window.js': require_context_module_1_23,
'./context/create-video-context.js': require_context_module_1_7,
'./device/accelerometer.js': require_context_module_1_8,
'./device/bluetooth.js': require_context_module_1_9,
'./device/compass.js': require_context_module_1_10,
'./device/network.js': require_context_module_1_11,
'./media/recorder.js': require_context_module_1_12,
'./network/download-file.js': require_context_module_1_13,
'./network/request.js': require_context_module_1_14,
'./network/socket.js': require_context_module_1_15,
'./network/upload-file.js': require_context_module_1_16,
'./storage/storage.js': require_context_module_1_17,
'./ui/create-animation.js': require_context_module_1_18,
'./ui/create-intersection-observer.js': require_context_module_1_19,
'./ui/create-selector-query.js': require_context_module_1_20,
'./ui/keyboard.js': require_context_module_1_21,
'./ui/page-scroll-to.js': require_context_module_1_22,
'./ui/tab-bar.js': require_context_module_1_23,
'./ui/window.js': require_context_module_1_24,
};
var req = function req(key) {
......
import {
invokeMethod,
getCurrentPageVm
} from '../../platform'
const RATES = [0.5, 0.8, 1.0, 1.25, 1.5]
function operateVideoPlayer (videoId, pageVm, type, data) {
invokeMethod('operateVideoPlayer', videoId, pageVm, type, data)
}
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 () {
operateVideoPlayer(this.id, this.pageVm, 'requestFullScreen')
}
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'))
}
import {
findElmById,
invokeVmMethod,
invokeVmMethodWithoutArgs
} from '../util'
const METHODS = {
play (ctx) {
return invokeVmMethodWithoutArgs(ctx, 'play')
},
pause (ctx) {
return invokeVmMethodWithoutArgs(ctx, 'pause')
},
seek (ctx, args) {
return invokeVmMethod(ctx, 'seek', args)
},
stop (ctx) {
return invokeVmMethodWithoutArgs(ctx, 'stop')
},
sendDanmu (ctx, args) {
return invokeVmMethod(ctx, 'sendDanmu', args)
},
playbackRate (ctx, args) {
return invokeVmMethod(ctx, 'playbackRate', args)
},
requestFullScreen (ctx, args) {
return invokeVmMethod(ctx, 'requestFullScreen', args)
},
exitFullScreen (ctx) {
return invokeVmMethodWithoutArgs(ctx, 'exitFullScreen')
},
showStatusBar (ctx) {
return invokeVmMethodWithoutArgs(ctx, 'showStatusBar')
},
hideStatusBar (ctx) {
return invokeVmMethodWithoutArgs(ctx, 'hideStatusBar')
}
}
export function operateVideoPlayer (videoId, pageVm, type, data) {
return METHODS[type](findElmById(videoId, pageVm), data)
}
import {
findElmById,
invokeVmMethod,
invokeVmMethodWithoutArgs
} from '../util'
class VideoContext {
constructor (id, ctx) {
this.id = id
this.ctx = ctx
}
play () {
return invokeVmMethodWithoutArgs(this.ctx, 'play')
}
pause () {
return invokeVmMethodWithoutArgs(this.ctx, 'pause')
}
seek (args) {
return invokeVmMethod(this.ctx, 'seek', args)
}
stop () {
return invokeVmMethodWithoutArgs(this.ctx, 'stop')
}
sendDanmu (args) {
return invokeVmMethod(this.ctx, 'sendDanmu', args)
}
playbackRate (args) {
return invokeVmMethod(this.ctx, 'playbackRate', args)
}
requestFullScreen (args) {
return invokeVmMethod(this.ctx, 'requestFullScreen', args)
}
exitFullScreen () {
return invokeVmMethodWithoutArgs(this.ctx, 'exitFullScreen')
}
showStatusBar () {
return invokeVmMethodWithoutArgs(this.ctx, 'showStatusBar')
}
hideStatusBar () {
return invokeVmMethodWithoutArgs(this.ctx, 'hideStatusBar')
}
}
export function createVideoContext (id, vm) {
if (!vm) {
return console.warn('uni.createVideoContext 必须传入第二个参数,即当前 vm 对象(this)')
}
const elm = findElmById(id, vm)
if (!elm) {
return console.warn('Can not find `' + id + '`')
}
return new VideoContext(id, elm)
}
import {
operateVideoPlayer as operateVueVideoPlayer
} from 'uni-platforms/h5/service/api/context/operate-video-player'
import {
operateVideoPlayer as operateNVueVideoPlayer
} from 'uni-platforms/app-plus-nvue/service/api/context/operate-video-player'
export function operateVideoPlayer (videoId, pageVm, type, data) {
pageVm.$page.meta.isNVue
? operateNVueVideoPlayer(videoId, pageVm, type, data)
: operateVueVideoPlayer(videoId, pageVm, type, data)
}
export function operateVideoPlayer (videoId, pageVm, type, data) {
const pageId = pageVm.$page.id
UniServiceJSBridge.publishHandler(pageId + '-video-' + videoId, {
videoId,
type,
data
}, pageId)
}
function operateVideoPlayer (videoId, pageId, type, data) {
UniServiceJSBridge.publishHandler(pageId + '-video-' + videoId, {
videoId,
type,
data
}, pageId)
}
const RATES = [0.5, 0.8, 1.0, 1.25, 1.5]
class VideoContext {
constructor (id, pageId) {
this.id = id
this.pageId = pageId
}
play () {
operateVideoPlayer(this.id, this.pageId, 'play')
}
pause () {
operateVideoPlayer(this.id, this.pageId, 'pause')
}
stop () {
operateVideoPlayer(this.id, this.pageId, 'stop')
}
seek (position) {
operateVideoPlayer(this.id, this.pageId, 'seek', {
position
})
}
sendDanmu ({
text,
color
} = {}) {
operateVideoPlayer(this.id, this.pageId, 'sendDanmu', {
text,
color
})
}
playbackRate (rate) {
if (!~RATES.indexOf(rate)) {
rate = 1.0
}
operateVideoPlayer(this.id, this.pageId, 'playbackRate', {
rate
})
}
requestFullScreen () {
operateVideoPlayer(this.id, this.pageId, 'requestFullScreen')
}
exitFullScreen () {
operateVideoPlayer(this.id, this.pageId, 'exitFullScreen')
}
showStatusBar () {
operateVideoPlayer(this.id, this.pageId, 'showStatusBar')
}
hideStatusBar () {
operateVideoPlayer(this.id, this.pageId, 'hideStatusBar')
}
}
export function createVideoContext (id, context) {
if (context) {
return new VideoContext(id, context.$page.id)
}
const app = getApp()
if (app.$route && app.$route.params.__id__) {
return new VideoContext(id, app.$route.params.__id__)
} else {
UniServiceJSBridge.emit('onError', 'createVideoContext:fail')
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册