Files
ruo-shan-cloud-pharmacy/miniprogram/package-live/volc-mini-sdk/components/player/volc-live-player/volc-live-player.js
T
陈誉午 994b267f5c feat: 电子药箱小程序 - 4Tab药品管理
- 电子药箱: 药品库存管理 + 手动录入 + 今日用药打卡
- 药品百科: 搜索 + 分类筛选 + 20种药品静态数据
- 惠教中心: 4条药品使用指南课程
- 我的: 家庭成员信息管理
- 自定义TabBar + navigation-bar组件
- SVG药品分类插图
2026-07-29 11:20:52 +08:00

1 line
16 KiB
JavaScript

"use strict";var _types=require("../types"),_utils=require("./utils"),_constant=require("../../../utils/constant"),_constants=require("../constants"),_utils2=require("../../../utils/utils"),_backgroundPlayback=require("../../../utils/background-playback"),_excluded=["shouldEmitRepeatedWaiting"];function _typeof(e){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_typeof(e)}function ownKeys(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),i.push.apply(i,n)}return i}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(i),!0).forEach(function(t){_defineProperty(e,t,i[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):ownKeys(Object(i)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))})}return e}function _defineProperty(e,t,i){return(t=_toPropertyKey(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}function _toPropertyKey(e){var t=_toPrimitive(e,"string");return"symbol"===_typeof(t)?t:String(t)}function _toPrimitive(e,t){if("object"!==_typeof(e)||null===e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var n=i.call(e,t||"default");if("object"!==_typeof(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}function _objectWithoutProperties(e,t){if(null==e)return{};var i,n,o=_objectWithoutPropertiesLoose(e,t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);for(n=0;n<r.length;n++)i=r[n],t.indexOf(i)>=0||Object.prototype.propertyIsEnumerable.call(e,i)&&(o[i]=e[i])}return o}function _objectWithoutPropertiesLoose(e,t){if(null==e)return{};var i,n,o={},r=Object.keys(e);for(n=0;n<r.length;n++)i=r[n],t.indexOf(i)>=0||(o[i]=e[i]);return o}var VIDEO_CONTEXT_NO_ARG_METHODS=new Set(["play","pause","stop","exitFullScreen","exitPictureInPicture"]),VIDEO_INTERNAL_RETRY_MAX=3,PAUSE_SOURCE={API:"api",USER:"user",NATIVE:"native"};Component({options:{multipleSlots:!0},properties:{engine:{type:String,value:_constant.BUILD_VIDEO_ONLY?"video":"live-player"},src:{type:String,value:""},objectFit:{type:String,value:"contain"},pictureInPictureMode:{type:Array,value:["push","pop"]},minCache:{type:Number,value:5},maxCache:{type:Number,value:10},successCode:{type:Number,value:_types.LiveStateCode.SUCCESS},showControls:{type:Boolean,value:!0},showPlayControl:{type:Boolean,value:!0},showFullscreenControl:{type:Boolean,value:!0}},data:{isPlaying:!1,isFullscreen:!1,controlsVisible:!0,isLoading:!1},observers:{engine:function(e,t){this._onEngineChange(e,t)},src:function(e,t){t!==e&&(this._resetPlaybackFlags(),this.setData({isLoading:!!e}))},showControls:function(e){if(!e)return this._clearControlsAutoHideTimer(),void(0,_utils2.setDataIfChanged)(this,{controlsVisible:!1});this._showControlsAndScheduleHide()},isPlaying:function(e,t){e!==t&&this._showControlsAndScheduleHide()}},lifetimes:{ready:function(){this._resetPlaybackFlags(),this._ensureContexts(this._getEngine()),this.data.showControls?this._showControlsAndScheduleHide():this.setData({controlsVisible:!1})},detached:function(){try{var e,t;null===(e=this.livePlayerContext)||void 0===e||null===(t=e.stop)||void 0===t||t.call(e)}catch(e){}try{var i,n;null===(i=this.videoContext)||void 0===i||null===(n=i.stop)||void 0===n||n.call(i)}catch(e){}this.livePlayerContext=null,this.videoContext=null,this._clearControlsAutoHideTimer(),this._clearWaitingEndTimer()}},methods:{_resetPlaybackFlags:function(){this._firstFrameEmitted=!1,this._videoAutoplayAttemptedSrc=null,this._videoInternalRetryCount=0,this._nextPauseSource="",this._isWaiting=!1,this._waitingSource="",this._clearWaitingEndTimer()},_enterWaiting:function(e,t){var i=t||{},n=i.shouldEmitRepeatedWaiting,o=_objectWithoutProperties(i,_excluded);return this._isWaiting?(n&&this._triggerEvent("waiting",e,_objectSpread({},o)),!1):(this._isWaiting=!0,this._waitingSource=(null==o?void 0:o.source)||"",this._triggerEvent("waiting",e,_objectSpread({},o)),!0)},_exitWaiting:function(e,t){if(!this._isWaiting)return!1;this._clearWaitingEndTimer();var i=this._waitingSource||"";return this._isWaiting=!1,this._waitingSource="",this._triggerEvent("waitingend",e,_objectSpread(_objectSpread({},t||{}),{},{waitingSource:i})),!0},_clearWaitingState:function(){this._isWaiting=!1,this._waitingSource="",this._clearWaitingEndTimer()},_clearWaitingEndTimer:function(){this._waitingEndTimer&&(clearTimeout(this._waitingEndTimer),this._waitingEndTimer=null)},_scheduleWaitingEndFallback:function(e){var t=this;"video"===this._getEngine()&&(this._clearWaitingEndTimer(),this._waitingEndTimer=setTimeout(function(){t._waitingEndTimer=null,t._exitWaiting(e,{source:"waiting_timeout",synthetic:!0})},_constants.VIDEO_WAITING_END_TIMEOUT_MS))},_clearControlsAutoHideTimer:function(){this._controlsAutoHideTimer&&(clearTimeout(this._controlsAutoHideTimer),this._controlsAutoHideTimer=null)},_scheduleControlsAutoHide:function(){var e=this;this._clearControlsAutoHideTimer(),this.data.isPlaying&&(this._controlsAutoHideTimer=setTimeout(function(){e.data.showControls&&e.data.isPlaying&&(0,_utils2.setDataIfChanged)(e,{controlsVisible:!1})},5e3))},_showControlsAndScheduleHide:function(){this.data.showControls&&((0,_utils2.setDataIfChanged)(this,{controlsVisible:!0}),this.data.isPlaying?this._scheduleControlsAutoHide():this._clearControlsAutoHideTimer())},_handleTapLayerTap:function(){this._showControlsAndScheduleHide()},_handleControlsTap:function(){this._showControlsAndScheduleHide()},_triggerEvent:function(e,t,i){var n=this._getEngine(),o=this.data.src||"",r=t&&"object"===_typeof(t)?t:{};this.triggerEvent(e,_objectSpread(_objectSpread({},i||{}),{},{engine:n,src:o,raw:r}))},_markNextPauseEvent:function(e){this._nextPauseSource=e||PAUSE_SOURCE.API},_consumeNextPauseSource:function(){var e=this._nextPauseSource||PAUSE_SOURCE.NATIVE;return this._nextPauseSource="",e},_emitFirstFrame:function(e,t){this._firstFrameEmitted||(this._firstFrameEmitted=!0,this._exitWaiting(e,{source:"firstframe"}),this.setData({isLoading:!1}),this._triggerEvent("firstframe",e,t))},call:function(e){if(e&&"string"==typeof e){for(var t=this._getEngine(),i=arguments.length,n=new Array(i>1?i-1:0),o=1;o<i;o++)n[o-1]=arguments[o];"video"!==t?this.callLivePlayerContext.apply(this,[e].concat(n)):this.callVideoContext.apply(this,[e].concat(n))}},callVideoContext:function(e){if(e&&"string"==typeof e){for(var t=this._getVideoContext(),i=t&&"function"==typeof t[e]?t[e]:null,n=arguments.length,o=new Array(n>1?n-1:0),r=1;r<n;r++)o[r-1]=arguments[r];var a=o&&o[0]&&"object"===_typeof(o[0])?o[0]:null,s=a&&"function"==typeof a.success?a.success:null,l=a&&"function"==typeof a.fail?a.fail:null,u=a&&"function"==typeof a.complete?a.complete:null;try{if(!i)return void(l&&l({errMsg:"".concat(e,":fail method not found")}));VIDEO_CONTEXT_NO_ARG_METHODS.has(e)?(i.call(t),s&&s({errMsg:"".concat(e,":ok")})):i.apply(t,o)}catch(t){l&&l({errMsg:"".concat(e,":fail"),error:t})}finally{u&&u({errMsg:"".concat(e,":complete")})}}},callLivePlayerContext:function(e){if(e&&"string"==typeof e){var t=this._getLivePlayerContext(),i=t&&"function"==typeof t[e]?t[e]:null;if(i){for(var n=arguments.length,o=new Array(n>1?n-1:0),r=1;r<n;r++)o[r-1]=arguments[r];i.apply(t,o)}}},_onEngineChange:function(e,t){if(t&&t!==e){try{var i,n,o,r;"video"===t?(null===(i=this.videoContext)||void 0===i||null===(n=i.stop)||void 0===n||n.call(i),this.videoContext=null):(null===(o=this.livePlayerContext)||void 0===o||null===(r=o.stop)||void 0===r||r.call(o),this.livePlayerContext=null)}catch(e){}(0,_utils2.setDataIfChanged)(this,{isPlaying:!1,isFullscreen:!1}),this._resetPlaybackFlags()}},_ensureContexts:function(e){"video"!==e?this.livePlayerContext||(this.livePlayerContext=wx.createLivePlayerContext("innerLivePlayer",this)):this.videoContext||(this.videoContext=wx.createVideoContext("innerLiveVideo",this))},_getVideoContext:function(){return this._ensureContexts("video"),this.videoContext},_getLivePlayerContext:function(){return this._ensureContexts("live-player"),this.livePlayerContext},_getEngine:function(){return"video"===this.data.engine?"video":"live-player"},_getCurrentMediaContext:function(){return"video"===this._getEngine()?this._getVideoContext():this._getLivePlayerContext()},canRequestBackgroundPlayback:function(){return(0,_backgroundPlayback.canRequestBackgroundPlaybackByPlayerType)(this._getEngine())},requestBackgroundPlayback:function(){var e=this._getCurrentMediaContext(),t=e&&"function"==typeof e.requestBackgroundPlayback?e.requestBackgroundPlayback:null;if(!t)throw{errMsg:"requestBackgroundPlayback:fail method not found"};try{t.call(e)}catch(e){throw{errMsg:(null==e?void 0:e.errMsg)||(null==e?void 0:e.message)||"requestBackgroundPlayback:fail",error:e}}},play:function(e){this.call("play",e)},stop:function(e){var t=this;this.call("stop",_objectSpread(_objectSpread({},e),{},{success:function(i){var n;null==e||null===(n=e.success)||void 0===n||n.call(e,i),t.setData({isPlaying:!1,isFullscreen:!1})}})),this._resetPlaybackFlags(),this.setData({isLoading:!1})},pause:function(e){var t=this,i=this._getEngine(),n=(null==e?void 0:e.pauseSource)||PAUSE_SOURCE.API;if(this._markNextPauseEvent(n),"video"===i)return this.setData({isPlaying:!1}),void this.callVideoContext("pause",e);this.callLivePlayerContext("pause",_objectSpread(_objectSpread({},e),{},{success:function(i){var n;null==e||null===(n=e.success)||void 0===n||n.call(e,i),t.setData({isPlaying:!1});var o=t._consumeNextPauseSource();t._triggerEvent("pause",i,{pauseSource:o,userInitiated:o===PAUSE_SOURCE.USER})}}))},resume:function(e){var t=this;"video"!==this._getEngine()?this.callLivePlayerContext("resume",_objectSpread(_objectSpread({},e),{},{success:function(i){var n;null==e||null===(n=e.success)||void 0===n||n.call(e,i),t.setData({isPlaying:!0}),t._triggerEvent("play")}})):this.play(e)},requestFullScreen:function(e){this.call("requestFullScreen",e)},exitFullScreen:function(e){this.call("exitFullScreen",e)},exitPictureInPicture:function(e){this.call("exitPictureInPicture",e)},stopAll:function(){try{var e,t;null===(e=this.videoContext)||void 0===e||null===(t=e.stop)||void 0===t||t.call(e)}catch(e){}try{var i,n;null===(i=this.livePlayerContext)||void 0===i||null===(n=i.stop)||void 0===n||n.call(i)}catch(e){}this.setData({isPlaying:!1,isFullscreen:!1}),this._resetPlaybackFlags(),this.setData({isLoading:!1})},handlePlay:function(e){this.setData({isPlaying:!0}),this._exitWaiting(null==e?void 0:e.detail,{source:"play"}),this._emitFirstFrame(null==e?void 0:e.detail),this._triggerEvent("play",null==e?void 0:e.detail)},handlePause:function(e){var t=this._consumeNextPauseSource();this.setData({isPlaying:!1}),this._triggerEvent("pause",null==e?void 0:e.detail,{pauseSource:t,userInitiated:t===PAUSE_SOURCE.USER})},handleError:function(e){var t,i,n,o=(null==e?void 0:e.detail)||{},r=Number(null!==(t=null!==(i=null!==(n=o.code)&&void 0!==n?n:o.errCode)&&void 0!==i?i:o.errno)&&void 0!==t?t:-1e4),a=o.message||o.msg||o.errMsg||"";if("video"===this._getEngine()){var s=this.data.src||"",l=(0,_utils.getVideoErrorRetryAction)(o,a);if(l===_utils.VideoErrorRetryAction.REPORT_ONLY)return void this._triggerEvent("retry",o,{code:r,message:a,reason:"video_error_report_only",retryAction:l,reportOnly:!0,src:s,liveEngine:"video"});this._triggerEvent("statechange",o,{message:a,code:r,reason:"video_error_callback"});var u=Number(this._videoInternalRetryCount||0);if(s&&u<VIDEO_INTERNAL_RETRY_MAX&&l!==_utils.VideoErrorRetryAction.NONE){var c=u+1;return this._videoInternalRetryCount=c,this._triggerEvent("retry",o,{code:r,message:a,retryCount:c,retryMax:VIDEO_INTERNAL_RETRY_MAX,reason:"video_error_retry",retryAction:l,src:s,liveEngine:"video"}),l===_utils.VideoErrorRetryAction.RESTART&&this.callVideoContext("stop"),void this.callVideoContext("play")}this.setData({isPlaying:!1}),this.setData({isLoading:!1}),this._clearWaitingState(),this._triggerEvent("error",o,{code:r,message:a})}},handleStateChange:function(e){var t=(null==e?void 0:e.detail)||{},i=t.code,n=t.message;if(this._triggerEvent("statechange",t,{code:i,message:n}),i===("number"!=typeof this.data.successCode||Number.isNaN(this.data.successCode)?_types.LiveStateCode.SUCCESS:this.data.successCode)&&(this.setData({isPlaying:!0}),this._emitFirstFrame(t,{code:i,message:n}),this._triggerEvent("play",t,{code:i,message:n})),i===_types.LiveStateCode.BEGIN_PLAY)this._exitWaiting(t,{code:i,message:n,source:"statechange_begin_play"});else if(i===_types.LiveStateCode.RESOLUTION_CHANGED){var o=(0,_utils.parseLiveStateResolutionChangeMessage)(n);o&&this._triggerEvent("loadedmetadata",t,o)}else i===_types.LiveStateCode.LOADING_START||i===_types.LiveStateCode.NETWORK_RECONNECTING?this._enterWaiting(t,{code:i,message:n,source:i===_types.LiveStateCode.LOADING_START?"statechange_loading_start":"statechange_reconnecting"}):i===_types.LiveStateCode.PLAY_ENDED?this.setData({isPlaying:!1}):_types.LIVE_PLAYER_ERROR_CODES.includes(i)&&(this.setData({isPlaying:!1}),this.setData({isLoading:!1}),this._clearWaitingState(),this._triggerEvent("error",t,{code:i,message:n}))},handleFullscreenChange:function(e){var t,i=null==e||null===(t=e.detail)||void 0===t?void 0:t.fullScreen;"boolean"==typeof i&&(0,_utils2.setDataIfChanged)(this,{isFullscreen:i}),this._triggerEvent("fullscreenchange",null==e?void 0:e.detail,{fullScreen:i}),this._showControlsAndScheduleHide()},handleNetStatus:function(e){var t=(null==e?void 0:e.detail)||{};this._triggerEvent("netstatus",t,{info:t.info})},handleWaiting:function(e){this._triggerEvent("statechange",null==e?void 0:e.detail,{message:"video live engine waiting",code:_types.LiveStateCode.LOADING_START,reason:"waiting_callback",detail:null==e?void 0:e.detail}),this._enterWaiting(null==e?void 0:e.detail,{code:_types.LiveStateCode.LOADING_START,message:"video live engine waiting",source:"waiting_callback",shouldEmitRepeatedWaiting:!0}),this._scheduleWaitingEndFallback(null==e?void 0:e.detail)},handleLoadedMetaData:function(e){var t,i;if(this._videoInternalRetryCount=0,this._triggerEvent("loadedmetadata",null==e?void 0:e.detail,{width:null==e||null===(t=e.detail)||void 0===t?void 0:t.width,height:null==e||null===(i=e.detail)||void 0===i?void 0:i.height}),this._exitWaiting(null==e?void 0:e.detail,{source:"loadedmetadata"}),this._triggerEvent("statechange",null==e?void 0:e.detail,{message:"video live engine loadedmetadata",code:_types.LiveStateCode.BEGIN_PLAY,detail:null==e?void 0:e.detail,reason:"loadedmetadata"}),"video"===this._getEngine()){var n=this.data.src||"";n&&this._videoAutoplayAttemptedSrc!==n&&(this._videoAutoplayAttemptedSrc=n,this.callVideoContext("play"))}},handleProgress:function(e){this._videoInternalRetryCount=0,this._exitWaiting(null==e?void 0:e.detail,{source:"progress"}),this._triggerEvent("statechange",null==e?void 0:e.detail,{message:"video live engine progress update",code:_types.LiveStateCode.PLAY_PROGRESS,detail:null==e?void 0:e.detail,reason:"progress"})},handleTimeUpdate:function(e){var t;this.setData({isLoading:!1}),this._videoInternalRetryCount=0,this._exitWaiting(null==e?void 0:e.detail,{source:"timeupdate"}),this._triggerEvent("statechange",null==e?void 0:e.detail,{message:"video live engine timeupdate",code:_types.LiveStateCode.PLAY_PROGRESS,detail:null==e?void 0:e.detail,reason:"timeupdate"}),this._triggerEvent("timeupdate",null==e?void 0:e.detail,{currentTime:null==e||null===(t=e.detail)||void 0===t?void 0:t.currentTime})},handleEnded:function(e){this.setData({isPlaying:!1,isLoading:!1}),this._triggerEvent("ended",null==e?void 0:e.detail)},handleEnterPictureInPicture:function(e){this._triggerEvent("enterpictureinpicture",null==e?void 0:e.detail)},handleLeavePictureInPicture:function(e){this._triggerEvent("leavepictureinpicture",null==e?void 0:e.detail)},_togglePlay:function(){this._showControlsAndScheduleHide(),this.data.isPlaying?this.pause({pauseSource:PAUSE_SOURCE.USER}):this.resume()},_toggleFullscreen:function(){this._showControlsAndScheduleHide(),this.data.isFullscreen?this.exitFullScreen():this.requestFullScreen({direction:90})}}});