Detailed Description
In order to describe the technical contents, the achieved objects and effects of the present invention in detail, the following description will be made with reference to the embodiments in conjunction with the accompanying drawings.
Referring to fig. 1 and fig. 3 to fig. 5, an embodiment of the present invention provides a video carousel switching method, which includes the steps of:
presetting a first preset number of video nodes and a second preset number of node containers, wherein the second preset number is smaller than the first preset number;
sequentially adding one video node into each node container, loading and sequentially playing node videos corresponding to the video nodes in the node containers;
acquiring the sliding distance of the sliding video node, judging whether the sliding distance is larger than a threshold value, if so, taking the sliding video node as a current node, and if the current node does not exist in the node container, replacing the node video farthest from the current node in the node container with the node video of the current node;
and judging whether the first preset number of video nodes of the batch are loaded and played, if so, acquiring the next batch of the first preset number of video nodes, adding the newly acquired video nodes into the corresponding node containers, and loading and playing.
From the above description, the beneficial effects of the invention are as follows: presetting a first preset number of video nodes and a second preset number of node containers, sequentially adding the video nodes into the node containers, and loading and sequentially playing node videos corresponding to the video nodes; by limiting the number of node containers and dynamically replacing the nodes in the node containers, the video content in the node containers can be circularly played through the node containers, node objects do not need to be frequently created and recovered, video playing smoothness is improved, and the video content of the latest historical node can be conveniently and quickly viewed; after the first preset number of video nodes are loaded and played, the next batch of video nodes are obtained according to the first preset number, so that all resources of video to be carousel are not required to be stored in the memory space, the condition that the video carousel is blocked due to the fact that too much memory space is occupied is avoided, and the smoothness of video carousel is improved.
Further, the obtaining the sliding distance of the video node includes:
the position of the video node is adjusted in real time by sliding the video node;
and at the end of the sliding, calculating the sliding distance according to the initial touch position of the sliding and the end touch position of the sliding.
From the above description, the position of the video node is adjusted in real time in the process of sliding the video node, and the sliding distance is calculated by the initial touch position and the end touch position in the sliding process, so that the video node can slide in real time, and the smoothness of video sliding is ensured.
Further, the determining whether the sliding distance is greater than a threshold value, if so, specifically includes:
setting a sliding animation;
judging whether the sliding distance is larger than a distance threshold value, if so, taking the video node selected after sliding as a current node, increasing the sliding distance until the sliding distance is up to the middle position of the current node, and playing the sliding animation in the sliding process;
if not, reducing the sliding distance until all the video nodes are restored to the position before sliding, and playing the sliding animation in the sliding process.
According to the above description, whether the next video node can be switched is judged according to the sliding distance, and the continuous video switching is realized by changing the sliding distance and playing the sliding animation, so that the user experience is improved.
Further, the loading and sequentially playing the node videos corresponding to the video nodes in the node container includes:
judging whether node videos corresponding to the video nodes exist in a cache, if so, acquiring the node videos from the cache, and if not, downloading the node videos from a network;
if the node video of the current node is cached to a preset percentage, starting to play the node video content, and suspending the node video in the rest node containers.
As can be seen from the above description, the node video content of the current node can be played when the node video of the current node is buffered to a preset percentage, and the node videos in the rest node containers are paused to be buffered, so that the buffering pressure can be reduced, and the smoothness of carousel is ensured.
Further, the method further comprises the following steps:
and judging whether the number of the node videos stored in the cache exceeds a number threshold, if so, deleting the node videos which are not played for the longest time in the cache.
As can be seen from the above description, the most recently and most unused algorithm is used for cache management, so that the node video which is not played for the longest time can be cleaned, and the cache pressure is reduced.
Referring to fig. 2, another embodiment of the present invention provides a video carousel switching terminal, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the following steps when executing the computer program:
presetting a first preset number of video nodes and a second preset number of node containers, wherein the second preset number is smaller than the first preset number;
sequentially adding one video node into each node container, loading and sequentially playing node videos corresponding to the video nodes in the node containers;
acquiring the sliding distance of the sliding video node, judging whether the sliding distance is larger than a threshold value, if so, taking the sliding video node as a current node, and if the current node does not exist in the node container, replacing the node video farthest from the current node in the node container with the node video of the current node;
and judging whether the first preset number of video nodes of the batch are loaded and played, if so, acquiring the next batch of the first preset number of video nodes, adding the newly acquired video nodes into the corresponding node containers, and loading and playing.
As can be seen from the above description, a first preset number of video nodes and a second preset number of node containers are preset, video nodes are sequentially added in the node containers, and node videos corresponding to the video nodes are loaded and sequentially played; by limiting the number of node containers and dynamically replacing the nodes in the node containers, the video content in the node containers can be circularly played through the node containers, node objects do not need to be frequently created and recovered, video playing smoothness is improved, and the video content of the latest historical node can be conveniently and quickly viewed; after the first preset number of video nodes are loaded and played, the next batch of video nodes are obtained according to the first preset number, so that all resources of video to be carousel are not required to be stored in the memory space, the condition that the video carousel is blocked due to the fact that too much memory space is occupied is avoided, and the smoothness of video carousel is improved.
Further, the obtaining the sliding distance of the video node includes:
the position of the video node is adjusted in real time by sliding the video node;
and at the end of the sliding, calculating the sliding distance according to the initial touch position of the sliding and the end touch position of the sliding.
From the above description, the position of the video node is adjusted in real time in the process of sliding the video node, and the sliding distance is calculated by the initial touch position and the end touch position in the sliding process, so that the video node can slide in real time, and the smoothness of video sliding is ensured.
Further, the determining whether the sliding distance is greater than a threshold value, if so, specifically includes:
setting a sliding animation;
judging whether the sliding distance is larger than a distance threshold value, if so, taking the video node selected after sliding as a current node, increasing the sliding distance until the sliding distance is up to the middle position of the current node, and playing the sliding animation in the sliding process;
if not, reducing the sliding distance until all the video nodes are restored to the position before sliding, and playing the sliding animation in the sliding process.
According to the above description, whether the next video node can be switched is judged according to the sliding distance, and the continuous video switching is realized by changing the sliding distance and playing the sliding animation, so that the user experience is improved.
Further, the loading and sequentially playing the node videos corresponding to the video nodes in the node container includes:
judging whether node videos corresponding to the video nodes exist in a cache, if so, acquiring the node videos from the cache, and if not, downloading the node videos from a network;
if the node video of the current node is cached to a preset percentage, starting to play the node video content, and suspending the node video in the rest node containers.
As can be seen from the above description, the node video content of the current node can be played when the node video of the current node is buffered to a preset percentage, and the node videos in the rest node containers are paused to be buffered, so that the buffering pressure can be reduced, and the smoothness of carousel is ensured.
Further, the method further comprises the following steps:
and judging whether the number of the node videos stored in the cache exceeds a number threshold, if so, deleting the node videos which are not played for the longest time in the cache.
As can be seen from the above description, the most recently and most unused algorithm is used for cache management, so that the node video which is not played for the longest time can be cleaned, and the cache pressure is reduced.
The video carousel switching method and the terminal are suitable for all video carousel switching products, and can improve the smoothness of video carousel, and the method and the terminal are described by the following specific embodiments:
example 1
Referring to fig. 1, 3 to 5, a video carousel switching method includes the steps of:
s1, presetting a first preset number of video nodes and a second preset number of node containers, wherein the second preset number is smaller than the first preset number.
Specifically, in this embodiment, 5 video nodes and 3 node containers are preset.
S2, adding one video node in each node container in sequence, loading and playing the node video corresponding to the video node in the node container in sequence.
The loading and sequentially playing the node videos corresponding to the video nodes in the node container comprises the following steps:
judging whether node videos corresponding to the video nodes exist in a cache, if so, acquiring the node videos from the cache, and if not, downloading the node videos from a network;
if the node video of the current node is cached to a preset percentage, starting to play the node video content, and suspending the node video in the rest node containers.
Specifically, when a user starts to view the video, the user enters a playing page, 3 child node containers are preloaded, video contents corresponding to the loaded video nodes are sequentially pre-cached in the containers according to the sequence of the video nodes, and the user starts to play automatically after waiting for the video in the currently displayed node container to be cached to a playable percentage. And preferentially caching the video of the current node, and starting to cache the video of the rest nodes after waiting for the current node to play.
When the video resource is acquired, the video resource is acquired from the local cache through video management, if the video exists in the local cache, the video resource is directly loaded into the memory, otherwise, the video resource is acquired from the network.
S3, acquiring the sliding distance of the video node, judging whether the sliding distance is larger than a threshold value, if so, taking the video node selected after sliding as a current node, and if the current node does not exist in the node container, replacing the node video farthest from the current node in the node container with the node video of the current node.
The step of obtaining the sliding distance of the video node includes:
the position of the video node is adjusted in real time by sliding the video node;
and at the end of the sliding, calculating the sliding distance according to the initial touch position of the sliding and the end touch position of the sliding.
Specifically, referring to fig. 3, node containers are created in the cyclic switching module, wherein each node container can independently display the content of a video, when a user slides up and down a screen, the Y axes of all nodes are actively updated, the sliding distance is calculated according to the initial touch position of the user and the current touch position, the difference value calculation is performed on the Y axes of all nodes under the current video list through the distance, and the sliding phenomenon generated by all current video nodes according to the touch position of the user is shown.
Judging whether the sliding distance is larger than a threshold value or not, if so, taking the video node selected after sliding as the current node specifically comprises:
setting a sliding animation;
judging whether the sliding distance is larger than a distance threshold value, if so, taking the video node selected after sliding as a current node, increasing the sliding distance until the sliding distance is up to the middle position of the current node, and playing the sliding animation in the sliding process;
if not, reducing the sliding distance until all the video nodes are restored to the position before sliding, and playing the sliding animation in the sliding process.
Specifically, referring to fig. 3 and 4, when the user stops sliding, judging whether the display of the next node is switched according to the sliding distance, and if the sliding distance is less than one half of the height of the current node container, restoring all the nodes; the method mainly comprises the steps of mainly controlling mobile animations of all nodes in a video list in a mobile module, updating the positions of the nodes according to the sliding distance of a user by setting the positions of the nodes, showing the sliding phenomenon of the video list, setting 5 nodes in the currently displayed video list, enabling a small number of nodes to be beneficial to quickly updating the positions of all the nodes, avoiding a large number of calculations, replacing videos in the nodes which are not displayed by data processing after the movement is finished, enabling the user to feel smooth sliding experience by playing the animations, switching to the next video when the touch distance of the user is large enough, and setting the sliding animation of 0.25S when switching the next video; when the distance is not enough, the user can restore to the original position, and the sliding animation needs to be played, so that the user can have a continuous experience visually.
And taking the video node selected after sliding as a current node, and if the current node does not exist in the node container, replacing the node video furthest from the current node in the node container with the node video of the current node.
Specifically, if the user slides upwards and takes the video node selected after sliding as the current node, judging whether the current node exists in the node container, if so, not modifying the node in the node container, if not, replacing the node video furthest from the current node in the node container with the node video of the current node, for example, the current node is a third video node, changing the current node into a fourth video node after the upward scrolling is finished, replacing the position of the first video node with the fourth video node after the sliding is finished, and correspondingly replacing the video in the node by data processing; if the user slides downwards, resetting and replacing a fourth video node with the first video node, wherein the processing of video data in the node is the same as the upwards sliding processing; after the setting is completed, video circulation carousel can be realized, and repeated creation and destruction of a large number of nodes are reduced.
S4, judging whether the first preset number of video nodes of the batch are loaded and played, if yes, acquiring the next batch of the first preset number of video nodes, adding the newly acquired video nodes into the corresponding node containers, and loading and playing.
Specifically, only after all videos of the current circulation carousel are loaded and played, loading subsequent videos according to a first preset number is continued, otherwise, no new videos are loaded, if the first preset number is not set, all videos are required to be loaded at one time or only one video is required to be loaded at one time, all videos occupy a high network at one time, and memory bottleneck is easily caused by the fact that the videos occupy memory; only one video is loaded, the video is required to be requested during each playing, the video is easy to be blocked when the network fluctuation is large, and poor user experience can be caused.
Example two
Referring to fig. 5, the difference between the present embodiment and the first embodiment is that how to store the loaded video is further defined, specifically:
and judging whether the number of the node videos stored in the cache exceeds a number threshold, if so, deleting the node videos which are not played for the longest time in the cache.
In this embodiment, the video may be cached to the local while being played during loading. When the number of the videos cached at the same time at present exceeds a threshold value, judging whether the video is the longest in all videos or not according to the time of playing the video last time, if so, cleaning the video from the current memory, and preloading in advance until the next time.
Example III
Referring to fig. 2, a video carousel switching terminal includes a memory, a processor, and a computer program stored in the memory and capable of running on the processor, where the processor implements the steps of the video carousel switching method according to the first or second embodiments when executing the computer program.
In summary, according to the video carousel switching method and the terminal provided by the invention, the first preset number of video nodes and the second preset number of node containers are preset, the video nodes are sequentially added in the node containers, and the node videos corresponding to the video nodes are loaded and sequentially played, wherein the rest nodes are cached when the current node is cached to a preset percentage and begins to play, so that the caching pressure is reduced, and the promotion of the flow field degree is facilitated; by limiting the number of node containers and dynamically replacing the nodes in the node containers, the video content in the node containers can be circularly played through the node containers, node objects do not need to be frequently created and recovered, video playing smoothness is improved, and the video content of the latest historical node can be conveniently and quickly viewed; after the sliding is finished, judging whether to switch to the next video node or restore to the node position before the sliding according to the sliding distance, and adding a sliding animation in the moving process to enable the sliding process to be smoothly carried out and improve the experience of a user; after the first preset number of video nodes are loaded and played, the next batch of video nodes are obtained according to the first preset number, so that all resources of video to be carousel are not required to be stored in the memory space, the condition that the video carousel is blocked due to the fact that too much memory space is occupied is avoided, and the smoothness of video carousel is improved.
The foregoing description is only illustrative of the present invention and is not intended to limit the scope of the invention, and all equivalent changes made by the specification and drawings of the present invention, or direct or indirect application in the relevant art, are included in the scope of the present invention.