Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, not all, embodiments of the present invention. The components of embodiments of the present invention generally described and illustrated in the figures herein may be arranged and designed in a wide variety of different configurations. Thus, the following detailed description of the embodiments of the present invention, presented in the figures, is not intended to limit the scope of the invention, as claimed, but is merely representative of selected embodiments of the invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures.
In the process of implementing the technical solution provided by the embodiment of the present application, the inventor of the present application finds that in the prior art, a solution for a browser page developer to load a video in a page mainly includes: the video file address is loaded into the page using the tag of HTML5 or the video is imported using a Flash plug-in. However, both of these solutions have problems, and the tag mechanism of HTML5 is not compatible with older versions of browsers. More and more browsers have many restrictions on Flash plug-ins, for example, some browsers do not have Flash plug-ins (e.g., Firefox, chrome, etc.), and devices using the iOS system (e.g., iPad, iPhone, iPod touch) do not support Flash. Therefore, when the same video file is loaded in browsers of different versions or browsers of different operating systems, the situations that the video file is not loaded successfully and the video cannot be played may occur.
The above prior art solutions have shortcomings which are the results of practical and careful study of the inventor, and therefore, the discovery process of the above problems and the solutions proposed by the following embodiments of the present invention to the above problems should be the contribution of the inventor to the present invention in the course of the present invention.
In order to alleviate the above problem, embodiments of the present invention provide a video compatible loading method and apparatus, and a video component. The following embodiments are provided to describe a video compatible loading method, device and video component provided by the present invention.
First embodiment
The embodiment of the invention provides a video compatible loading method. Referring to fig. 1, fig. 1 is a flowchart illustrating a video compatible loading method according to a first embodiment of the present invention. The following describes in detail the flow of a video compatible loading method, which includes: step S120, step S130, and step S140.
Step S120, responding to the operation of starting the browser page, and loading the browser page.
In this embodiment, when a user opens a browser page, the browser responds to an operation of starting the browser page by the user, and loads the browser page.
Step S130, when loading the browser page, performing video compatibility detection on the current browser through the pre-configured video component 230, and selecting a video loading mode supported by the current browser.
Referring to fig. 2, fig. 2 is a flowchart illustrating sub-steps of step S130 shown in fig. 1 according to a first embodiment of the present invention. The step S130 includes a sub-step S131, a sub-step S132, a sub-step S133, a sub-step S134, and a sub-step S135.
Sub-step S131, detecting whether the hypertext video parameter of the current browser is defined through the pre-configured video component 230.
In this embodiment, the hypertext video parameter may be, but is not limited to, html videoelement. The HTMLVideoElement interface provides special properties and methods for manipulating video objects, inherits the properties and methods of htmlmediaelements and htmlelements, and can be applied to different browsers.
In this embodiment, the Video component 230 may further determine whether the current browser supports the Video tag of HTML5 by detecting whether the HTML videoelement of the current browser is defined. The Video tag of HTML5 can add the address of the Video file to the browser page to facilitate Video loading.
When the hypertext video parameter is defined, substep S132 is performed.
When the hypertext video parameter is not defined, substep S133.
In sub-step S132, the video component 230 selects a hypertext video loading mode as the video loading mode supported by the current browser.
In this embodiment, when the hypertext Video parameter (HTML Video element) is defined, the Video component 230 may determine that the current browser supports a Video tag of HTML5, and may select a hypertext Video loading mode as the Video loading mode supported by the current browser. The hypertext Video loading mode means that the Video component 230 may create a Video tag of HTML5, and fill an address of a Video file (e.g., a Video file in mp4 format, webm format, or ogv format) configured by a developer into an src attribute of the Video tag for Video loading.
In sub-step S133, the video component 230 detects whether the current browser installs a video plug-in.
In this embodiment, when the hypertext video parameter is not defined, the video component 230 can detect whether the current browser installs a video plug-in. The video plug-in may include, but is not limited to, Flash plug-in, npapi (netscape plug-in Application Programming interface), active plug-in schemes, and the like.
For example, the video component 230 may determine whether a Flash plug-in is installed in the current browser through navigator.
When the video plug-in is installed, substep S134 is performed.
When the video plug-in is not installed, substep S135 is performed.
In sub-step S134, the video component 230 selects a video plug-in loading mode as the video loading mode supported by the current browser.
In this embodiment, when installing a video plug-in, the video component 230 may select a video plug-in loading mode as the video loading mode supported by the current browser.
For example, if the current browser is installed with a Flash plug-in, the video plug-in loading mode means that the video component 230 can load a Flash video file configured by a developer in advance by using SWFObject.
In this embodiment, SWFObject is a JavaScript module for conveniently inserting Adobe Flash media resources (swf files) in HTML. The JavaScript script in SWFObject can automatically detect the support condition of various mainstream browsers on PC and Mac machines to the Flash plug-in, so that the inserted Flash media resources are simple, convenient and safe.
In sub-step S135, the video component 230 performs video demotion based on the pre-configured still picture.
In this embodiment, when a Video plug-in is not installed, that is, when the current browser does not support both a hypertext Video loading mode (for example, a Video tag of HTML 5) and a Video plug-in loading mode (for example, a Flash plug-in loading mode), the Video component 230 may perform Video demotion display processing, that is, the Video component 230 may load and display a static picture configured in advance by a developer in a browser page.
In this embodiment, different technical implementation schemes are provided for different browsers, and video loading can be performed in a video loading mode supported by a browser by performing video compatibility detection on the browser. The scheme is basically applicable to most browsers, and the video component 230 is high in portability and wide in application range.
In step S140, the video component 230 performs delayed loading on the video file based on the selected video loading manner.
Referring to fig. 3, fig. 3 is a flowchart illustrating sub-steps of step S140 shown in fig. 1 according to a first embodiment of the present invention. The step S140 includes a substep S141, a substep S142, and a substep S143.
Substep S141, a listening check is performed on page scrolling and browser window scaling by the video component 230.
In this embodiment, in order to improve the loading performance, the video component 230 may perform a lazy loading operation on a video file, that is, the video component 230 may perform monitoring detection on a scroll event of a mouse operated by a user and a zoom event of a browser window. For example, the video component 230 may sum the size of the browser window and the scrolling value of the browser window, and compare the sum result with a preset top position value of the display frame of the loaded video file.
In sub-step S142, the video component 230 determines whether the display position of the video file is within the current visual view according to the detection result.
In this embodiment, the video component 230 may determine whether the display position of the video file is within the current visual view according to a detection result obtained by comparing the summation result with the top position value.
In this embodiment, if the summation result is consistent with the comparison result of the top position value, or is within a preset reasonable threshold range, it may be determined that the display position of the video file is within the current visual view.
In sub-step S143, when the current visual view is displayed, the video component 230 loads the video file based on the selected video loading manner.
In this embodiment, when the current visual view is within the current visual view, the video component 230 may load the video file based on the video loading manner selected in step S130.
In this embodiment, if the current view is not in the current view, the video component 230 will not load the video file, and will continue to monitor and detect page scrolling and browser window zooming.
In this embodiment, resources such as videos and pictures can be delayed and loaded as required by the scheme, so that a potential page white screen caused by blocking of page display when the video component 230 loads the resources is avoided, the loading speed and performance of the page can be effectively improved, and user experience is improved.
Referring to fig. 4, fig. 4 is a second flowchart illustrating a video compatible loading method according to a first embodiment of the present invention. The method further comprises the following steps: step S110 and step S115.
Step S110, responding to the operation of editing the configuration parameters of the video component 230, and updating the configuration of the video component 230 based on the configuration parameters.
Referring to fig. 5, fig. 5 is a flowchart illustrating sub-steps of step S110 shown in fig. 4 according to a first embodiment of the present invention. The step S110 includes a substep S111, a substep S112, a substep S113, and a substep S114.
Substep S111, monitoring an editing event of the configuration text box of the video component 230, and responding to an operation of editing the configuration parameters of the video component 230.
In this embodiment, in the configuration text box provided by the video component 230, a developer can perform custom editing on the video component 230 through the editing function provided by the video component 230. For example, a developer can perform custom editing on configuration parameters such as width and height (height) of a video display area, a video file address, and a video playing speed.
In this embodiment, a callback function corresponding to an API (Application Programming Interface) provided by a browser may be used to monitor a custom editing operation of a developer in a configuration text box, and when the developer edits configuration parameters, the video component 230 may obtain a notification and respond to the operation of editing the configuration parameters of the video component 230.
And a substep S112, obtaining the configuration parameters edited to the configuration text box.
In this embodiment, the configuration parameters may include, but are not limited to, a width and a height (width, height) of the Video display area, Video file addresses (e.g., Video file addresses in mp4 format and webm format loaded by a Video tag of HTML5, Video file addresses in swf format corresponding to a Flash plug-in, img format corresponding to a still picture, etc.), a Video playing speed, and the like.
And a substep S113, performing configuration update on the data state of the video component 230 based on the configuration parameters, and performing preview play on the video file subjected to configuration update.
In this embodiment, the browser may perform configuration update on the data state of the video component 230 based on the configuration parameters edited by the developer, update the data state inside the video component 230, and automatically preview and play the video file subjected to configuration update to the developer.
In this embodiment, an automatic preview mode is adopted in the scheme, and the browser can automatically preview and play the updated configuration effect to the developer, so that the developer can dynamically adjust the visual effect of the page.
And a substep S114, responding to the storage operation completed by the configuration, and performing conversion processing on the stored configuration parameters to obtain variable texts corresponding to the configuration parameters.
In this embodiment, after the developer completes the configuration change of the video component 230, the browser may click the save button, respond to the save operation completed by the configuration of the developer, save the edited and changed configuration parameters, and perform conversion processing on the saved configuration parameters to convert the configuration parameters into the variable text of the JavaScript.
In step S115, in response to the initial import operation of introducing the configuration updated video component 230 into the browser page, the video component 230 is applied to the browser page.
In this embodiment, the browser responds to an initial import operation in which a developer imports the video component 230 into the browser page to apply the video component 230 to the browser page. Wherein the initializing import operation comprises: after the configuration of the video component 230 is completed, when a developer needs to use the video component 230, the developer introduces (performs import processing) the video component 230 into a developed browser page; then, a module export class (e.g. Video) is created, and the variable text of the JavaScript obtained by the previous conversion is passed into the constructor of the Video class, that is: new Video (parmas), whereby the Video component 230 can be successfully introduced into the browser page.
In the embodiment, a developer only needs to write codes when introducing and custom-editing the video component 230, and other parts can be automatically realized by the video component 230, so that the use threshold of the video component 230 can be reduced, and the use range of the video component 230 can be expanded.
Second embodiment
The embodiment of the invention also provides a video compatible loading device 200. Referring to fig. 6, fig. 6 is a functional block diagram of a video compatible loading device 200 according to a second embodiment of the present invention. The device comprises: a response module 220 and a video component 230.
The response module 220 is configured to respond to an operation of starting a browser page, and load the browser page.
The video component 230 is configured to perform video compatibility detection on the current browser when the browser page is loaded, and select a video loading mode supported by the current browser.
The video component 230 is further configured to perform delayed loading on a video file based on the selected video loading manner.
Referring to fig. 6 again, the apparatus further includes: the configuration update module 210.
The configuration update module 210 is configured to respond to an operation of editing the configuration parameters of the video component 230, and perform configuration update on the video component 230 based on the configuration parameters.
The response module 220 is further configured to respond to an initial import operation of introducing the video component 230 with the configuration update into the browser page, so as to apply the video component 230 to the browser page.
It can be understood that, for the specific operation method of each functional module in this embodiment, reference may be made to the detailed description of the corresponding step in the first embodiment, and no repeated description is provided herein.
Third embodiment
An embodiment of the present invention further provides a video component 230. Referring to fig. 7, fig. 7 is a functional unit diagram of a video module 230 according to a third embodiment of the present invention. The video component 230 includes: a detection selection unit 231 and a loading unit 232.
The detection selecting unit 231 is configured to perform video compatibility detection on the current browser when a browser page is loaded, and select a video loading mode supported by the current browser.
And a loading unit 232, configured to perform delayed loading on the video file based on the selected video loading manner.
It is understood that, in the present embodiment, the detailed description of step S130 and step S140 in the first embodiment can be referred to for the specific operation method of each functional unit of the video component 230, and the detailed description is not repeated herein.
An embodiment of the present invention further provides a readable storage medium, where a computer program is stored in the readable storage medium, and when the computer program is executed, the video compatible loading method provided in the first embodiment is implemented.
Further, the video compatible loading method, apparatus and video component 230 provided by the embodiment of the present invention can be applied to the electronic device 100. Referring to fig. 8, fig. 8 is a schematic block diagram of a structure of an electronic device 100 according to an embodiment of the present invention. The electronic device 100 may be a tablet computer, a Personal Computer (PC), a notebook computer, or even a server. The electronic device 100 may include a bus 110, a processor 120, and a memory 130.
In this embodiment, electronic device 100 may be implemented by bus 110 as a general bus architecture. Bus 110 may include any number of interconnecting buses and bridges depending on the specific application of electronic device 100 and the overall design constraints. The bus 110 connects various circuits including the processor 120, the memory 130, and the like. The bus 110 may also connect various other circuits such as timing sources, peripherals, voltage regulators, or power management circuits, which are well known in the art, and therefore, will not be described in detail herein.
In this embodiment, the memory 130 stores the video compatible loader 200, the video compatible loader 200 includes at least one software functional module which can be stored in the memory 130 in a form of software or firmware (firmware), and the processor 120 executes various functional applications and data processing by running the software programs and modules stored in the memory 130.
The Memory 130 may be, but is not limited to, a Random Access Memory (RAM), a Read Only Memory (ROM), a Programmable Read-Only Memory (PROM), an Erasable Read-Only Memory (EPROM), an electrically Erasable Read-Only Memory (EEPROM), and the like. The memory 130 is used for storing a program, and the processor 120 executes the program after receiving the execution instruction. Further, the software programs and modules within the memory 130 may also include an operating system, which may include various software components and/or drivers for managing system tasks (e.g., memory management, storage device control, power management, etc.), and may communicate with various hardware or software components to provide an operating environment for other software components.
The processor 120 may be an integrated circuit chip having signal processing capabilities. The Processor 120 may be a general-purpose Processor including a Central Processing Unit (CPU), a Network Processor (NP), and the like. The various methods, steps and logic blocks disclosed in the embodiments of the present invention may be implemented or performed. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
It will be appreciated that the configuration depicted in FIG. 8 is merely illustrative and that electronic device 100 may include more or fewer components than shown in FIG. 8 or have a different configuration than shown in FIG. 8. The components shown in fig. 8 may be implemented in hardware, software, or a combination thereof.
In summary, embodiments of the present invention provide a video compatible loading method and apparatus, and a video component. The method comprises the following steps: and responding to the operation of starting the browser page, and loading the browser page. When the browser page is loaded, performing video compatibility detection on the current browser through a pre-configured video component, and selecting a video loading mode supported by the current browser. And carrying out delayed loading on a video file based on the selected video loading mode through the video component.
Therefore, different technical implementation schemes are provided for different browsers, and video loading can be performed by selecting a video loading mode supported by the browser through performing video compatibility detection on the browser. The scheme is basically applicable to most browsers, and the video component is high in transportability and wide in application range. In addition, according to the scheme, resources such as videos and pictures can be loaded in a delayed mode according to needs, potential page white screen caused by blocking of page display when the video components load the resources is avoided, the loading speed and performance of the page can be effectively improved, and user experience is improved.
The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention, and various modifications and changes may be made by those skilled in the art. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.