Audio playback method, device, electronic device, and storage medium
Through the coordination of audio loading instance and channel instance, the problem of repeated playback disorder caused by multiple audio files triggering playback is solved, and a stable audio playback effect is achieved.
Patent Information
- Application Number
- CN202310152362.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-14
- Publication Date
- 2025-08-15
- Estimated Expiration
- 2043-02-14
AI Technical Summary
In the prior art, the same audio file is prone to misplaying repeatedly when it is triggered to play multiple times.
By obtaining the audio loading instance and the audio channel instance, we can determine whether the audio resource is loading. When the loading is not completed, add the audio channel instance to the preset list. After the loading is completed, play it uniformly to avoid repeated playback.
It effectively avoids repeated playback incorrectly when the same audio file is triggered multiple times, and improves the stability and efficiency of audio playback.
Smart Images

Figure CN116107538B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of audio processing technology, and in particular to an audio playback method, device, electronic device and storage medium. Background Art
[0002] In web games, there will be different background music or special effect music. The audio objects provided by the game engine can control the playback properties of the audio files.
[0003] Since audio files cannot be played before loading is complete, existing audio file playback technology usually loads the audio file after triggering the audio playback instruction and monitors the loading status of the audio file. When the message of the audio file loading completion is monitored, the interface for playing the audio file is called to play the corresponding audio file. In this way, if the playback instruction of the same audio file is triggered multiple times, the audio file will be requested to load each time it is triggered, and it will be played immediately after loading is completed, resulting in the problem of audio playback confusion. It can be seen that the existing technology has the technical problem of repeated playback confusion when controlling the same audio file to be triggered to play multiple times. Summary of the Invention
[0004] In view of this, the purpose of the present invention is to provide an audio playback method, device, electronic device and storage medium to avoid the technical problem of repeated playback confusion when the same audio file is triggered to play multiple times.
[0005] In a first aspect, an embodiment of the present invention provides an audio playback method, comprising: in response to a playback instruction of a target audio resource, obtaining an audio loading instance corresponding to the target audio resource, the audio loading instance being used to load the target audio resource; playing the target audio resource through an audio channel instance corresponding to the audio loading instance, the audio channel instance being used to set the playback properties of the target audio resource; if the target audio resource cannot be played, adding the audio channel instance to a preset audio channel instance list, the preset audio channel instance list including at least one audio channel instance corresponding to the target audio resource; in response to a loading completion instruction of the target audio resource, playing the target audio resource through the preset audio channel instance list.
[0006] In a second aspect, an embodiment of the present invention provides an audio playback device, which includes: a response module for obtaining an audio loading instance corresponding to the target audio resource in response to a playback instruction of the target audio resource, wherein the audio loading instance is used to load the target audio resource; a setting module for playing the target audio resource through an audio channel instance corresponding to the audio loading instance, wherein the audio channel instance is used to set the playback properties of the target audio resource; an adding module for adding the audio channel instance to a preset audio channel instance list if the target audio resource cannot be played, wherein the preset audio channel instance list includes at least one audio channel instance corresponding to the target audio resource; and a playback module for playing the target audio resource through the preset audio channel instance list in response to a loading completion instruction of the target audio resource.
[0007] In a third aspect, an embodiment of the present invention provides an electronic device, including a processor and a memory, wherein the memory stores machine-executable instructions that can be executed by the processor, and the processor executes the machine-executable instructions to implement the above-mentioned audio playback method.
[0008] In a fourth aspect, an embodiment of the present invention provides a machine-readable storage medium, which stores machine-executable instructions. When the machine-executable instructions are called and executed by a processor, the machine-executable instructions prompt the processor to implement the above-mentioned audio playback method.
[0009] The embodiments of the present invention bring the following beneficial effects:
[0010] The above-mentioned audio playback method, device, electronic device and storage medium, in response to the playback instruction of the target audio resource, obtains the audio loading instance corresponding to the target audio resource, the audio loading instance is used to load the target audio resource; the target audio resource is played through the audio channel instance corresponding to the audio loading instance, the audio channel instance is used to set the playback attribute of the target audio resource; if the target audio resource cannot be played, the audio channel instance is added to the preset audio channel instance list, the preset audio channel instance list includes at least one audio channel instance corresponding to the target audio resource; in response to the loading completion instruction of the target audio resource, the target audio resource is played through the preset audio channel instance list. In this way, after each playback instruction of the target audio resource is triggered, the target audio resource is played through the audio channel instance corresponding to the audio loading instance. If it cannot be played, it is added to the waiting queue, so that after the target audio resource is loaded, the target audio resource is played uniformly through the preset audio channel instance list, thereby avoiding the technical problem of repeated playback confusion when the same audio file is triggered to play multiple times.
[0011] Other features and advantages of the present invention will be described in the following description, and in part will become apparent from the description, or understood by practicing the present invention. The purposes and other advantages of the present invention are realized and obtained by the structures particularly pointed out in the description, claims and drawings.
[0012] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, preferred embodiments are given below and described in detail with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] In order to more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the specific embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without paying any creative work.
[0014] Figure 1 This is a flow chart of an embodiment of an audio playback method according to an embodiment of the present invention;
[0015] Figure 2 This is a flow chart of another embodiment of the audio playback method in an embodiment of the present invention;
[0016] Figure 3 A schematic diagram of an audio playback device provided by an embodiment of the present invention;
[0017] Figure 4 A schematic diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0018] To make the objectives, technical solutions, and advantages of the embodiments of the present invention more clear, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the embodiments described are only part of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work shall fall within the scope of protection of the present invention.
[0019] The terms "first," "second," "third," "fourth," and the like (if any) in the description and claims of the present invention and in the accompanying drawings are used to distinguish similar objects and are not necessarily used to describe a particular order or precedence. It should be understood that the terms used in this manner are interchangeable where appropriate so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including" or "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product, or apparatus that includes a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units that are not explicitly listed or that are inherent to these processes, methods, products, or apparatus.
[0020] In one embodiment, an embodiment of the present invention is applied to terminal web pages, such as terminal game web pages, terminal display web pages, etc. The terminal web pages can be web pages developed based on any web development engine / framework, such as egret game engine, Turbulenz game engine, AngularJS web application development framework, etc., which are not specifically limited here.
[0021] For ease of understanding, the specific process of the embodiment of the present invention is described below. Figure 1 , an embodiment of the audio playback method in the embodiment of the present invention includes:
[0022] Step S10: In response to a play instruction of a target audio resource, obtaining an audio loading instance corresponding to the target audio resource, where the audio loading instance is used to load the target audio resource;
[0023] In one embodiment, when the audio playback control of the target audio resource in the terminal webpage is touched, or when the playback conditions of the target audio resource are met, the playback instruction of the target audio resource is triggered. For example, in a web game, when the terminal user clicks the playback control of the background music, the playback instruction of the background music is responded to; or in a web game, when the terminal user clicks the button for receiving the props, the playback instruction of the sound effect file for receiving the props is responded to. The target audio resource can be a file of any audio format. The target audio resource to be loaded by the audio loading instance is specified by the audio resource identifier in the audio loading instance. The audio resource identifier can be the file name of the target audio resource, the absolute storage path of the file, the relative storage path of the file, the cache storage path of the file, the network storage location of the file, etc. The specific details are not limited here.
[0024] It is understandable that in object-oriented development, a "class" is called an "instance" after being instantiated. A class is static and does not occupy processes and memory, while an instance is dynamic and can occupy processes and memory. It is understandable that an object created based on a class is also an instance. In this embodiment, an audio loading instance is also an audio loading object. In one embodiment, the terminal responds to the play instruction of the target audio resource, obtains the audio loading instance corresponding to the target audio resource, and loads the target audio resource through the audio loading instance, wherein the audio loading instance is an instance of the audio loading class, also referred to as an audio loading object.
[0025] In one embodiment, an audio loading instance is an instantiated class created based on a terminal web page development engine, having audio loading functionality encapsulated by the terminal web page development engine and created according to the instantiation standard encapsulated by the web terminal development engine. For example, an audio loading instance created based on the egret game engine may be "new egret.Sound()," while an audio loading instance created based on the Turbulenz game engine may be "soundDevice.createSound()." The specifics are not limited here.
[0026] It should be noted that after obtaining the audio loading instance corresponding to the target audio resource, the audio loading instance is used to load the target audio resource, and then requesting to load the target audio resource. Whether the target audio resource is loaded depends on the file size of the target audio resource and the speed of the network request. In one embodiment, in order to improve the playback efficiency of the target audio resource, in response to the playback instruction of the target audio resource, it is determined whether the cache contains the target audio resource. If the cache contains the target audio resource, there is no need to obtain the audio loading instance corresponding to the target audio resource. The audio loading instance is used to load the target audio resource. Instead, the target audio resource is played directly through the audio channel instance corresponding to the audio loading instance, so that the target audio resource is played successfully.
[0027] Step S20: Play the target audio resource through the audio channel instance corresponding to the audio loading instance, where the audio channel instance is used to set the playback properties of the target audio resource;
[0028] It should be noted that an audio channel instance is also an instantiated class used to set the playback properties of a target audio resource. In one embodiment, an audio channel instance is also an instantiated class created based on the terminal web development engine, has the audio playback property setting functionality encapsulated by the terminal web development engine, and is created according to the instantiation standards encapsulated by the web terminal development engine. For example, an audio channel instance created based on the egret game engine can be "egret.SoundChannel = new egret.Sound()", while an audio channel instance created based on the Turbulenz game engine can be "loadedSound.channels". The specifics are not limited here.
[0029] It can be understood that the audio channel instance corresponds to the specified audio loading instance, and is used to set the playback properties of the target audio resource specified in the specified audio loading instance. For example, if the audio loading instance specifies the target audio resource A, and the audio channel instance corresponds to the audio loading instance, then the audio channel instance is used to set the playback properties of the target audio resource A. The specific details are not limited here.
[0030] In one embodiment, the audio channel instance is used to set the playback properties of the target audio resource, including but not limited to: the channel for audio playback / stop playback, volume, playback position, loop playback mode, etc., among which the loop playback mode can set the audio to loop once, loop multiple times, or loop infinitely, etc., which is not limited here.
[0031] It should be noted that the playback of the target audio resource can be set by an audio loading instance or by an audio channel instance. In this implementation, in order to avoid a target audio resource playback error caused by the target audio resource not being loaded completely when the target audio resource is played through the audio loading instance, the target audio resource is played through the audio channel instance corresponding to the audio loading instance, so that no error will be reported even if the target audio resource is not loaded completely, thereby reducing the error rate of audio playback.
[0032] Step S30: If the target audio resource cannot be played, the audio channel instance is added to a preset audio channel instance list, where the preset audio channel instance list includes at least one audio channel instance corresponding to the target audio resource;
[0033] In this step, if the audio channel instance corresponding to the audio loading instance cannot play the target audio resource, it means that the target audio resource has not been loaded. In this case, the audio channel instance is added to the preset audio channel instance list for setting the playback of the target audio resource when the target audio resource is loaded. In this embodiment, whether the target audio resource has been loaded can be determined without monitoring the loading progress of the audio resource, thereby reducing the impact of the loading progress of the audio resource on the audio playback effect.
[0034] It should be noted that a preset audio channel instance list corresponds to a target audio resource, that is, the same preset audio channel instance list contains at least one audio channel instance corresponding to the same target audio resource. In one embodiment, the number of audio channel instances in the preset audio channel instance list is less than or equal to the number of times the play instruction of the target audio resource is triggered, wherein the target terminal web page refers to the triggering web page of the play instruction of the target audio resource, and the number of times the play instruction of the target audio resource is triggered refers to the number of times the play instruction of the target audio resource is triggered within a life cycle of the target terminal web page. For example, a target terminal web page from opening to closing can be a life cycle, or a target terminal web page from activation (active) to uninstallation (discarded) can also be a life cycle, which is not limited here.
[0035] Step S40: In response to the instruction indicating that the target audio resource has been loaded, the target audio resource is played through the preset audio channel instance list.
[0036] In this embodiment, when the target audio resource is loaded, the target audio resource's loading completion instruction is responded to, and the playback attributes of the target audio resource are set through all audio channel instances in the preset audio channel instance list, so that the target audio resource is played. It can be understood that since the target audio resource is played through all audio channel instances in the preset audio channel instance list after the target audio resource is loaded, even if the target audio resource is triggered to play multiple times, it will not be played multiple times or at different times, thereby reducing the impact of the loading progress of the audio resource on the playback effect and improving the audio playback effect.
[0037] In one embodiment, after responding to the instruction to complete loading of the target audio resource, the playback attributes of the target audio resource can be set through all audio channel instances in the preset audio channel instance list, or the playback attributes of the target audio resource can be set through any audio channel instance in the preset audio channel instance list. Both of them are to play the target audio resource in the final playback effect, so no specific limitation is made here.
[0038] The audio playback method provided by the above embodiment plays the target audio resource through the audio channel instance corresponding to the audio loading instance each time the playback instruction of the target audio resource is triggered. If it cannot be played, it is added to the queue to be played, so that after the target audio resource is loaded, the target audio resource is played uniformly through the preset audio channel instance list, thereby avoiding the technical problem of repeated playback confusion when the same audio file is triggered to play multiple times.
[0039] See also Figure 2 Another embodiment of the audio playback method in the embodiment of the present invention includes:
[0040] Step S201: In response to a play instruction of a target audio resource, determining whether the cache contains an audio loading instance corresponding to the target audio resource;
[0041] In this step, in order to avoid the situation where the same audio file is triggered to play multiple times and the audio file is repeatedly loaded multiple times, resulting in waste and occupation of network request resources, after the play instruction of the target audio resource is triggered, it is first determined whether the cache already contains the audio loading instance corresponding to the target audio resource. If it is already contained, it means that the target audio resource has been triggered to play the instruction during the life cycle of the target terminal web page and can be directly obtained. If the cache does not contain the audio loading instance corresponding to the target audio resource, it means that the target audio resource is triggered to play the instruction for the first time during the life cycle of the target terminal web page and can be directly created. It can be understood that compared to determining whether the cache contains the target audio file, determining whether the cache contains the audio loading instance corresponding to the target audio resource is faster and more accurate, thereby improving the efficiency of audio playback.
[0042] Step S202: If the cache does not contain the audio loading instance corresponding to the target audio resource, create an audio loading instance corresponding to the target audio resource, and load the target audio resource through the audio loading instance;
[0043] It can be understood that if the cache does not contain the audio loading instance corresponding to the target audio resource, an audio loading instance corresponding to the target audio resource is created, and the target audio resource is loaded through the audio loading instance request, and the audio loading instance corresponding to the target audio resource is stored in the cache, so that when the playback instruction of the target audio resource is triggered again, the audio loading instance corresponding to the target audio resource can be directly obtained, and there is no need to repeatedly load the target audio resource, thereby improving the efficiency of audio playback and reducing the waste and occupation of network request resources.
[0044] In one embodiment, the above-mentioned loading of the target audio resource through the audio loading instance includes: sending a loading request of the target audio resource through the audio loading instance, and monitoring the loading status of the loading request through the loading status mark; when the loading status mark indicates that the target audio resource is loaded, throwing a loading completion message of the target audio resource. In this embodiment, when loading the target audio resource, the target audio resource is requested to be loaded through the audio resource identifier in the audio loading instance, and the loading status mark of the target audio resource is obtained. For example, the loading status mark can be loading, unload, a loading status code (such as 200), etc., which is not specifically limited here. Then, when the loading status mark indicates that the target audio resource is loaded, a message of the target audio resource loading completion is thrown, so that the audio loading instance or the audio channel instance corresponding to the audio loading instance captures the message and plays the target audio resource.
[0045] Step S203: If the cache contains an audio loading instance corresponding to the target audio resource, obtain the audio loading instance corresponding to the target audio resource in the cache;
[0046] It should be noted that if the cache already contains an audio loading instance corresponding to the target audio resource, the audio loading instance corresponding to the target audio resource in the cache can be directly read. In one embodiment, after reading the audio loading instance corresponding to the target audio resource cached, it is also possible to request the target audio resource to be played through the audio loading instance corresponding to the target audio resource to obtain the audio channel instance specified by the audio loading instance for subsequent setting of playback properties for the target audio resource.
[0047] In one embodiment, after step S203, it also includes: in response to the cache cleaning instruction, deleting the audio loading instance corresponding to the target audio resource in the cache, and the preset audio channel instance list corresponding to the target audio resource. In this embodiment, the cache cleaning instruction can be triggered at the end of the life cycle of the terminal web page, or at any time when the cache needs to be cleaned, and the specific timing is not limited here. When the cache cleaning instruction is triggered, the terminal clears the audio loading instance corresponding to the target audio resource, and the preset audio channel instance list corresponding to the target audio resource to free up cache space.
[0048] Step S204: Play the target audio resource through the audio channel instance corresponding to the audio loading instance, where the audio channel instance is used to set the playback properties of the target audio resource;
[0049] In one embodiment, the above step S204 includes: determining whether the audio loading instance specifies an audio channel instance; if the audio loading instance does not specify an audio channel instance, creating an audio channel instance corresponding to the audio loading instance; and playing the target audio resource through the audio channel instance corresponding to the audio loading instance. It is understandable that the audio loading instance can specify an audio channel instance. In one embodiment, when requesting to play the target audio resource through the audio loading instance, the audio channel instance returned by the request can be obtained, that is, the audio channel instance specified by the audio loading instance. In another embodiment, an audio channel instance can also be created and the created audio channel instance is assigned to the audio loading instance corresponding to the target audio resource, thereby obtaining the audio channel instance specified by the audio loading instance. It should be noted that both the audio channel instance and the audio loading instance can play the target audio resource, and the audio channel instance can set the playback properties of the target audio resource in more detail, such as volume, channel, etc., which are not specifically limited here. In this embodiment, if the audio loading instance has specified an audio channel instance, the target audio resource can be played directly through the audio channel instance specified by the audio loading instance.
[0050] In one embodiment, the above step S204 includes: monitoring whether the target audio resource has been loaded through the loading completion event of the audio loading instance; if the target audio resource has been loaded, setting the playback attributes of the target audio resource through the audio channel instance corresponding to the audio loading instance to play the target audio resource. In this embodiment, in order to determine whether the target audio resource already exists, that is, it has been loaded, the loading completion of the target audio resource is monitored through the loading completion event of the audio loading instance. The loading completion event is the response of the audio loading instance to the change of the audio loading state. When the loading state of the audio loading instance changes to loading completion, the audio loading instance can capture the change of the state through the loading completion event and respond. In this embodiment, the response to the loading completion event is to set the playback attributes of the target audio resource through the audio channel instance corresponding to the audio loading instance to play the target audio resource, that is, when the audio loading instance captures the state of the target audio resource being loaded, it is played.
[0051] Step S205: If the target audio resource cannot be played, the audio channel instance is added to a preset audio channel instance list, where the preset audio channel instance list includes at least one audio channel instance corresponding to the target audio resource;
[0052] In one embodiment, the above step S205 includes: if the target audio resource has not been loaded, the audio channel instance is added to the preset audio channel instance list, and the callback function of loading completion is registered through the audio channel instance in the preset audio channel instance list, so as to capture the loading completion message of the target audio resource through the audio channel instance. One situation in which the target audio resource cannot be played is that the target audio resource has not been loaded. Then, in order to avoid the error problem caused by playing the target audio resource through the audio channel instance at this time, the audio channel instance is first added to the preset audio channel instance list, and the target audio resource is played only when the instruction of audio loading completion is received later, that is, delayed playback processing is performed. In this embodiment, after the audio channel instance is added to the preset audio channel instance list, the callback function of loading completion is registered through all or any audio channel instance in the preset audio channel instance list, and the loaded callback function is used to capture the loading completion message of the target audio resource.
[0053] Step S206 : In response to the instruction indicating that the target audio resource has been loaded, the target audio resource is played through the preset audio channel instance list.
[0054] In one embodiment, the above step S206 includes: responding to the loading completion instruction of the target audio resource through the callback function of the loaded audio channel instance, traversing all audio channel instances in the preset audio channel instance list, and setting the playback attributes of all audio channel instances to play the target audio resource. In this embodiment, when the callback function of any audio channel instance in the preset audio channel instance list captures the loading completion message of the target audio resource, it means that the loading completion instruction of the target audio resource is received, responding to the loading completion instruction, traversing all audio channel instances in the preset audio channel instance list, and setting the playback attributes of the target audio resource through each audio channel instance to play the target audio resource according to the set playback attributes.
[0055] Corresponding to the above method embodiment, see Figure 3A schematic diagram of an audio playback device is shown, which includes: a response module 30, used to respond to a playback instruction of a target audio resource, obtain an audio loading instance corresponding to the target audio resource, and the audio loading instance is used to load the target audio resource; a setting module 32, used to play the target audio resource through an audio channel instance corresponding to the audio loading instance, and the audio channel instance is used to set the playback attribute of the target audio resource; an adding module 34, used to add the audio channel instance to a preset audio channel instance list if the target audio resource cannot be played, and the preset audio channel instance list includes at least one audio channel instance corresponding to the target audio resource; a playing module 36, used to respond to a loading completion instruction of the target audio resource, and play the target audio resource through the preset audio channel instance list.
[0056] The above-mentioned audio playback device plays the target audio resource through the audio channel instance corresponding to the audio loading instance each time the playback instruction of the target audio resource is triggered. If it cannot be played, it will be added to the queue to be played, so that after the target audio resource is loaded, the target audio resource can be played uniformly through the preset audio channel instance list, thereby avoiding the technical problem of repeated playback confusion when the same audio file is triggered to play multiple times.
[0057] The above-mentioned response module includes: a response unit, which is used to respond to the playback instruction of the target audio resource and determine whether the cache contains an audio loading instance corresponding to the target audio resource; a creation unit, which is used to create an audio loading instance corresponding to the target audio resource if the cache does not contain the audio loading instance corresponding to the target audio resource, and load the target audio resource through the audio loading instance; and an acquisition unit, which is used to acquire the audio loading instance corresponding to the target audio resource in the cache if the cache contains the audio loading instance corresponding to the target audio resource.
[0058] The above-mentioned creation unit is specifically used to: send a loading request for the target audio resource through the audio loading instance, and monitor the loading status of the loading request through the loading status mark; when the loading status mark indicates that the loading of the target audio resource is completed, throw a loading completion message of the target audio resource.
[0059] The above-mentioned device also includes: a cleaning module, which is used to delete the audio loading instance corresponding to the target audio resource and the preset audio channel instance list corresponding to the target audio resource in the cache in response to the cache cleaning instruction.
[0060] The above-mentioned setting module is also used to: determine whether the audio loading instance specifies an audio channel instance; if the audio loading instance does not specify an audio channel instance, create an audio channel instance corresponding to the audio loading instance; and play the target audio resource through the audio channel instance corresponding to the audio loading instance.
[0061] The above-mentioned setting module is also used to: monitor whether the target audio resource is loaded through the loading completion event of the audio loading instance; if the target audio resource is loaded, set the playback attributes of the target audio resource through the audio channel instance corresponding to the audio loading instance to play the target audio resource.
[0062] The above-mentioned adding module is also used to: if the target audio resource has not been loaded, add the audio channel instance to the preset audio channel instance list, and register a loading completion callback function through the audio channel instance in the preset audio channel instance list, so as to capture the loading completion message of the target audio resource through the audio channel instance.
[0063] The above-mentioned playback module is also used to: respond to the loading completion instruction of the target audio resource through the callback function of the loading completion in the audio channel instance, traverse all audio channel instances in the preset audio channel instance list, and set the playback attributes of all audio channel instances to play the target audio resource.
[0064] This embodiment further provides an electronic device, including a processor and a memory, wherein the memory stores machine-executable instructions that can be executed by the processor, and the processor executes the machine-executable instructions to implement the above-mentioned audio playback method. The electronic device can be a server or a terminal device.
[0065] See also Figure 4 As shown, the electronic device includes a processor 100 and a memory 101. The memory 101 stores machine executable instructions that can be executed by the processor 100. The processor 100 executes the machine executable instructions to implement the above audio playback method.
[0066] Furthermore, Figure 4 The electronic device shown further includes a bus 102 and a communication interface 103 , and the processor 100 , the communication interface 103 and the memory 101 are connected via the bus 102 .
[0067] The memory 101 may include a high-speed random access memory (RAM), and may also include a non-volatile memory, such as at least one disk storage. The communication connection between the system network element and at least one other network element is achieved through at least one communication interface 103 (which may be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. may be used. The bus 102 may be an ISA bus, a PCI bus, or an EISA bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 4 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or one type of bus.
[0068] The processor 100 may be an integrated circuit chip with signal processing capabilities. During implementation, each step of the above method can be completed by hardware integrated logic circuits in the processor 100 or software instructions. The above processor 100 may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the various methods, steps, and logic block diagrams disclosed in the embodiments of the present invention. The general-purpose processor may be a microprocessor or any conventional processor. The steps of the method disclosed in conjunction with the embodiments of the present invention can be directly implemented and executed by a hardware decoding processor, or by a combination of hardware and software modules in the decoding processor. The software module may be located in a storage medium such as a random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, or register, which is well-known in the art. The storage medium is located in the memory 101. The processor 100 reads the information in the memory 101 and, in conjunction with its hardware, performs the steps of the method of the aforementioned embodiment, for example:
[0069] In response to a playback instruction of a target audio resource, an audio loading instance corresponding to the target audio resource is obtained, and the audio loading instance is used to load the target audio resource; the target audio resource is played through an audio channel instance corresponding to the audio loading instance, and the audio channel instance is used to set the playback properties of the target audio resource; if the target audio resource cannot be played, the audio channel instance is added to a preset audio channel instance list, and the preset audio channel instance list includes at least one audio channel instance corresponding to the target audio resource; in response to a loading completion instruction of the target audio resource, the target audio resource is played through the preset audio channel instance list.
[0070] In this method, each time the play instruction of the target audio resource is triggered, the target audio resource is played through the audio channel instance corresponding to the audio loading instance. If it cannot be played, it is added to the queue to be played, so that after the target audio resource is loaded, the target audio resource is played uniformly through the preset audio channel instance list, thereby avoiding the technical problem of repeated playback confusion when the same audio file is triggered to play multiple times.
[0071] The above-mentioned response to the playback instruction of the target audio resource obtains the audio loading instance corresponding to the target audio resource, and the audio loading instance is used to load the target audio resource, including: responding to the playback instruction of the target audio resource, determining whether the cache contains the audio loading instance corresponding to the target audio resource; if the cache does not contain the audio loading instance corresponding to the target audio resource, creating an audio loading instance corresponding to the target audio resource, and loading the target audio resource through the audio loading instance; if the cache contains the audio loading instance corresponding to the target audio resource, obtaining the audio loading instance corresponding to the target audio resource in the cache.
[0072] The above-mentioned loading of the target audio resource through the audio loading instance includes: sending a loading request of the target audio resource through the audio loading instance, and monitoring the loading status of the loading request through the loading status mark; when the loading status mark indicates that the loading of the target audio resource is completed, throwing a loading completion message of the target audio resource.
[0073] The above method also includes: in response to the cache cleaning instruction, deleting the audio loading instance corresponding to the target audio resource and the preset audio channel instance list corresponding to the target audio resource in the cache.
[0074] The above-mentioned playing of the target audio resource through the audio channel instance corresponding to the audio loading instance includes: determining whether the audio loading instance specifies an audio channel instance; if the audio loading instance does not specify an audio channel instance, creating an audio channel instance corresponding to the audio loading instance; and playing the target audio resource through the audio channel instance corresponding to the audio loading instance.
[0075] The above-mentioned playing of the target audio resource through the audio channel instance corresponding to the audio loading instance includes: monitoring whether the target audio resource is loaded through the loading completion event of the audio loading instance; if the target audio resource is loaded, setting the playback properties of the target audio resource through the audio channel instance corresponding to the audio loading instance to play the target audio resource.
[0076] The above-mentioned adding the audio channel instance to the preset audio channel instance list if the target audio resource cannot be played includes: if the target audio resource has not been loaded, adding the audio channel instance to the preset audio channel instance list, and registering a loading completion callback function through the audio channel instance in the preset audio channel instance list to capture the loading completion message of the target audio resource through the audio channel instance.
[0077] The above-mentioned response to the loading completion instruction of the target audio resource and playing the target audio resource through the preset audio channel instance list includes: responding to the loading completion instruction of the target audio resource through the callback function of the loading completion in the audio channel instance, traversing all audio channel instances in the preset audio channel instance list, and setting the playback attributes of all audio channel instances to play the target audio resource.
[0078] This embodiment further provides a machine-readable storage medium storing machine-executable instructions. When the machine-executable instructions are called and executed by a processor, the machine-executable instructions prompt the processor to implement the above-mentioned audio playback method. For example:
[0079] In response to a playback instruction of a target audio resource, an audio loading instance corresponding to the target audio resource is obtained, and the audio loading instance is used to load the target audio resource; the target audio resource is played through an audio channel instance corresponding to the audio loading instance, and the audio channel instance is used to set the playback properties of the target audio resource; if the target audio resource cannot be played, the audio channel instance is added to a preset audio channel instance list, and the preset audio channel instance list includes at least one audio channel instance corresponding to the target audio resource; in response to a loading completion instruction of the target audio resource, the target audio resource is played through the preset audio channel instance list.
[0080] In this method, each time the play instruction of the target audio resource is triggered, the target audio resource is played through the audio channel instance corresponding to the audio loading instance. If it cannot be played, it is added to the queue to be played, so that after the target audio resource is loaded, the target audio resource is played uniformly through the preset audio channel instance list, thereby avoiding the technical problem of repeated playback confusion when the same audio file is triggered to play multiple times.
[0081] The above-mentioned response to the playback instruction of the target audio resource obtains the audio loading instance corresponding to the target audio resource, and the audio loading instance is used to load the target audio resource, including: responding to the playback instruction of the target audio resource, determining whether the cache contains the audio loading instance corresponding to the target audio resource; if the cache does not contain the audio loading instance corresponding to the target audio resource, creating an audio loading instance corresponding to the target audio resource, and loading the target audio resource through the audio loading instance; if the cache contains the audio loading instance corresponding to the target audio resource, obtaining the audio loading instance corresponding to the target audio resource in the cache.
[0082] The above-mentioned loading of the target audio resource through the audio loading instance includes: sending a loading request of the target audio resource through the audio loading instance, and monitoring the loading status of the loading request through the loading status mark; when the loading status mark indicates that the loading of the target audio resource is completed, throwing a loading completion message of the target audio resource.
[0083] The above method also includes: in response to the cache cleaning instruction, deleting the audio loading instance corresponding to the target audio resource and the preset audio channel instance list corresponding to the target audio resource in the cache.
[0084] The above-mentioned playing of the target audio resource through the audio channel instance corresponding to the audio loading instance includes: determining whether the audio loading instance specifies an audio channel instance; if the audio loading instance does not specify an audio channel instance, creating an audio channel instance corresponding to the audio loading instance; and playing the target audio resource through the audio channel instance corresponding to the audio loading instance.
[0085] The above-mentioned playing of the target audio resource through the audio channel instance corresponding to the audio loading instance includes: monitoring whether the target audio resource is loaded through the loading completion event of the audio loading instance; if the target audio resource is loaded, setting the playback properties of the target audio resource through the audio channel instance corresponding to the audio loading instance to play the target audio resource.
[0086] The above-mentioned adding the audio channel instance to the preset audio channel instance list if the target audio resource cannot be played includes: if the target audio resource has not been loaded, adding the audio channel instance to the preset audio channel instance list, and registering a loading completion callback function through the audio channel instance in the preset audio channel instance list to capture the loading completion message of the target audio resource through the audio channel instance.
[0087] The above-mentioned response to the loading completion instruction of the target audio resource and playing the target audio resource through the preset audio channel instance list includes: responding to the loading completion instruction of the target audio resource through the callback function of the loading completion in the audio channel instance, traversing all audio channel instances in the preset audio channel instance list, and setting the playback attributes of all audio channel instances to play the target audio resource.
[0088] The computer program products of the audio playback method, device, electronic device, and storage medium provided in the embodiments of the present invention include a computer-readable storage medium storing program code. The instructions included in the program code can be used to execute the methods described in the previous method embodiments. For specific implementation, please refer to the method embodiments and will not be repeated here.
[0089] Those skilled in the art will clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described systems and devices can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0090] In addition, in the description of the embodiments of the present invention, unless otherwise expressly specified or limited, the terms "mounted," "connected," and "connected" should be understood in a broad sense. For example, they may refer to fixed connections, detachable connections, or integral connections; they may refer to mechanical connections or electrical connections; they may refer to direct connections or indirect connections through an intermediate medium; and they may refer to internal communication between two components. Those skilled in the art will understand the specific meanings of the above terms in the present invention based on the specific circumstances.
[0091] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
[0092] In the description of the present invention, it should be noted that the terms "center," "upper," "lower," "left," "right," "vertical," "horizontal," "inner," and "outer," etc., indicating orientations or positional relationships, are based on the orientations or positional relationships shown in the accompanying drawings and are intended solely to facilitate and simplify the description of the present invention. They are not intended to indicate or imply that the devices or components referred to must have, be constructed, or operate in a specific orientation, and therefore should not be construed as limitations on the present invention. Furthermore, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.
[0093] Finally, it should be noted that the above embodiments are only specific implementation methods of the present invention, which are used to illustrate the technical solutions of the present invention, rather than to limit them. The scope of protection of the present invention is not limited thereto. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that any person skilled in the art can modify or easily conceive of changes to the technical solutions described in the above embodiments within the technical scope disclosed by the present invention, or replace some of the technical features therein with equivalents. Such modifications, changes or replacements do not deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should be included in the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be based on the scope of protection of the claims.
Claims
1. An audio playback method, characterized in that: The method comprises: In response to a play instruction of a target audio resource, obtaining an audio loading instance corresponding to the target audio resource, wherein the audio loading instance is used to load the target audio resource; Play the target audio resource through the audio channel instance corresponding to the audio loading instance, where the audio channel instance is used to set the playback properties of the target audio resource; If the target audio resource cannot be played, adding the audio channel instance to a preset audio channel instance list, where the preset audio channel instance list includes at least one audio channel instance corresponding to the target audio resource; In response to the loading completion instruction of the target audio resource, the target audio resource is played through the preset audio channel instance list.
2. The method according to claim 1, characterized in that The step of obtaining an audio loading instance corresponding to the target audio resource in response to a play instruction of the target audio resource includes: In response to a play instruction of a target audio resource, determining whether a cache contains an audio loading instance corresponding to the target audio resource; If the cache does not contain the audio loading instance corresponding to the target audio resource, create an audio loading instance corresponding to the target audio resource, and load the target audio resource through the audio loading instance; If the cache contains the audio loading instance corresponding to the target audio resource, the audio loading instance corresponding to the target audio resource in the cache is obtained.
3. The method according to claim 2, characterized in that The loading of the target audio resource through the audio loading instance includes: Sending a loading request for the target audio resource through the audio loading instance, and monitoring the loading status of the loading request through a loading status mark; When the loading status mark indicates that the loading of the target audio resource is complete, a loading completion message of the target audio resource is thrown.
4. The method according to claim 2, characterized in that After playing the target audio resource through the preset audio channel instance list in response to the instruction for completing the loading of the target audio resource, the method further includes: In response to the cache cleanup instruction, the audio loading instance corresponding to the target audio resource and the preset audio channel instance list corresponding to the target audio resource in the cache are deleted.
5. The method according to claim 1, wherein Playing the target audio resource through the audio channel instance corresponding to the audio loading instance includes: Determine whether the audio loading instance specifies an audio channel instance; If the audio loading instance does not specify an audio channel instance, create an audio channel instance corresponding to the audio loading instance; The target audio resource is played through the audio channel instance corresponding to the audio loading instance.
6. The method according to claim 1 or 5, characterized in that Playing the target audio resource through the audio channel instance corresponding to the audio loading instance includes: Monitor whether the target audio resource is loaded successfully through the loading completion event of the audio loading instance; If the target audio resource is loaded, the playback attribute of the target audio resource is set through the audio channel instance corresponding to the audio loading instance to play the target audio resource.
7. The method according to claim 1, characterized in that If the target audio resource cannot be played, adding the audio channel instance to a preset audio channel instance list includes: If the target audio resource has not been loaded, the audio channel instance is added to a preset audio channel instance list, and a loading completion callback function is registered through the audio channel instance in the preset audio channel instance list to capture the loading completion message of the target audio resource through the audio channel instance.
8. The method according to claim 7, characterized in that The step of playing the target audio resource by using the preset audio channel instance list in response to the instruction of completion of loading the target audio resource comprises: Through the callback function of the loaded audio channel instance, in response to the loading completion instruction of the target audio resource, all audio channel instances in the preset audio channel instance list are traversed, and the playback attributes of all audio channel instances are set to play the target audio resource.
9. An audio playback device, characterized in that: The device comprises: A response module, configured to obtain an audio loading instance corresponding to the target audio resource in response to a play instruction of the target audio resource, wherein the audio loading instance is used to load the target audio resource; A setting module, configured to play the target audio resource through the audio channel instance corresponding to the audio loading instance, wherein the audio channel instance is used to set the playback properties of the target audio resource; an adding module, configured to add the audio channel instance to a preset audio channel instance list if the target audio resource cannot be played, the preset audio channel instance list including at least one audio channel instance corresponding to the target audio resource; A playing module is configured to play the target audio resource through the preset audio channel instance list in response to a loading completion instruction of the target audio resource.
10. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the memory stores machine-executable instructions that can be executed by the processor, and the processor executes the machine-executable instructions to implement the audio playback method according to any one of claims 1 to 8.
11. A machine-readable storage medium, characterized in that The machine-readable storage medium stores machine-executable instructions. When the machine-executable instructions are called and executed by the processor, the machine-executable instructions prompt the processor to implement the audio playback method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Voice playing method and equipment
CN104346189A
Audio information playing method and device and electronic equipment
CN111460211A