Audio playing control method and device, electronic equipment and storage medium
By building virtual audio devices and audio forwarding channels, the problem of affecting the audio playback quality when multiple applications play at the same time is solved, and the priority playback and rapid recovery of audio data is achieved, and the audio playback quality is improved.
Patent Information
- Application Number
- CN202311344536.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-17
- Publication Date
- 2025-04-18
AI Technical Summary
When multiple applications play audio simultaneously, it affects the audio playback quality of the current application, resulting in a degradation of sound quality.
Build a virtual audio device, forward audio data to physical audio devices through the audio forwarding channel, realize audio data management of multiple applications, and ensure that the audio data of the current application is played first.
Improves audio playback quality, ensures that the audio data of the current application is not affected by other applications during playback, and quickly restores audio playback of other applications after the first application ends the audio playback.
Smart Images

Figure CN119847471A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of electronic technology, and in particular to an audio playback control method, device, electronic device and storage medium. Background Art
[0002] With the advancement of digital technology, audio devices are becoming more and more powerful and can support multiple applications (Application, APP) to play audio at the same time. However, in some specific scenarios, some users hope that one application can exclusively use the audio device to avoid audio interference from other applications, such as watching teaching videos.
[0003] In the existing technology, when an application needs to play audio exclusively, the playback functions of other applications are usually stopped so that the current application can play the audio device exclusively, which is not friendly to other applications. Alternatively, the audio stream of the current application is separated from the mixed audio by using audio diversion technology, and the separated audio is sent to the corresponding audio device. Since the original audio data cannot be directly processed but the mixed audio stream is processed, and since the mixed audio stream needs to be processed, the sound quality of the original audio is likely to change during the processing, thereby resulting in a decrease in the audio playback quality. Summary of the invention
[0004] In order to solve the above technical problems, the embodiments of the present application provide an audio playback control method, device, electronic device and storage medium to solve the problem of affecting the playback quality of the audio corresponding to the current application when multiple applications are played simultaneously, thereby improving the audio playback quality.
[0005] In order to solve the above technical problems, the embodiments of the present application provide the following technical solutions:
[0006] In a first aspect, an embodiment of the present application provides an audio playback control method, which is applied to an electronic device, where the electronic device includes a physical audio device, and the method includes:
[0007] Constructing a virtual audio device, wherein the virtual audio device includes an audio forwarding channel, and the audio forwarding channel is used for the virtual audio device to forward audio data to the physical audio device;
[0008] Acquire first audio data corresponding to the first application, and play the first audio data through a physical audio device; at the same time, close the audio forwarding channel, and play second audio data corresponding to the second application through a virtual audio device;
[0009] After the first application finishes playing the audio, the audio forwarding channel is opened to enable the virtual audio device to forward the second audio data to the physical audio device, so that the physical audio device plays the second audio data.
[0010] In some embodiments, constructing a virtual audio device includes:
[0011] Get the build tool and use it to create a driver project.
[0012] In the driver program project, a device interface is defined, wherein the device interface is used to interact with the second application program, and the device interface includes an input interface, an output interface, a data interface, and a device property;
[0013] Write driver code according to the device interface;
[0014] Compile the driver code to get the virtual audio device.
[0015] In some embodiments, before obtaining the first audio data corresponding to the first application and playing the first audio data through the physical audio device, the method further includes:
[0016] Create device enumerator and audio playback client agent;
[0017] Determine the physical audio device through the device enumerator;
[0018] Acquiring first audio data corresponding to the first application and playing the first audio data through a physical audio device includes:
[0019] The first audio data corresponding to the first application is obtained through the audio playback client agent, and the first audio data is sent to the physical audio device to play the first audio data through the physical audio device.
[0020] In some embodiments, the audio playback client agent includes an acquisition tool, which acquires first audio data corresponding to the first application through the audio playback client agent, and sends the first audio data to the physical audio device, including:
[0021] Acquire the first audio data and the first buffer corresponding to the first application program through an acquisition tool;
[0022] storing the first audio data in a first buffer;
[0023] The first audio data corresponding to the first application is obtained from the first buffer through the audio playback client agent, and the first audio data corresponding to the first application is sent to the physical audio device.
[0024] In some embodiments, the virtual audio device includes a second buffer, and an audio forwarding channel is opened to enable the virtual audio device to forward second audio data to the physical audio device, so that the physical audio device plays the second audio data, including:
[0025] Receiving second audio data corresponding to the second application program through the input interface;
[0026] The second audio data is stored in a second buffer, the second audio data corresponding to the second application is obtained from the second buffer through the virtual audio device, and the second audio data is forwarded to the physical audio device through the audio forwarding channel, so that the physical audio device plays the second audio data.
[0027] In some embodiments, before obtaining the first audio data corresponding to the first application, the method further includes:
[0028] Sending the first audio data to the first application through the third application according to a playback requirement, wherein the playback requirement includes a playback duration;
[0029] If the playing time is greater than or equal to the preset time value, the sending of the first audio data to the first application is stopped.
[0030] In some embodiments, when the first audio data corresponding to the first application is being played, the state of the physical audio device is an exclusive state;
[0031] When the first application finishes playing the audio, the state of the physical audio device is a shared state.
[0032] In a second aspect, an embodiment of the present application provides an audio playback control device, which is applied to an electronic device, the electronic device including a physical audio device, and the device includes:
[0033] A construction unit, used for constructing a virtual audio device, wherein the virtual audio device includes an audio forwarding channel, and the audio forwarding channel is used for the virtual audio device to forward audio data to the physical audio device;
[0034] A first control unit is used to obtain first audio data corresponding to a first application and play the first audio data through a physical audio device; at the same time, close the audio forwarding channel and play second audio data corresponding to a second application through a virtual audio device;
[0035] The second control unit is used to open the audio forwarding channel after the first application finishes audio playback, so that the virtual audio device forwards the second audio data to the physical audio device, so that the physical audio device plays the second audio data.
[0036] In a third aspect, an embodiment of the present application provides an electronic device, comprising: at least one processor, and at least one memory, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of the audio playback control method of the first aspect.
[0037] In a fourth aspect, an embodiment of the present application provides a non-volatile computer-readable storage medium, which stores a plurality of instructions suitable for loading by a processor to execute the audio playback control method of the first aspect.
[0038] The beneficial effect of the implementation mode of the present application is: different from the prior art, the implementation mode of the present application provides an audio playback control method, the method comprising: constructing a virtual audio device, obtaining first audio data corresponding to a first application, so as to play the first audio data through a physical audio device, and at the same time, closing an audio forwarding channel, so as to play second audio data corresponding to a second application through the virtual audio device, and after the first application finishes audio playback, opening the audio forwarding channel so that the virtual audio device forwards the second audio data to the physical audio device, so that the physical audio device plays the second audio data. The present application can realize that the physical audio device plays the first audio data corresponding to the first application, improves the playback quality of the first audio data, and at the same time, does not affect the normal playback of other applications, and can quickly resume the playback of audio corresponding to other applications after the first application finishes audio playback. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] One or more embodiments are exemplarily described by corresponding drawings, which do not constitute limitations on the embodiments. Elements with the same reference numerals in the drawings represent similar elements, and the figures in the drawings do not constitute proportional limitations unless otherwise stated.
[0040] Figure 1 is a schematic diagram of an application environment provided by an embodiment of the present application;
[0041] Figure 2 It is a flowchart of an audio playback control method provided in an embodiment of the present application;
[0042] Figure 3 yes Figure 2 A detailed flow chart of step S201 in FIG.
[0043] Figure 4 It is a schematic diagram of a flow chart of audio data transmission provided by an embodiment of the present application;
[0044] Figure 5 is a schematic diagram of a process for determining a physical audio device provided by an embodiment of the present application;
[0045] Figure 6 yes Figure 2 A detailed flow chart of step S202 in FIG.
[0046] Figure 7 yes Figure 6A detailed flow chart of step S2021 in FIG.
[0047] Figure 8 yes Figure 2 A detailed flow chart of step S203 in FIG.
[0048] Fig. 9 It is a timing diagram of an audio playback control method provided in an embodiment of the present application;
[0049] Fig.10 is a schematic diagram of controlling the playback of a first application and a second application provided in an embodiment of the present application;
[0050] Fig.11 It is a structural diagram of an audio playback control device provided in an embodiment of the present application;
[0051] Fig.12 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application.
[0052] Description of Figure Numbers:
[0053] Label name Label name 100 Application Environment 1101 Audio playback control device 10 Control Terminal 1111 Building Blocks 20 Electronic devices 1112 First control unit 211 processor 1113 Second control unit 212 Memory DETAILED DESCRIPTION
[0054] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0055] It should be noted that, if there is no conflict, the various features in the embodiments of the present application can be combined with each other, and all are within the scope of protection of the present application. In addition, the words "first", "second", etc. used in the present application do not limit the data, but only divide the same or similar items with basically the same functions and effects.
[0056] The technical solution of the present application is described in detail below in conjunction with the accompanying drawings:
[0057] See also Figure 1 , Figure 1 is a schematic diagram of an application environment provided by an embodiment of the present application;
[0058] like Figure 1As shown, the application environment 100 includes: a control terminal 10, an electronic device 20, wherein the electronic device 20 is a controlled terminal controlled by the control terminal, the control terminal 10 is used to send audio data to the electronic device 20, the electronic device 20 is used to receive the audio data sent by the control terminal 10, and play the received audio data through a physical audio device, and at the same time close the audio forwarding channel of the virtual audio device corresponding to the application currently running in the electronic device 20, so that the virtual audio device plays the audio data corresponding to the running application, and the control terminal 10 is connected to the electronic device 20 via a wireless network or a wired interface. It can be understood that the control terminal 10 and the electronic device 20 can be networked devices such as tablet computers and computer terminals, the wired interface includes USB, HDMI, FireWire, Thunderbolt and other interfaces, and the wireless interface includes wireless networks such as wireless local area networks.
[0059] It should be noted that the control terminal 10 and the electronic device 20 need to be connected to the same local area network to ensure that the control terminal 10 will not be affected by the network when sending audio data to the electronic device 20. For example, in a teaching scenario, the control terminal 10 is the teacher's end and the electronic device 20 is the student's end. The teacher's end and the student's end need to be connected to the same local area network to ensure the stable transmission of teaching data, and the student's end can be uniformly managed through the teacher's end to improve the teaching quality.
[0060] See also Figure 2 , Figure 2 It is a flowchart of an audio playback control method provided in an embodiment of the present application;
[0061] The audio playback control method is applied to an electronic device. Specifically, the execution subject of the audio playback control method is one or at least two processors of the electronic device.
[0062] like Figure 2 As shown, the method includes:
[0063] Step S201: construct a virtual audio device, wherein the virtual audio device includes an audio forwarding channel, and the audio forwarding channel is used for the virtual audio device to forward audio data to the physical audio device;
[0064] In an embodiment of the present application, the electronic device is equipped with a physical audio device, such as a headset or a speaker, and the physical audio device is used to play the sound of the video or audio.
[0065] In an embodiment of the present application, a virtual audio device is a software that simulates a physical audio device. The virtual audio device includes an audio forwarding channel, which is composed of an input interface, a data interface, and an output interface. The input interface is used to receive audio data, and the audio data includes an audio signal, which is an analog signal or a digital signal. The audio signal is an actual audible sound. The data interface is used to transmit control signals, such as volume control, switching control and other signals. The output interface is used to send audio data to a physical audio device so as to play the audio signal in the audio data through the physical audio device.
[0066] Specifically, a virtual audio device is constructed, wherein the virtual audio device includes an audio forwarding channel, the virtual audio device is used to receive audio data sent by an application, and send the audio data to a physical audio device through the audio forwarding channel, so as to play the audio data corresponding to the application through the physical audio device.
[0067] In an embodiment of the present application, in the absence of a physical audio device, the virtual audio device can still receive audio data sent by the application. Since the audio data is not forwarded to the physical audio device, the application is in a silent state at this time.
[0068] Please refer to Figure 3 , Figure 3 yes Figure 2 A detailed flow chart of step S201 in FIG.
[0069] like Figure 3 As shown, step S201 includes:
[0070] Step S2011: Obtain a build tool, and create a driver project using the build tool;
[0071] In the embodiment of the present application, the construction tool is used to provide a development environment for the virtual audio device, and recreate a driver project in the development environment, such as providing a dynamic link library (DLL), which includes functions such as initialization, control and data transmission of the virtual audio device, and the driver project is used to write codes related to implementing the virtual audio device. It should be noted that the construction tool is an existing development tool, such as a driver development system (Windows Driver Kit, WDK), which is not limited here.
[0072] Preferably, this application takes WDK as an example and constructs a virtual audio device through WDK.
[0073] Specifically, a WDK installation package is downloaded from the official website of WDK through a browser or other search website, and installed on the electronic device, WDK is started, and a driver project is created in the development environment provided by WDK.
[0074] Step S2012: in the driver project, define a device interface, wherein the device interface is used to interact with the second application, and the device interface includes an input interface, an output interface, a data interface, and device properties;
[0075] Specifically, in the driver project, a device interface is defined. The device interface is a functional interface required for implementing a virtual audio device. The device interface includes an input interface, an output interface, a data interface, device properties, etc. The device properties include device type (to identify the type of device), device ID, device setting options and other property information.
[0076] In the embodiment of the present application, the audio forwarding channel is composed of an input interface, an output interface, and a data interface in the device interface.
[0077] Step S2013: Write driver code according to the device interface;
[0078] Specifically, the device interface includes an input interface, an output interface, a data interface, device attributes, etc. The functions of the interfaces included in the device interface are written to obtain a driver program code that can be compiled and run.
[0079] Step S2014: compile the driver code to obtain a virtual audio device;
[0080] Specifically, the driver program code is compiled to obtain executable program code, and the executable program code is packaged to obtain a virtual audio device.
[0081] In the embodiment of the present application, the constructed virtual audio device needs to be installed in the electronic device before it can be used. Specifically, the virtual audio device is installed in the electronic device for use by the application program.
[0082] Please refer to Figure 4 , Figure 4 It is a schematic diagram of a flow chart of audio data transmission provided by an embodiment of the present application;
[0083] like Figure 4 As shown, the process of sending the audio data includes:
[0084] Step S401: sending first audio data to the first application program through the third application program according to a playback requirement;
[0085] In the embodiment of the present application, the playback requirement is the requirement that the audio and video in the control terminal needs to be played on the electronic device, for example: in an electronic classroom, when the teacher is teaching, the audio and video on the teacher's side needs to be played on the student's side.
[0086] In an embodiment of the present application, the third application is installed on the control terminal, and the first application is installed on the electronic device. The third application and the first application can be the same application or different applications. The third application sends audio data to the first application to synchronize the audio and video in the control terminal to the electronic device for playback through the electronic device.
[0087] Specifically, the first audio data is audio data required to be played in the third application. According to the playback requirements, the first audio data is synchronized to the electronic device at the control terminal, that is, the first audio data is sent to the first application through the third application.
[0088] Step S402: Determine whether the playing time is greater than or equal to a preset time value;
[0089] In an embodiment of the present application, the playback requirement includes the playback duration, which is the duration of the current third application sending the first audio data to the first application. The preset duration value is the duration of the audio that the third application needs to play. For example, the preset duration value is 30 minutes or 45 minutes. The duration of the preset duration value can be determined according to actual needs and is not limited here.
[0090] Specifically, determine whether the playback duration is greater than or equal to the preset duration value. If the playback duration is greater than or equal to the preset duration value, jump to step S403; otherwise, jump to step S404.
[0091] Step S403: Stop sending the first audio data to the first application;
[0092] Specifically, when the playing duration is greater than or equal to the preset duration value, the first audio data is stopped from being sent to the first application, that is, the first audio data required to be played by the third application has all been sent to the first application.
[0093] Step S404: Continue to send the first audio data to the first application;
[0094] Specifically, when the playing time is less than the preset time value, the first audio data continues to be sent to the first application, that is, the first audio data required to be played by the third application has not been fully sent to the first application.
[0095] Please refer to Figure 5 , Figure 5 is a schematic diagram of a process for determining a physical audio device provided by an embodiment of the present application;
[0096] like Figure 5 As shown, the process of determining the physical audio device includes:
[0097] Step S501: Create a device enumerator and an audio playback client agent;
[0098] In an embodiment of the present application, a device enumerator is a tool for identifying and selecting physical audio devices, that is, obtaining a list of physical audio devices from the operating system of the electronic device and selecting a physical audio device to communicate with, so as to set the selected physical audio device to an exclusive state, so that one application exclusively uses the physical audio device to play audio, and other applications cannot access the physical audio device at the same time.
[0099] In an embodiment of the present application, the audio playback client agent is used to interact with the physical audio device. The audio playback client agent can receive the first audio data sent by the third application and send the first audio data to the physical audio device.
[0100] Specifically, create a device enumerator, define a multimedia device interface, and implement the functions of the multimedia device interface to obtain a device enumerator. For example, the multimedia device interface is IMMDeviceEnumerator, IMMEndpoint, and SetProperty. IMMDeviceEnumerator is used to enumerate physical audio devices, that is, to generate a list of physical audio devices. IMMEndpoint is used to represent the audio endpoint device, that is, the physical audio device where the audio data is played. SetProperty is used to set the state of the physical audio device, such as the exclusive state and the shared state.
[0101] Specifically, creating an audio playback client proxy includes: defining a proxy interface, and specifically implementing the functions of the proxy interface to obtain the audio playback client proxy. For example, the proxy interface is IAudioClient in the audio session interface (Windows AudioSession Interface, WASAPI), and IAudioClient includes IAudioRenderClient, which is used to receive audio data and send audio data to a physical audio device.
[0102] Step S502: Determine the physical audio device through the device enumerator;
[0103] Specifically, a list of physical audio devices of the electronic device is obtained through a device enumerator, and a physical audio device corresponding to the first audio data corresponding to the first application is selected from the list, and the physical audio device is set to be accessible only to the first application.
[0104] Step S202: obtaining first audio data corresponding to the first application, and playing the first audio data through a physical audio device; at the same time, closing the audio forwarding channel, and playing second audio data corresponding to the second application through a virtual audio device;
[0105] In the embodiment of the present application, the second application is an application in the electronic device that can play audio and video, and the first application and the second application are different applications.
[0106] In an embodiment of the present application, the second audio data corresponding to the second application needs to be sent to the virtual audio device first, and then the second audio data is sent to the physical audio device through the audio forwarding channel of the virtual audio device.
[0107] Specifically, the electronic device receives the first audio data sent by the third application to obtain the first audio data corresponding to the first application, and sends the first audio data to the physical audio device to play the first audio data through the physical audio device. At the same time, the audio forwarding channel of the virtual audio device is closed to play the second audio data corresponding to the second application through the virtual audio device.
[0108] In an embodiment of the present application, when a first application and a second application in an electronic device are running simultaneously, in order not to affect the playback quality of the first audio data sent by the third application, it is necessary to close the output interface in the audio forwarding channel of the virtual audio device, so that the second audio data corresponding to the second application is only sent to the virtual audio device, and the second audio data is played through the virtual audio device, so that the second application is in a mute state without affecting the playback of the first audio data corresponding to the first application, and at the same time, it will not affect the normal playback of the second application.
[0109] In an embodiment of the present application, when a first application and a second application in an electronic device are running simultaneously, in order not to affect the playback quality of the first audio data sent by a third application, the input interface in the audio forwarding channel can also be closed to interrupt the forwarding of the second audio data corresponding to the second application, so as to pause the playback of the second audio data corresponding to the second application in the virtual audio device, so that when the first application stops playing audio, the second audio data corresponding to the original second application can be restored.
[0110] Please refer to 6 again. Figure 6 yes Figure 2 A detailed flow chart of step S202 in FIG.
[0111] like Figure 6 As shown, step S202 includes:
[0112] Step S2021: obtaining first audio data corresponding to the first application through the audio playback client agent, and sending the first audio data to the physical audio device to play the first audio data through the physical audio device;
[0113] Specifically, the first audio data sent by the third application is received through the audio playback client agent to obtain the first audio data corresponding to the first application, and the first audio data is sent to the physical audio device to play the first audio data through the physical audio device.
[0114] Please refer to Figure 7 , Figure 7 yes Figure 6 A detailed flow chart of step S2021 in FIG.
[0115] like Figure 7 As shown, step S2021 includes:
[0116] Step S2201: obtaining first audio data and a first buffer corresponding to a first application program through an acquisition tool;
[0117] In an embodiment of the present application, the proxy interface in the audio playback client proxy includes an acquisition tool, which includes a data function and a buffer allocation function. The data function includes: OnDataAvailable function and RenderMoreData function, and the buffer allocation function includes CreateBuffer() function in GetBuffer.
[0118] Specifically, first audio data corresponding to the first application is received through a data function, and a first buffer is acquired through a buffer allocation function. The first buffer is used to store the first audio data.
[0119] In an embodiment of the present application, the first audio data obtained by the acquisition tool can be pulse code modulation data (Pulse Code Modulation, PCM), rawstream data, that is, PCM audio data, wherein the PCM audio data is an uncompressed audio sampling data raw stream, and the rawstream data is an uncompressed audio stream.
[0120] In an embodiment of the present application, the audio playback client agent can directly obtain the PCM audio data or rawstream data of the first audio data, and directly send the PCM audio data or rawstream data of the first audio data to the physical audio device, so that the first audio data does not need to undergo special processing during the transmission process, and the first audio data can be played synchronously on the control terminal and the electronic device.
[0121] Step S2202: storing the first audio data in the first buffer;
[0122] Specifically, the acquired first audio data is stored in a first buffer, wherein the first buffer is a high-speed buffer provided by one of a static random access memory (SRAM), a double data rate synchronous dynamic random access memory (DDR), a resistive random access memory (RRAM), etc.
[0123] In an embodiment of the present application, the first buffer can increase the speed of transmission and processing of the first audio data, and provide temporary storage space when the first audio data is transmitted from the control terminal to the electronic device, so that the processing speed of the first audio data can be optimized within an appropriate time.
[0124] Step S2203: obtaining first audio data corresponding to the first application from the first buffer through the audio playback client agent, and sending the first audio data corresponding to the first application to the physical audio device;
[0125] Specifically, if there is first audio data in the first buffer, the first audio data corresponding to the first application is obtained from the first buffer through the audio playback client agent, and the obtained first audio data is sent to the physical audio device so that the physical audio device plays the first audio data.
[0126] Step S203: after the first application finishes playing the audio, opening the audio forwarding channel so that the virtual audio device forwards the second audio data to the physical audio device, so that the physical audio device plays the second audio data;
[0127] Specifically, after the first application finishes audio playback, the audio forwarding channel is opened, that is, the output interface in the audio forwarding channel is set to an open state. When the second application is playing audio, the second audio data corresponding to the second application is forwarded to the physical audio device through the virtual audio device, so that the physical audio device plays the second audio data, thereby making the second application silent.
[0128] In an embodiment of the present application, after the first application finishes playing audio, the state of the physical audio device is set to a shared state, that is, the audio forwarding channel of the virtual audio device is opened, so that the physical audio device can receive the second audio data corresponding to the second application. The shared state means that multiple applications share the physical audio device and can play audio of multiple applications at the same time.
[0129] Please refer to Figure 8 , Figure 8 yes Figure 2 A detailed flow chart of step S203 in FIG.
[0130] like Figure 8 As shown, step S203 includes:
[0131] Step S2031: receiving second audio data corresponding to the second application through the input interface;
[0132] Specifically, when the second application is playing audio, the second audio data corresponding to the second application is sent to the virtual audio device, and the virtual audio device receives the second audio data corresponding to the second application through the input interface in the audio forwarding channel.
[0133] Step S2032: storing the second audio data in the second buffer, obtaining the second audio data corresponding to the second application from the second buffer through the virtual audio device, and forwarding the second audio data to the physical audio device through the output interface, so that the physical audio device plays the second audio data;
[0134] In an embodiment of the present application, the virtual audio device is used to receive second audio data corresponding to a second application and send the second audio data to a physical audio device. In order to increase the transmission speed of the second audio data, when constructing the virtual audio device, a second buffer area is allocated to the virtual audio device, and the second buffer area is used to store the second audio data corresponding to the second application.
[0135] Specifically, the second audio data corresponding to the second application is stored in the second buffer, the second audio data corresponding to the second application is obtained from the second buffer through the data interface, and the second audio data is forwarded to the physical audio device through the output interface, so that the physical audio device plays the second audio data, wherein the second buffer is a high-speed buffer, which is provided by one of a static random access memory (Static Random-Access Memory, SRAM), a double data rate synchronous dynamic random access memory (Double Data Rate, DDR), a resistive random access memory (Resistive Random Access Memory, RRAM), etc.
[0136] In an embodiment of the present application, a third application sends first audio data to the first application so that the physical audio device of the electronic device plays the first audio data. When the electronic device is playing second audio data corresponding to the second application, the audio forwarding channel in the virtual audio device is closed so that the second audio data corresponding to the second application cannot be forwarded to the physical audio device, and the second application is still in a running state and the second application is in a silent state.
[0137] In the embodiment of the present application, the virtual audio device can coordinate the access of multiple applications to the physical audio device, thereby ensuring the correct processing and playback of audio data corresponding to the application.
[0138] In an embodiment of the present application, when a physical audio device is implemented to play the first audio data corresponding to a first application, the playback quality of the first audio data is improved. At the same time, the normal playback of other applications will not be affected, and after the first application ends the audio playback, the playback of the audio corresponding to other applications can be quickly resumed.
[0139] Please refer to 9 again. Fig. 9 It is a timing diagram of an audio playback control method provided in an embodiment of the present application;
[0140] like Fig. 9 As shown, the timing of the audio playback control method includes:
[0141] Step S901: sending first audio data;
[0142] Specifically, the third application sends the first audio data to the first application.
[0143] Step S902: closing the audio forwarding channel of the virtual audio device currently occupied by the second application;
[0144] Specifically, when the first application receives the first audio data sent by the third application, and the electronic device corresponding to the first application is playing the second audio data corresponding to the second application, the audio forwarding channel of the virtual audio device occupied by the second application is closed, so that the second audio data corresponding to the second application is prohibited from being sent to the physical audio device, so that the second audio data corresponding to the second application is played through the virtual audio device, and the second application is in a muted state.
[0145] Step S903: receiving first audio data, determining a physical audio device, and playing the first audio data through the physical audio device;
[0146] Specifically, when the electronic device receives the first audio data corresponding to the first application, it determines the physical audio device that plays the first audio data corresponding to the first application, so as to determine that the physical audio device is in an exclusive state, and sends the first audio data corresponding to the first application to the physical audio device so as to play the first audio data through the physical audio device.
[0147] Step S904: stop sending the first audio data;
[0148] Specifically, when all the first audio data to be played have been sent to the first application, sending the first audio data to the first application is stopped.
[0149] Step S905: Open the audio forwarding channel;
[0150] Specifically, when the first application has received all the first audio data and stops playing, the audio forwarding channel of the virtual audio device is opened so that the second audio data corresponding to the second application is sent to the physical audio device, and the second audio data is played through the physical audio device to resume the playback of the second audio data corresponding to the second application.
[0151] In an embodiment of the present application, when the first audio data corresponding to the first application is being played, the audio forwarding channel of the virtual audio device is closed to improve the playback quality of the first audio data when the physical audio device plays the first audio data corresponding to the first application. At the same time, the normal playback of other applications is not affected. After the first application finishes the audio playback, the audio forwarding channel of the virtual audio device is opened to quickly resume the playback of the audio corresponding to other applications.
[0152] Please refer to Fig.10 , Fig.10 is a schematic diagram of controlling the playback of a first application and a second application provided in an embodiment of the present application;
[0153] like Fig.10 As shown, the schematic diagram includes: a first application, a second application, a virtual audio device, and a physical audio device.
[0154] Specifically, when the first application sends the first audio data to the physical audio device for playing, the audio forwarding channel of the virtual audio device is closed, so that the second application plays the second audio data through the virtual audio device. At this time, the physical audio device is in an exclusive state.
[0155] Specifically, when the first application stops playing audio, the second application sends the second audio data to the virtual audio device, and forwards the second audio data to the physical audio device through the virtual audio device, so as to play the second audio data corresponding to the second application through the physical audio device.
[0156] In an embodiment of the present application, when the first audio data corresponding to the first application is being played, the audio forwarding channel of the virtual audio device is closed to improve the playback quality of the first audio data when the physical audio device plays the first audio data corresponding to the first application. At the same time, the normal playback of other applications is not affected. After the first application finishes the audio playback, the audio forwarding channel of the virtual audio device is opened to quickly resume the playback of the audio corresponding to other applications.
[0157] See also Fig.11 , Fig.11 It is a structural diagram of an audio playback control device provided in an embodiment of the present application;
[0158] like Fig.11 As shown, the audio playback control device 1101 includes:
[0159] A construction unit 1111 is used to construct a virtual audio device, wherein the virtual audio device includes an audio forwarding channel, and the audio forwarding channel is used for the virtual audio device to forward audio data to the physical audio device;
[0160] The first control unit 1112 is used to obtain the first audio data corresponding to the first application and play the first audio data through the physical audio device; at the same time, close the audio forwarding channel and play the second audio data corresponding to the second application through the virtual audio device;
[0161] The second control unit 1113 is used to open the audio forwarding channel after the first application finishes audio playback, so that the virtual audio device forwards the second audio data to the physical audio device, so that the physical audio device plays the second audio data.
[0162] In an embodiment of the present application, the audio playback control device can be a software module, which includes a number of instructions stored in a memory. The processor can access the memory and call the instructions for execution to complete the audio playback control methods of the above-mentioned embodiments.
[0163] In the embodiments of the present application, the audio playback control device can also be constructed by hardware devices. For example, the audio playback control device can be constructed by one or more chips, and each chip can work in coordination with each other to complete the audio playback control method described in the above embodiments. For another example, the audio playback control device can also be constructed by various logic devices, such as a general-purpose processor, a digital signal processor (Digital Signal Processing, DSP), an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), a programmable logic array (Field-Programmable Gate Array, FPGA), a single-chip microcomputer, an ARM processor (Acorn RISC Machine) or other programmable logic devices, discrete gates or transistor logic, discrete hardware components or any combination of these components.
[0164] The audio playback control device in the embodiment of the present application can be a device, or a component, integrated circuit, or chip in a terminal. The device can be a mobile electronic device or a non-mobile electronic device. Exemplarily, the mobile electronic device can be a mobile phone, a tablet computer, a laptop computer, a PDA, an in-vehicle electronic device, a wearable device, an ultra-mobile personal computer (ultra-mobile personal computer, UMPC), a netbook or a personal digital assistant (personal digital assistant, PDA), etc., and the non-mobile electronic device can be a server, a network attached storage (Network Attached Storage, NAS), a personal computer (personal computer, PC), a television (television, TV), a teller machine or a self-service machine, etc., which is not specifically limited in the embodiment of the present application.
[0165] The audio playback control device in the embodiment of the present application may be a device having an operating system. The operating system may be an Android operating system, an iOS operating system, or other possible operating systems, which are not specifically limited in the embodiment of the present application.
[0166] The audio playback control device provided in the embodiment of the present application can achieve Figure 2 To avoid repetition, the various processes implemented by the method embodiment are not described here.
[0167] It should be noted that the above device can execute the audio playback control method provided in the embodiment of the present application, and has the corresponding functional modules and beneficial effects of the execution method. For technical details not described in detail in the device embodiment, please refer to the audio playback control method provided in the embodiment of the present application.
[0168] In an embodiment of the present application, an audio playback control device is provided, including a construction unit for constructing a virtual audio device, wherein the virtual audio device includes an audio forwarding channel, and the audio forwarding channel is used for the virtual audio device to forward audio data to the physical audio device; a first control unit is used to obtain first audio data corresponding to a first application, and play the first audio data through the physical audio device; at the same time, close the audio forwarding channel, and play the second audio data corresponding to the second application through the virtual audio device; a second control unit is used to open the audio forwarding channel after the first application ends the audio playback, so that the virtual audio device forwards the second audio data to the physical audio device, so that the physical audio device plays the second audio data.
[0169] In an embodiment of the present application, when the first audio data corresponding to the first application is being played, the audio forwarding channel of the virtual audio device is closed to ensure that when the physical audio device plays the first audio data corresponding to the first application, it does not affect the normal playback of other applications, and after the first application ends the audio playback, the playback quality of the first audio data is improved. At the same time, it can not affect the normal playback of other applications, and after the first application ends the audio playback, it can quickly resume the playback of the audio corresponding to other applications.
[0170] Please refer to Fig.12 , Fig.12 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application;
[0171] like Fig.12 As shown, the electronic device 20 includes one or more processors 211 and a memory 212. Fig.12 A processor 211 is taken as an example.
[0172] The processor 211 and the memory 212 may be connected via a bus or other means. Fig.12 The example of connecting through bus is taken in the following.
[0173] A processor, used to execute the audio playback control method in any embodiment of the present application, including:
[0174] Constructing a virtual audio device, wherein the virtual audio device includes an audio forwarding channel, and the audio forwarding channel is used for the virtual audio device to forward audio data to the physical audio device;
[0175] Acquire first audio data corresponding to the first application, and play the first audio data through a physical audio device; at the same time, close the audio forwarding channel, and play second audio data corresponding to the second application through a virtual audio device;
[0176] After the first application finishes playing the audio, the audio forwarding channel is opened to enable the virtual audio device to forward the second audio data to the physical audio device, so that the physical audio device plays the second audio data.
[0177] In an embodiment of the present application, when a physical audio device is implemented to play the first audio data corresponding to a first application, the playback quality of the first audio data is improved. At the same time, the normal playback of other applications will not be affected, and after the first application ends the audio playback, the playback of the audio corresponding to other applications can be quickly resumed.
[0178] The memory 212 is a non-volatile computer-readable storage medium that can be used to store non-volatile software programs, non-volatile computer executable programs and modules, such as program instructions / modules corresponding to the audio playback control method in the embodiment of the present application. The processor 211 executes various functional applications and data processing of the electronic device by running the non-volatile software programs, instructions and modules stored in the memory 212, that is, the audio playback control method of the above method embodiment is implemented.
[0179] The memory 212 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some embodiments, the memory 212 may optionally include a memory remotely arranged relative to the processor 211. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0180] One or more modules are stored in the memory 212, and when executed by one or more processors 211, the audio playback control method in any of the above method embodiments is executed, for example, the above described audio playback control method is executed. Figure 2 The steps shown.
[0181] An embodiment of the present application also provides a computer program product, which includes one or more program codes, which are stored in a non-volatile computer-readable storage medium. A processor of an electronic device reads the program code from the non-volatile computer-readable storage medium, and the processor executes the program code to complete the steps of the audio playback control method provided in the above embodiment.
[0182] Through the description of the above implementation methods, ordinary technicians in this field can understand that all or part of the steps of implementing the above embodiments can be completed by hardware, or by hardware related to program code, and the program can be stored in a non-volatile computer-readable storage medium. The non-volatile computer-readable storage medium mentioned above can be a read-only memory, a disk or an optical disk, etc.
[0183] Through the description of the above implementation methods, a person of ordinary skill in the art can clearly understand that each implementation method can be implemented by means of software plus a general hardware platform, and of course, can also be implemented by hardware. A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a computer program, and the program can be stored in a non-volatile computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the non-volatile computer-readable storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc.
[0184] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Under the concept of the present application, the technical features in the above embodiments or different embodiments can also be combined, the steps can be implemented in any order, and there are many other changes in different aspects of the present application as mentioned above, which are not provided in detail for the sake of simplicity. Although the present application has been described in detail with reference to the aforementioned embodiments, a person of ordinary skill in the art should understand that the technical solutions described in the aforementioned embodiments can still be modified, or some of the technical features can be replaced by equivalents. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the scope of the technical solutions of the embodiments of the present application.
Claims
1. A method for controlling audio playback, characterized in that: Applied to an electronic device, the electronic device includes a physical audio device, the method includes: Constructing a virtual audio device, wherein the virtual audio device includes an audio forwarding channel, and the audio forwarding channel is used for the virtual audio device to forward audio data to the physical audio device; Acquire first audio data corresponding to the first application, and play the first audio data through the physical audio device; at the same time, close the audio forwarding channel, and play second audio data corresponding to the second application through the virtual audio device; After the first application finishes playing the audio, the audio forwarding channel is opened to enable the virtual audio device to forward the second audio data to the physical audio device, so that the physical audio device plays the second audio data.
2. The method according to claim 1, characterized in that The step of constructing a virtual audio device comprises: Obtain a build tool, and create a driver project using the build tool; In the driver program project, a device interface is defined, wherein the device interface is used to interact with the second application program, and the device interface includes an input interface, an output interface, a data interface, and device properties; According to the device interface, write the driver code; Compile the driver code to obtain the virtual audio device.
3. The method according to claim 2, characterized in that Before obtaining the first audio data corresponding to the first application and playing the first audio data through the physical audio device, the method further includes: Create device enumerator and audio playback client agent; Determining the physical audio device by the device enumerator; The acquiring the first audio data corresponding to the first application and playing the first audio data through the physical audio device includes: The first audio data corresponding to the first application is obtained through the audio playback client agent, and the first audio data is sent to the physical audio device to play the first audio data through the physical audio device.
4. The method according to claim 3, characterized in that The audio playback client agent includes an acquisition tool, and the acquisition of the first audio data corresponding to the first application program through the audio playback client agent, and sending the first audio data to the physical audio device, includes: Acquire, by the acquisition tool, first audio data and a first buffer corresponding to the first application program; storing the first audio data in the first buffer; The first audio data corresponding to the first application is obtained from the first buffer through the audio playback client agent, and the first audio data corresponding to the first application is sent to the physical audio device.
5. The method according to any one of claims 2 to 4, characterized in that: The virtual audio device includes a second buffer, and the audio forwarding channel is opened so that the virtual audio device forwards the second audio data to the physical audio device, so that the physical audio device plays the second audio data, including: receiving, via the input interface, second audio data corresponding to the second application; The second audio data is stored in the second buffer, the second audio data corresponding to the second application is obtained from the second buffer through the virtual audio device, and the second audio data is forwarded to the physical audio device through the audio forwarding channel, so that the physical audio device plays the second audio data.
6. The method according to claim 5, characterized in that Before acquiring the first audio data corresponding to the first application, the method further includes: Sending the first audio data to the first application through a third application according to a playback requirement, wherein the playback requirement includes a playback duration; If the playing duration is greater than or equal to a preset duration value, the sending of the first audio data to the first application is stopped.
7. The method according to any one of claims 1 to 4 and 6, characterized in that: When the first audio data corresponding to the first application is being played, the state of the physical audio device is an exclusive state; When the first application ends audio playback, the state of the physical audio device is a shared state.
8. An audio playback control device, characterized in that: Applied to an electronic device, the electronic device includes a physical audio device, and the apparatus includes: A construction unit, configured to construct a virtual audio device, wherein the virtual audio device comprises an audio forwarding channel, and the audio forwarding channel is used for the virtual audio device to forward audio data to the physical audio device; A first control unit is used to obtain first audio data corresponding to a first application, and play the first audio data through the physical audio device; at the same time, close the audio forwarding channel, and play second audio data corresponding to a second application through the virtual audio device; The second control unit is used to open the audio forwarding channel after the first application ends audio playback, so that the virtual audio device forwards the second audio data to the physical audio device, so that the physical audio device plays the second audio data.
9. An electronic device, characterized in that: include: At least one processor and at least one memory, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of the audio playback control method described in any one of claims 1-7.
10. A non-volatile computer-readable storage medium, characterized in that: The non-volatile computer-readable storage medium stores a plurality of instructions, and the instructions are suitable for being loaded by a processor to execute the audio playback control method described in any one of claims 1-7.