Disclosure of Invention
An object of the present application is to provide an online audio playing method and device, so as to implement that a playing device with low hardware configuration can play rich audio resources online without downloading or saving a complete audio file.
According to an aspect of the present application, an online audio playing method is provided, which is applied to a playing device side, wherein the method includes:
establishing an audio buffer area in an existing executable memory of the playing device, wherein the playing device further comprises an audio player and a playing buffer area corresponding to the audio player;
downloading a target audio file from a target server to the audio cache region in a segmented manner in a breakpoint continuous transmission manner, and writing the file content of the downloaded target audio file in the audio cache region into a playing cache region according to the segmented sequence of the breakpoint continuous transmission manner when the audio cache region is full;
and playing the file contents of the playing buffer area in sequence through the audio player.
Further, the above online audio playing method based on low hardware configuration further includes, before establishing an audio buffer in an existing executable memory of the playing device:
acquiring the highest play code rate which can be supported by the play equipment;
determining a first preset cache length of the audio cache region according to the highest playing code rate;
wherein, the establishing an audio buffer area in the existing executable memory of the playing device includes:
and correspondingly creating an audio cache region with the first preset cache length in an existing executable memory of the playing device.
Further, the above online audio playing method based on low hardware configuration further includes, before establishing an audio buffer in an existing executable memory of the playing device:
acquiring the playing code rate of each audio file in all the audio files;
determining different playing levels of the playing code rate according to the playing code rate of each audio file;
determining different second preset cache lengths of the audio cache regions corresponding to different playing levels;
wherein, the establishing an audio buffer area in the existing executable memory of the playing device includes:
acquiring a target playing code rate of the target audio file;
determining a target playing level to which the target playing code rate belongs;
and correspondingly creating an audio cache region with a second preset cache length of the target corresponding to the target playing level in the existing executable memory of the playing device.
Further, in the above online audio playing method based on low hardware configuration, when the audio buffer is full, after writing the file content of the downloaded target audio file in the audio buffer into the playing buffer according to the segmentation sequence performed in the breakpoint resuming manner, the method further includes:
judging whether the residual memory of the audio cache region reaches a preset memory threshold value in real time,
if yes, continuously downloading the residual file content of the target audio file from the target server to the audio cache region in a segmented manner in a breakpoint continuous transmission mode until the audio cache region is full or the target audio file is completely downloaded.
Further, the above online audio playing method based on low hardware configuration further includes:
monitoring the downloading rate of the target audio file from the server in a segmented manner;
determining whether the download rate is less than a preset download rate threshold,
and if so, sending a network connection request to a server storing the target audio file.
Further, the method for playing the online audio based on the low-hardware configuration, where the sending a network connection request to the server storing the target audio file includes:
and sending the network connection request to the target server.
Further, the method for playing the online audio based on the low-hardware configuration, where the sending a network connection request to the server storing the target audio file includes:
and sending the network connection request to a target history server in a plurality of history servers cached in the playing device.
According to another aspect of the present application, there is also provided a non-volatile storage medium having computer-readable instructions stored thereon, which, when executed by a processor, cause the processor to implement the above-mentioned online audio playing method.
According to another aspect of the present application, there is also provided an online audio playing device, wherein the device includes:
one or more processors;
a non-volatile storage medium for storing one or more computer-readable instructions,
when executed by the one or more processors, cause the one or more processors to implement an online audio playback method as described above.
Compared with the prior art, the method and the device have the advantages that an audio cache region is established in the existing executable memory of the playing device, and the playing device further comprises an audio player and a playing cache region corresponding to the audio player; downloading a target audio file from a target server to the audio cache region in a segmented manner in a breakpoint continuous transmission manner, and writing the file content of the downloaded target audio file in the audio cache region into a playing cache region according to the segmented sequence of the breakpoint continuous transmission manner when the audio cache region is full; the file contents of the playing cache region are played in sequence through the audio player, so that the playing equipment with low hardware configuration can play rich audio resources on line under the condition of not downloading or storing complete audio files.
Detailed Description
The present application is described in further detail below with reference to the attached figures.
In a typical configuration of the present application, the terminal, the device serving the network, and the trusted party each include one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include forms of volatile memory in a computer readable medium, Random Access Memory (RAM) and/or non-volatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM). Memory is an example of a computer-readable medium.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include non-transitory computer readable media (transient media), such as modulated data signals and carrier waves.
As shown in fig. 1, a flow diagram of an online audio playing method according to an aspect of the present application is shown. The online audio playing method is applied to a playing device, and comprises the following steps: step S11, step S12, and step S13 specifically include the steps of:
step S11, an audio buffer area is established in the existing executable memory of the playing device, and the playing device also comprises an audio player and a playing buffer area corresponding to the audio player; here, the audio buffer is a continuous block of Memory space applied in an existing executable Memory (i.e., Random Access Memory (RAM)), which is referred to as a cache, and the implementation manner includes, but is not limited to, dynamically applying for N Bytes of Memory space through a Memory application interface of a real-time operating system RTOS, for example, through a malloc (i.e., dynamically allocating Memory) function, or determining a Byte type as a static array with a length of N, where the Byte type is a data type, and the applicable system includes, but is not limited to, an RTOS system, and is also applicable to a non-RTOS system and a system supporting a larger RAM and a larger Flash; and after the audio buffer area is established, controlling the addition and elimination of data in the audio buffer in a management mode of a circular queue.
Step S12, downloading the target audio file from the target server to the audio buffer area in a segmented manner by adopting a breakpoint continuous transmission manner, and writing the file content of the downloaded target audio file in the audio buffer area into a playing buffer area according to the segmented sequence carried out by the breakpoint continuous transmission manner when the audio buffer area is full; here, the GET method in the Hypertext Transfer Protocol (HTTP) or the Hyper Text Transfer Protocol over secure session Layer (HTTPs) may specify the start position and length characteristics of the file content to be acquired, so that the target audio file is segmented from the target server and presented in the audio cache region, and breakpoint resume may be performed.
In step S12, the File Transfer Protocol (FTP) is used as the breakpoint resume, and the FTP client software breakpoint resume refers to that when downloading or uploading, a downloading or uploading task (a File or a compressed packet) is artificially divided into several parts, each part is uploaded or downloaded by using a thread, if a network failure occurs, the uncompleted part can be uploaded or downloaded from the uploaded or downloaded part without uploading or downloading from the beginning, so that the user can save time and increase speed.
Step S13, playing the file contents of the play buffer in sequence by the audio player. Here, the file contents of the play buffer are played by the audio player in the order written from the audio buffer to the play buffer.
Through the steps S11 to S13, the present application establishes an audio buffer in an existing executable memory of a playback device, where the playback device further includes an audio player and a corresponding playback buffer; downloading a target audio file from a target server to the audio cache region in a segmented manner in a breakpoint continuous transmission manner, and writing the file content of the downloaded target audio file in the audio cache region into a playing cache region according to the segmented sequence of the breakpoint continuous transmission manner when the audio cache region is full; the file contents of the playing cache region are played in sequence through the audio player, so that the playing equipment with low hardware configuration can play rich audio resources on line under the condition of not downloading or storing complete audio files.
For example, in a preferred embodiment of the present application, a continuous memory space is applied as an audio buffer in an executable memory RAM of a low-hardware-configuration playing device, and data addition and elimination in the audio buffer are controlled by a management manner of a circular queue, a target audio file is downloaded from a target server to the audio buffer, wherein when the target audio file is downloaded, file contents specifying start positions and length characteristics can be downloaded from the target server by a GET method in an HTTP (or HTTPs) protocol, so as to realize that the target audio file is downloaded to the audio buffer in segments, and when the audio buffer is full, the file contents of the target audio file already downloaded by the audio buffer are written into the playing buffer in the order of downloading from the target server to the audio buffer, enabling an audio player in the playing device to play the file content in the playing cache region, playing the file content according to the sequence written in the playing cache region when the audio player plays the file content in the playing cache region, and continuously writing the file content of the target audio file into the playing cache region by the audio cache region while the audio player plays the file content in the playing cache region, so as to ensure that the audio player does not have the condition of interruption or blockage in the playing process.
Next, in the above embodiment of the present application, before the step S11 establishes an audio buffer in the existing executable memory of the playback device, the method further includes:
acquiring the highest play code rate which can be supported by the play equipment;
determining a first preset cache length of the audio cache region according to the highest playing code rate;
it should be noted that, establishing an audio buffer area in an existing executable memory of a playing device may be implemented by, for example, predicting an upper limit of a playing code rate of an audio file that can be supported by the playing device (i.e., a supportable highest playing code rate), and then setting a fixed first preset buffer length according to the highest playing code rate of the audio file that can be supported by the playing device, so that the audio buffer area may be established in the existing executable memory of the playing device according to the first preset buffer length.
Wherein, the establishing an audio buffer area in the existing executable memory of the playing device includes:
and correspondingly creating an audio cache region with the first preset cache length in an existing executable memory of the playing device.
In order to save resources for adjusting the buffer length of the audio buffer by the playing device, before the audio buffer is established in the existing executable memory of the playing device, the highest play code rate which can be supported by the playing device can be directly acquired, and then the first preset buffer length of the audio buffer is determined according to the highest play code rate, so that when the target audio file with any play code rate is acquired and the buffer needs to be played later, the audio buffer for the target audio file to be cached can be correspondingly established in the existing executable memory of the playing device directly according to the first preset buffer length, and the buffer length of the audio buffer is the first preset buffer length, thereby not only saving resources for calculating the buffer length of the created audio buffer each time, but also meeting the highest play code rate which can be supported by the playing device, the playing requirements of the user are met as much as possible.
In a preferred embodiment of the present application, the highest play code rate may be a highest play code rate of any size that can be supported by a playing device, and the maximum time that can be supported by the playing device under the current highest play code rate is determined according to the highest play code rate, in the present application, the supportable highest play code rate is preferably 300kbps, if the maximum time that can be supported by the playing device when the highest play code rate is 300kbps is 30s, a first preset buffer length is determined according to the highest play code rate 300kbps, and an audio buffer corresponding to the first preset buffer length is established in an existing executable memory of the playing device, for example, the size of the audio buffer is 300kbps 30s/8 — 1125kb.
Next, in the foregoing embodiments of the present application, before establishing an audio buffer in an existing executable memory of a playback device, the method further includes:
acquiring the playing code rate of each audio file in all the audio files;
determining different playing levels of the playing code rate according to the playing code rate of each audio file;
determining different second preset cache lengths of the audio cache regions corresponding to different playing levels;
it should be noted that, an audio buffer is established in the existing executable memory of the playing device, and may also be implemented in the following manner, before each audio file is downloaded from the server, an audio buffer needs to be established in the existing executable memory of the playing device, before the audio file needs to be downloaded from the server next time, the audio buffer that has been established last time is released first, and the audio buffer is established according to the step of establishing the audio buffer each time; further, the playing code rate of each audio file is obtained, different playing levels of the playing code rate are determined according to the playing code rate of each audio file, wherein the presentation form of the playing level includes but is not limited to a buffer area or a specific buffer length value, and different second preset buffer lengths are determined according to different playing levels, so that different playing code rates can be matched with and create audio buffer areas with different buffer lengths, and the buffer requirements of different playing code rates in an actual application scene are met.
Wherein, the establishing an audio buffer area in the existing executable memory of the playing device includes:
acquiring a target playing code rate of the target audio file;
determining a target playing level to which the target playing code rate belongs;
and correspondingly creating an audio cache region with a second preset cache length of the target corresponding to the target playing level in the existing executable memory of the playing device.
In order to save the space resources of the executable memory in the playback device, before the audio buffer is established in the existing executable memory of the playback device, before playing the target audio file, the target playing code rate of the target audio file required to be downloaded at the current time can be obtained, the playing level at the current time is determined according to the target playing code rate of the target audio file at the current time, then, determining a current target second preset cache length according to the current playing level, establishing a current audio cache region in an existing executable memory of the playing device according to the target second preset cache length, and the cache length of the audio cache region is the second preset cache length, so that the occupation of the executable memory space in the playing equipment can be reduced as much as possible, the playing fluency of the audio file can be ensured, and the cache requirements of different playing code rates can be met.
For example, in a preferred embodiment of the present application, the target playback bitrate of the target audio file to be played each time may include any size, and a time length corresponding to the target playback bitrate of the target audio file is preset, where the time length may include any value, in this application, the target playback bitrate of the current target audio file is preferably 50kbps, and the preset time length is 30s, and then a second preset buffer length is determined when the playback bitrate at the time length of 30s is 50kbps, and an audio buffer area corresponding to the second preset buffer length is established in an existing executable memory of the playback device, where the size of the audio buffer area is 50kbps 30s/8 187.5 KB.
Next to the foregoing embodiment of the present application, in step S12, when the audio buffer is full, after writing the file content of the downloaded target audio file in the audio buffer into a play buffer according to the segmentation sequence performed in the breakpoint resuming manner, the method further includes:
judging whether the residual memory of the audio cache region reaches a preset memory threshold value in real time, wherein the preset memory threshold value comprises but is not limited to any memory value;
if yes, continuously downloading the residual file content of the target audio file from the target server to the audio cache region in a segmented manner in a breakpoint continuous transmission mode until the audio cache region is full or the target audio file is completely downloaded.
As shown in fig. 2, when the audio buffer is full, after the file content of the downloaded target audio file in the audio buffer is written into the play buffer in a segmented sequence according to the breakpoint continuous transmission manner, it is further required to determine whether the remaining memory of the audio buffer reaches a preset memory threshold in real time. The real-time judgment is to know the cache residue in the audio cache region in time so as to download the file content of the target audio file from the server to the audio cache region in time, thereby ensuring the fluency of subsequent playing; the preset memory threshold represents the consumption of the file content of the downloaded target audio file in the audio cache region, the larger the preset memory threshold is, the more the consumption of the file content of the downloaded target audio file is, and the smaller the preset memory threshold is, the less the consumption of the file content of the downloaded target audio file is; the preset memory threshold may be set according to different conditions of a network, for example, in a case that a network condition is good, the preset memory threshold may be set to be larger, because if the network condition is good, even if the file content consumption of the downloaded target audio file is large, the file content can be supplemented, and in a case that the network condition is poor, the preset memory threshold may be set to be smaller, because if the network condition is poor, in order to enable the consumption of the file content of the downloaded target audio file in the audio cache region to be supplemented in time, it is avoided that the file content consumption speed of the downloaded target audio file is faster than the speed of downloading from the server, which results in playing card pause, the preset memory threshold needs to be set to be smaller.
If the real-time judgment result is: and if the residual memory of the audio cache region reaches a preset memory threshold value, continuously downloading the residual file content of the target audio file from the target server to the audio cache region in a segmented manner in a breakpoint continuous transmission mode until the audio cache region is full or the target audio file is completely downloaded, so that the problems that the audio file cannot be downloaded in time and the playing is blocked or the playing quality is poor and the like caused by the fact that the file content cached in the audio cache region is completely written into the playing cache region are avoided, and smooth playing of the audio player is ensured. If the real-time judgment result is: and if the residual memory of the audio cache region does not reach the preset memory threshold value, continuously writing the file contents of the target audio file cached in the audio cache region into the playing cache region in sequence, and temporarily not continuously downloading the residual file contents of the target audio file from the target server to the audio cache region.
For example, in a preferred embodiment of the present application, if the mobile terminal is in a network with a faster network speed such as 4G, a preset memory threshold may be set as 2/3 of the size of an audio buffer, the size of the remaining memory of the audio buffer may be determined in real time, and if the size of the remaining memory reaches 2/3 of the size of the preset buffer, the remaining file content of the target audio file is downloaded from the target server to the audio buffer in a segmented manner continuously in a breakpoint continuous manner until the audio buffer is full or the target audio file is completely downloaded, so as to avoid that the audio file cannot be downloaded in time and the problem of playing card pause or poor playing quality occurs after the file content cached in the audio buffer is completely written into the playing buffer, thereby ensuring smooth playing of the audio player; if the size of the residual memory does not reach 2/3 the size of the preset cache region, continuing to write the file contents of the target audio file cached in the audio cache region into the playing cache region in sequence, and temporarily not needing to continue downloading the residual file contents of the target audio file from the target server to the audio cache region.
For another example, in a preferred embodiment of the present application, when in a network with a slow network speed such as 2G or 3G, the preset memory threshold may be set to 1/3 of the size of the audio buffer, the size of the remaining memory of the audio buffer may be determined in real time, and if the size of the remaining memory reaches 1/3 of the size of the preset buffer, continuously downloading the residual file content of the target audio file from the target server to the audio cache region in a segmented manner in a breakpoint continuous transmission manner until the audio cache region is full or the target audio file is completely downloaded, therefore, the problems that the audio file cannot be downloaded in time and the playing is blocked or the playing quality is poor and the like after the cached file content in the audio cache region is completely written into the playing cache region are avoided, and the smooth playing of the audio player is ensured; if the size of the residual memory does not reach 1/3 the size of the preset cache region, continuing to write the file contents of the target audio file cached in the audio cache region into the playing cache region in sequence, and temporarily not needing to continue downloading the residual file contents of the target audio file from the target server to the audio cache region.
Following the above embodiments of the present application, wherein the method further comprises:
monitoring the downloading rate of the target audio file from the server in a segmented manner;
and judging whether the download rate is smaller than a preset download rate threshold, wherein the preset download rate threshold can be set according to different conditions of the network, if the network is in a high-speed network, the preset download rate threshold can be set to be relatively larger, and if the network is in a low-speed network, the client sets the preset download rate threshold to be relatively smaller.
And if so, sending a network connection request to a server storing the target audio file.
As shown in fig. 3, during the process of caching and playing by the playing device, the downloading rate of the target audio file from the server in a segment manner needs to be monitored; in a preferred embodiment of the present application, the network monitoring function of the playing device is implemented by a code or the like, and then the timer triggering function is implemented by a timer mechanism of the RTOS itself, and a timer is set to trigger the network monitoring function of the playing device at regular time, so as to be able to monitor the downloading rate of the target audio file from the server in a segmented manner at regular time.
As shown in fig. 3, after the download rate of the target audio file is monitored, it is determined whether the download rate is less than a preset download rate threshold,
if so, sending a network connection request to a server storing the target audio file, otherwise, not interfering the caching and playing of the playing equipment, and monitoring the downloading rate of the target audio file to be carried out next time.
Here, the download rate includes, but is not limited to, the speed, the flow rate, the time delay, etc. of the data received by the playback device from the server, i.e. the number of bytes transmitted from the server to the playback device in a unit time (usually within 1 second, but not limited in this application); after the network monitoring function is started, the number of bytes transmitted from the server to the playing device in unit time is monitored, if the downloading rate is lower than the preset downloading rate threshold value continuously for N seconds (in order to judge the downloading rate in time, the value of N is lower than 10 seconds as far as possible, but is not limited in the application), it can be considered that the connection between the playing device and the current server is in problem, the server storing the target audio file can be actively reconnected, wherein, the server storing the target audio file can be a currently connected server or other servers storing the target audio file, so as to avoid the situation that the speed can not be recovered after the same server is reconnected, therefore, the playing device and the server recover a normal connection state, and the downloading rate of data is guaranteed; if the playing device has reconnected with the server for many times, that is, if the connection frequency of the playing device and the server is too high, it indicates that the current network condition is unstable, the time interval of the timer can be adjusted, and the interval time is appropriately shortened, so that the network monitoring is more accurate.
For example, in a preferred embodiment of the present application, if the preset download rate threshold is 100KB/s, the network monitoring function is started, and the number of bytes transmitted from the server to the playback device per second is detected, and if the download rate threshold is 5s continuously, the rate is lower than 100KB/s, it may be considered that there is a problem in connection between the playback device and the current server at this time, and therefore the playback device needs to actively reconnect to the current server, or reconnect to another server storing the target audio file, so that the playback device and the server recover to a normal connection state, thereby ensuring the download rate of data.
Following the above-mentioned embodiments of the present application, the sending a network connection request to a server storing the target audio file includes:
and sending the network connection request to the target server.
For example, when the download rate is less than the preset download threshold, the playback device may send a network connection request to the current target server again, so as to recover the normal connection state between the playback device and the target server, and ensure the data transmission rate between the playback device and the target server.
Following the above-mentioned embodiments of the present application, the sending a network connection request to a server storing the target audio file includes:
and sending the network connection request to a target history server in a plurality of history servers cached in the playing device. Here, when the network connection request is resent, if the IP addresses of the plurality of servers are cached before, one of the IP addresses of the plurality of servers cached before may be reselected for connection, which may avoid performing domain name resolution for each connection, thereby speeding up the speed of the playback device obtaining data from the server, and improving the fluency of obtaining the file content of the audio file and the user experience.
For example, when the download rate is less than the preset download threshold, if the IP addresses of the servers are cached before, the playback device may reselect one of the IP addresses cached before to send the network connection request, so as to avoid a situation that the download rate cannot be recovered after reconnecting the same server.
According to another aspect of the present application, there is also provided a non-volatile storage medium having computer-readable instructions stored thereon, which, when executed by a processor, cause the processor to implement the above-mentioned online audio playing method.
According to another aspect of the present application, there is also provided an online audio playing device, wherein the device includes:
one or more processors;
a non-volatile storage medium for storing one or more computer-readable instructions,
when executed by the one or more processors, cause the one or more processors to implement an online audio playback method as described above.
Here, for details of each embodiment of the online audio playing device, reference may be specifically made to corresponding parts of the embodiment of the online audio playing method, and details are not described herein again.
In summary, the present application establishes an audio buffer area in an existing executable memory of a playing device, where the playing device further includes an audio player and a playing buffer area corresponding to the audio player; downloading a target audio file from a target server to the audio cache region in a segmented manner in a breakpoint continuous transmission manner, and writing the file content of the downloaded target audio file in the audio cache region into a playing cache region according to the segmented sequence of the breakpoint continuous transmission manner when the audio cache region is full; the file contents of the playing cache region are played in sequence through the audio player, so that the playing equipment with low hardware configuration can play rich audio resources on line under the condition of not downloading or storing complete audio files.
It should be noted that the present application may be implemented in software and/or a combination of software and hardware, for example, implemented using Application Specific Integrated Circuits (ASICs), general purpose computers or any other similar hardware devices. In one embodiment, the software programs of the present application may be executed by a processor to implement the steps or functions described above. Likewise, the software programs (including associated data structures) of the present application may be stored in a computer readable recording medium, such as RAM memory, magnetic or optical drive or diskette and the like. Additionally, some of the steps or functions of the present application may be implemented in hardware, for example, as circuitry that cooperates with the processor to perform various steps or functions.
In addition, some of the present application may be implemented as a computer program product, such as computer program instructions, which when executed by a computer, may invoke or provide methods and/or techniques in accordance with the present application through the operation of the computer. Program instructions which invoke the methods of the present application may be stored on a fixed or removable recording medium and/or transmitted via a data stream on a broadcast or other signal-bearing medium and/or stored within a working memory of a computer device operating in accordance with the program instructions. An embodiment according to the present application comprises an apparatus comprising a memory for storing computer program instructions and a processor for executing the program instructions, wherein the computer program instructions, when executed by the processor, trigger the apparatus to perform a method and/or a solution according to the aforementioned embodiments of the present application.
It will be evident to those skilled in the art that the present application is not limited to the details of the foregoing illustrative embodiments, and that the present application may be embodied in other specific forms without departing from the spirit or essential attributes thereof. The present embodiments are therefore to be considered in all respects as illustrative and not restrictive, the scope of the application being indicated by the appended claims rather than by the foregoing description, and all changes which come within the meaning and range of equivalency of the claims are therefore intended to be embraced therein. Any reference sign in a claim should not be construed as limiting the claim concerned. Furthermore, it is obvious that the word "comprising" does not exclude other elements or steps, and the singular does not exclude the plural. A plurality of units or means recited in the apparatus claims may also be implemented by one unit or means in software or hardware. The terms first, second, etc. are used to denote names, but not any particular order.