Audio playing state control method and device, electronic equipment and storage medium
By creating a collection of audio playback status instances and real-time detection of audio status, the complex state management problem in online audio playback is solved, efficient state flow and playback control operations are achieved, and audio playback effect and code scalability are improved.
Patent Information
- Application Number
- CN202411159841.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-22
- Publication Date
- 2024-12-27
AI Technical Summary
In online audio playback scenarios, audio status management is complex, and existing solutions are difficult to achieve efficient state flow and broadcast control operations, affecting the audio playback effect.
By creating a collection of playback status instances for the audio player, the audio status is detected in real time, and the target status instance is determined according to the detection conditions, setting it to the current status, performing corresponding operations, isolating the flow logic of each status instance, and simplifying state management.
It improves the accuracy and efficiency of audio playback status streaming, enhances the scalability of player code, and simplifies state management and playback control operations.
Smart Images

Figure CN119201029A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to an audio playback status control method, device, electronic device, and computer-readable storage medium. Background Art
[0002] In audio production scenarios, it is usually necessary to play audio files for effect preview. The vast majority of audio production tools are client software, and audio files are located locally. In online audio production scenarios, the audio is located in the cloud, and the playback method depends on the support for audio playback in the browser. For example, in web applications, the implementation of the audio player depends on the precise control of each individual audio playback instance. Since audio relies on remote acquisition, especially in scenarios where multiple audios are played at the same time, each audio has an independent state and behavior. Therefore, online audio playback is limited to the asynchrony of communication between multiple audio instances. When judging the state of the audio and controlling the playback of the audio according to the state, the existing solution has a high degree of implementation complexity. Each time the state flows between states, it is necessary to comprehensively judge the flow relationship between the states, resulting in complex state flow and playback control methods, low state management efficiency, and affecting the audio playback effect. Summary of the invention
[0003] In view of this, in order to solve some or all of the above technical problems, the embodiments of the present application provide an audio playback status control method, device, electronic device and computer-readable storage medium.
[0004] In a first aspect, an embodiment of the present application provides an audio playback state control method, the method comprising: in response to the start of an audio player, creating a playback state instance set of an audio player; using the playback state instance set to detect the state of audio played by the audio player in real time; according to the detection condition corresponding to each playback state instance in the playback state instance set, determining a target playback state instance that currently meets the corresponding detection condition from the playback state instance set; setting the target state detected by the target playback state instance as the current state of the audio player; and executing the corresponding operation of the audio player according to the current state.
[0005] In one possible implementation, creating a play state instance set of an audio player includes: creating a play state base class, wherein the play state base class includes a play control method; creating an audio player instance, and in the audio player instance, creating at least two play state instances belonging to the play state base class as a play state instance set; and implementing corresponding play control methods in the play state instances in the play state instance set.
[0006] In a possible implementation, after executing the operation corresponding to the audio player according to the current state, the method further includes: in the current state, if the play control method included in the target play state instance is triggered, executing the play control operation corresponding to the play control method.
[0007] In one possible implementation, the playback state instance set includes at least two of the following state instances related to playback control operations: a ready state instance, a playback state instance, a pause state instance, a segment jump state instance, and a playback completion state instance; in the current state, if the playback control method contained in the target playback state instance is triggered, the playback control operation corresponding to the playback control method is executed, including: if the current state is the ready state, in response to triggering the audio playback method contained in the ready state instance, an audio playback operation is executed; in response to triggering the segment jump method contained in the ready state instance, an audio segment jump operation is executed; if the current state is the playback state, in response to triggering the pause playback method contained in the playback state instance, a pause playback operation is executed; in response to triggering the playback The fragment jump method contained in the state instance executes the audio fragment jump operation; if the current state is the pause state, in response to the audio play method contained in the triggered pause state instance, the audio play operation is executed; in response to the fragment jump method contained in the triggered pause state instance, the audio fragment jump operation is executed; if the current state is the fragment jump state, in response to the audio play method contained in the triggered fragment jump state instance, the audio play operation is executed; in response to the pause play method contained in the triggered fragment jump state instance, the pause play operation is executed; if the current state is the playback completion state, in response to the audio play method contained in the triggered playback completion state instance, the audio play operation is executed; in response to the fragment jump method contained in the triggered playback completion state instance, the audio fragment jump operation is executed.
[0008] In one possible implementation, the play state instance set includes at least one of the following state instances that are not related to the play control operation: an unprepared state instance, a play error state instance; after executing the operation corresponding to the audio player according to the current state, the method further includes: if the current state is an unprepared state, in response to the completion of the loading of the audio resource, the prepared state instance jumps the current state to the prepared state; in response to the play error state instance detecting an audio resource loading error, the play error state instance jumps the current state to the play error state; if the current state is a play state, in response to the play error state instance detecting an audio clip loading error, the play error state instance jumps the current state to the play error state; if the current state is a play state, in response to the play error state instance detecting an audio clip loading error, the play error state instance jumps the current state to the play error state; if the current state is a play error state, all operations on the audio player are stopped.
[0009] In one possible implementation, the audio player is a multi-audio player for simultaneously playing multiple audios; according to the detection conditions corresponding to each playback state instance in the playback state instance set, a target playback state instance that currently meets the corresponding detection conditions is determined from the playback state instance set, including: for each playback state instance in the playback state instance set, if the states of at least N audios among the multiple audios meet the detection conditions corresponding to the playback state instance, the playback state instance is determined as the target playback state instance, wherein N is the preset number of detection conditions corresponding to the playback state instance.
[0010] In one possible implementation, the audio player instance also includes a state change operation method; setting the target state detected by the target playback state instance as the current state of the audio player, including: calling the state change operation method included in the audio player instance by the target playback state instance, and setting the target playback state instance to the current playback state instance included in the audio player instance; executing corresponding operations of the audio player according to the current state, including: executing corresponding operations by the current playback state instance.
[0011] In a second aspect, an embodiment of the present application provides an audio playback state control device, the device comprising: a creation module, for creating a set of playback state instances of an audio player in response to the audio player being started;
[0012] A detection module is used to use a play state instance set to detect the state of the audio played by the audio player in real time; a determination module is used to determine the target play state instance that currently meets the corresponding detection conditions from the play state instance set according to the detection conditions corresponding to each play state instance in the play state instance set; a setting module is used to set the target state detected by the target play state instance as the current state of the audio player; and a first execution module is used to execute the corresponding operation of the audio player according to the current state.
[0013] In a third aspect, an embodiment of the present application provides an electronic device, comprising: a memory for storing a computer program; a processor for executing the computer program stored in the memory, and when the computer program is executed, the method of any embodiment of the audio playback status control method of the first aspect of the present application is implemented.
[0014] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, a method as in any embodiment of the audio playback status control method of the first aspect described above is implemented.
[0015] In a fifth aspect, an embodiment of the present application provides a computer program, which includes a computer-readable code. When the computer-readable code runs on a device, the processor in the device implements a method as in any embodiment of the audio playback status control method of the first aspect mentioned above.
[0016] The audio playback state control method, device, electronic device and computer-readable storage medium provided by the embodiment of the present application, by creating a set of playback state instances of the audio player when the audio player is started, using the set of playback state instances, detecting the state of the audio played by the audio player in real time, determining the target playback state instance that currently meets the corresponding detection condition according to the detection condition corresponding to each playback state instance, setting the target state detected by the target playback state instance as the current state of the audio player, and finally executing the corresponding broadcast control operation of the audio player according to the current state. The embodiment of the present application realizes the isolation of the flow logic of each state during audio playback, and each state instance does not affect each other. It only needs to respond to the event of the audio player in real time to detect whether it meets its own state. There is no need to set the state flow logic separately, avoid complex business judgment, and improve the accuracy and efficiency of the playback state flow. In addition, the playback state instance can be increased or decreased according to demand, and because the state instances do not affect each other, the scalability of the player code can be greatly enhanced to cope with the ever-changing business. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0018] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0019] One or more embodiments are exemplarily described by pictures in the corresponding drawings, and these exemplified descriptions do not constitute limitations on the embodiments. Elements with the same reference numerals in the drawings represent similar elements, and unless otherwise stated, the figures in the drawings do not constitute proportional limitations.
[0020] Figure 1 A flowchart of an audio playback state control method provided in an embodiment of the present application;
[0021] Figure 2 A flowchart of another audio playback state control method provided in an embodiment of the present application;
[0022] Figure 3A A schematic diagram of the code structure of the playback status base class provided in an embodiment of the present application;
[0023] Figure 3B A schematic diagram of the code structure of an audio player example provided in an embodiment of the present application;
[0024] Figure 3C A schematic diagram of the calling relationship between the playback state base class, audio player instance and each playback state instance provided in an embodiment of the present application;
[0025] Figure 4 A flowchart of another audio playback state control method provided in an embodiment of the present application;
[0026] Figure 5 A schematic diagram of jumping between various playback state instances provided in an embodiment of the present application;
[0027] Figure 6 A flowchart of another audio playback state control method provided in an embodiment of the present application;
[0028] Figure 7 A schematic diagram of the structure of an audio playback state control device provided in an embodiment of the present application;
[0029] Figure 8 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0030] Various exemplary embodiments of the present application will now be described in detail with reference to the accompanying drawings. Obviously, the described embodiments are part of the embodiments of the present application, rather than all of the embodiments. It should be noted that unless otherwise specifically stated, the relative arrangement of the components and steps, the numerical expressions and the numerical values described in these embodiments do not limit the scope of the present application.
[0031] Those skilled in the art will understand that the terms "first" and "second" in the embodiments of the present application are only used to distinguish between different steps, devices, modules and other objects, and do not represent any specific technical meanings, nor do they indicate the logical order between them.
[0032] It should also be understood that in this embodiment, “plurality” may refer to two or more than two, and “at least one” may refer to one, two or more than two.
[0033] It should also be understood that any component, data or structure mentioned in the embodiments of the present application can generally be understood as one or more, unless explicitly limited or otherwise indicated in the context.
[0034] In addition, the term "and / or" in this application is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this application generally indicates that the associated objects before and after are in an "or" relationship.
[0035] It should also be understood that the description of the various embodiments in this application focuses on the differences between the various embodiments, and the same or similar aspects thereof can be referenced to each other, and for the sake of brevity, they will not be described one by one.
[0036] The following description of at least one exemplary embodiment is merely illustrative in nature and is in no way intended to limit the present application, its application, or uses.
[0037] Technologies, circuits, and devices known to ordinary technicians in the relevant art may not be discussed in detail, but where appropriate, the above-mentioned technologies, circuits, and devices should be considered as part of the specification.
[0038] It should be noted that like reference numerals and letters refer to similar items in the following figures, and therefore, once an item is defined in one figure, it need not be further discussed in subsequent figures.
[0039] It should be noted that, in the absence of conflict, the embodiments in this application and the features in the embodiments can be combined with each other. To facilitate the understanding of the embodiments of the present application, the present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments. Obviously, the described embodiments are part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0040] In order to solve the technical problems of complex audio state flow logic, unclear code logic and low scalability of playback control methods in the prior art, the present application provides an audio playback state control method, which can realize that different state instances only respond to the states corresponding to themselves, and the flow logics of different state instances are isolated from each other and do not affect each other, thereby making the code logic clearer and easier to maintain and expand.
[0041] Figure 1A flowchart of an audio playback state control method provided for an embodiment of the present application. The method can be applied to one or more electronic devices such as laptop computers, desktop computers, smart phones, portable computers, servers, etc. In an application scenario, the method can be applied to a terminal device, the terminal device is connected to the server via a network, an audio player is provided on the terminal device, and the audio played by the audio player can be obtained from the server. According to the method, the audio playback control operation is implemented.
[0042] In addition, the execution subject of the present method may be hardware or software. When the execution subject is hardware, the execution subject may be one or more of the electronic devices. For example, a single electronic device may execute the present method, or a plurality of electronic devices may cooperate with each other to execute the present method. When the execution subject is software, the present method may be implemented as a plurality of software or software modules, or as a single software or software module. No specific limitation is made herein.
[0043] like Figure 1 As shown, the method specifically includes:
[0044] Step 101, in response to the audio player being started, creating a set of play state instances of the audio player.
[0045] In some embodiments, the audio player can be a separate player client or an online player implemented on a browser. When the audio player is started, a play state instance set can be created through code initialization. Each play state instance in the play state instance set corresponds to a state of the audio player. For example, the play state instance corresponds to the play state, the pause state instance corresponds to the pause state, etc.
[0046] Step 102: Using the play status instance set, the state of the audio played by the audio player is detected in real time.
[0047] In some embodiments, each playback state instance can execute the audio playback event response method contained therein, and if it is detected that the audio playback event is consistent with the event set by itself, it determines the state corresponding to the playback state instance.
[0048] Step 103 : According to the detection condition corresponding to each play state instance in the play state instance set, determine the target play state instance that currently meets the corresponding detection condition from the play state instance set.
[0049] In some embodiments, each play state instance corresponds to a detection condition. When the player state detected by a play state instance meets the corresponding detection condition, the play state instance can be determined as a target play state instance.
[0050] For example, for a play state instance, when it detects an event that the audio is playing, it can be determined that the corresponding detection condition is currently met, and the play state instance is the target play state instance. For a pause state instance, when it detects an event that the audio is paused, it can be determined that the corresponding detection condition is currently met, and the pause state instance is the target play state instance.
[0051] Step 104, setting the target state detected by the target playback state instance as the current state of the audio player.
[0052] In some embodiments, the state value of the detected target state can be used as the state value of the current state by setting the current state variable. Optionally, the target playback state instance can be assigned to the pre-established current state instance, and when the target playback state instance detects the corresponding state, the current state instance is obtained accordingly, and the current state of the audio player can be determined.
[0053] Step 105, executing the operation corresponding to the audio player according to the current state.
[0054] In some embodiments, the correspondence between the current state and the operation of the audio player can be preset. For example, if the current state is the playing state, the broadcast control method included in the audio player instance can perform the audio playback operation; if the current state is the pause state, the above-mentioned broadcast control method can perform the pause playback operation. In addition, the above-mentioned current state instance can also be used to execute the included broadcast control method to realize the control of the audio player.
[0055] It should also be noted that the operation corresponding to the audio player can also be a non-broadcast control operation, that is, an operation that is not related to playback control. For example, the playback state instance set may include a playback error state instance, that is, when the playback error state instance detects an error in loading an audio resource, the current state is a playback error state, and the audio player can output an error prompt message. For another example, the playback state instance set may include an unready state instance, that is, when it is detected that the audio player does not meet the prerequisites required to play the audio, the current state is an unready state, and the audio player can output an unready prompt message.
[0056] The audio playback state control method provided by the embodiment of the present application creates a set of playback state instances of the audio player when the audio player is started, uses the set of playback state instances to detect the state of the audio played by the audio player in real time, determines the target playback state instance that currently meets the corresponding detection condition according to the detection condition corresponding to each playback state instance, sets the target state detected by the target playback state instance as the current state of the audio player, and finally executes the corresponding broadcast control operation of the audio player according to the current state. The embodiment of the present application realizes the isolation of the flow logic of each state during audio playback, and each playback state instance does not affect each other. It only needs to respond to the event of the audio player in real time to detect whether it meets the state of the playback state instance itself. There is no need to set the state flow logic separately, avoid complex business judgment, and improve the accuracy and efficiency of the playback state flow. In addition, the playback state instance can be increased or decreased according to demand, and because the playback state instances do not affect each other, the scalability of the player code can be greatly enhanced to cope with the ever-changing business.
[0057] In some optional implementations, such as Figure 2 As shown, step 101 includes:
[0058] Step 1011, create a play status base class.
[0059] Among them, the play state base class includes the play control method. The play state base class is an abstract class of various play states. That is, on the basis of the play state base class, various play state instances belonging to the play state base class can be defined. In the play state base class, multiple play control methods can be declared, and different play state instances can contain corresponding play control methods and define the play control methods.
[0060] like Figure 3A As shown, it shows the code structure of the base class BaseState, where play(), pause(), seek(), etc. are play control methods, which are used to implement the functions of playing, pausing, and jumping to a segment of the audio player. In addition, Figure 3A Other types of methods are also shown, for example, initState(), which is used to initialize the play state base class, and bindAudioEvent(), which is used to monitor audio events. In addition, the play state base class can also declare a reference to an audio player instance so that each play state instance can call the method contained in the audio player instance.
[0061] Step 1012: create an audio player instance, and in the audio player instance, create at least two play state instances belonging to the play state base class as a play state instance set.
[0062] like Figure 3BAs shown, it shows a schematic diagram of the code structure of the audio player instance MultiPlayer. It creates a ready state instance (readyState:ReadyState), a playing state instance (playingState:PlayingState), a pause state instance (pauseState:PauseState), a segment jump state instance (seekingState:SeekingState), a playback state instance (endedState:EndedState), a loading error state instance (errorState:ErrorState), and an unready state instance (unredayState:UnreadyState). In addition, Figure 3B The method included in the audio player instance is also shown, for example, the above play(), pause(), seek() and other play control methods are included. It also includes initMultiPlayer(), which is used to initialize the audio player instance, and changeState(), which is used to switch the current play state instance.
[0063] Step 1013: Implement a corresponding play control method in the play state instance in the play state instance set.
[0064] Among them, in the playback state instance related to the audio playback process, the playback control method inherited from the basic state class can be set. For example, in the preparation state instance, the audio playback method play() and the segment jump method seek() can be implemented; in the playback state instance, the pause playback method pause() and the segment jump method seek() can be implemented; in the pause state instance, the audio playback method play() and the segment jump method seek() can be implemented; in the segment jump state instance, the pause playback method pause() and the audio playback method play() can be implemented.
[0065] like Figure 3C As shown in FIG. 1 , it shows the calling relationship between the play state base class, the audio player instance and each play state instance. Figure 3C It can be seen that the audio player instance MultiPlayer contains various playback state instances, and each playback state instance belongs to the playback state base class BaseState.
[0066] This embodiment implements the playback control method in the playback state instance, so that the execution of the playback control method is only related to the current playback state, making the code logic clearer and avoiding playback errors caused by complex logic such as judgment and jump between different states.
[0067] In some optional implementations, such as Figure 4 As shown, after step 105, the method further includes:
[0068] Step 106: In the current state, if the play control method included in the target play state instance is triggered, the play control operation corresponding to the play control method is executed.
[0069] Specifically, in the current state, if the target playback state instance includes a playback control method, the playback control instruction of the audio player can be responded to, and then the corresponding playback control method can be executed. After executing the playback control method, the method provided by the embodiment of the present application can be repeatedly executed, that is, the playback state instance set is continued to be used to detect the state of the audio player in real time, and the corresponding operation of the audio player is continued to be executed according to the detected state, so as to jump between different states and execute the corresponding playback control method when the audio is playing.
[0070] For example, if the current state is the play state, the corresponding play state instance includes the pause method pause() and the segment jump method seek(). When the pause instruction is triggered, the pause method can be executed, and the audio being played can be paused. When the segment jump instruction is triggered, the segment jump method can be executed, and the specified segment can be jumped to continue playing.
[0071] This embodiment realizes the state jump of the audio player during the playback process by executing the playback control method by the target playback state instance in the current state. Since the current state is only related to the corresponding target playback state instance, the isolation of different playback state instances is realized. The playback control method is executed by the current target playback state instance to avoid playback errors caused by complex state judgment.
[0072] In some optional implementations, the play state instance set includes at least two of the following state instances related to the play control operation: a ready state instance, a play state instance, a pause state instance, a segment jump state instance, and a play complete state instance. The above state instances related to the play control operation include instances of the play control method.
[0073] The above step 106 can be performed as follows:
[0074] If the current state is the ready state, in response to the audio play method contained in the ready state instance, the audio play operation is performed; in response to the segment jump method contained in the ready state instance, the audio segment jump operation is performed;
[0075] If the current state is the playing state, in response to the pause playing method contained in the triggering playing state instance, the pause playing operation is performed; in response to the segment jumping method contained in the triggering playing state instance, the audio segment jumping operation is performed;
[0076] If the current state is the pause state, in response to the audio play method contained in the instance of the triggering pause state, the audio play operation is performed; in response to the segment jump method contained in the instance of the triggering pause state, the audio segment jump operation is performed;
[0077] If the current state is the segment jump state, in response to the audio play method contained in the trigger segment jump state instance, the audio play operation is performed; in response to the pause play method contained in the trigger segment jump state instance, the pause play operation is performed.
[0078] If the current state is the playback completion state, in response to triggering the audio playback method contained in the playback completion state instance, an audio playback operation is performed; in response to triggering the segment jump method contained in the playback completion state instance, an audio segment jump operation is performed.
[0079] like Figure 3C As shown, the ready state instance ReadyState, the playing state instance PlayingState, the pause state instance PauseState, the segment jump state instance SeekingState, and the playing completion state instance EndedState all include a play control method, that is, these play state instances are state instances related to the play control operation.
[0080] like Figure 5 , which shows a schematic diagram of jumping between various playback state instances. For example, if the current state corresponds to the playback state instance PlayingState, then in the playback state, the pause playback method pause() or the segment jump method seek() can be executed, and then the current state jumps to the pause state or the jump state, and the pause state instance or the segment jump state instance continues to respond to the user's instructions.
[0081] For another example, if the current state corresponds to the ready state instance ReadyState, then in the ready state, the audio playback method play() or the segment jump method seek() can be executed, and then the current state jumps to the play state or jump state, and the play state instance or segment jump state instance continues to respond to user instructions.
[0082] For jumps between other playback state instances, please refer to Figure 5 As shown by the arrows, they will not be described one by one here.
[0083] This embodiment sets a plurality of state instances related to the play control operation, thereby realizing accurate jumps between different play state instances by executing the play control method, thereby simplifying the logic of play state adjustment and helping to improve the efficiency of play state management.
[0084] In some optional implementations, the play state instance set includes at least one of the following state instances that are not related to the play control operation: an unprepared state instance, a play error state instance. The above state instances that are not related to the play control operation do not include instances of the play control method.
[0085] After step 105, the method further comprises:
[0086] If the current state is the unprepared state, in response to the completion of the loading of the audio resource, the prepared state instance jumps the current state to the prepared state; in response to the playback error state instance detecting an audio resource loading error, the playback error state instance jumps the current state to the playback error state;
[0087] If the current state is the playing state, in response to the playing error state instance detecting an audio clip loading error, the playing error state instance jumps the current state to the playing error state;
[0088] If the current state is a playback error state, stop all operations on the audio player.
[0089] like Figure 5 As shown, when the audio resource starts to be loaded, it enters the unready state after being detected by the unready instance UnredyState. In the unready state, you can wait for the audio resource to be loaded. The ready state instance ReadyState detects that the current state jumps to the ready state. If an error occurs during loading, the error state instance ErrorState detects that the current state jumps to the error state.
[0090] like Figure 5 As shown, in the playing state, if the playing error state instance ErrorState detects an audio clip loading error, the playing error state instance jumps the current state to the playing error state.
[0091] like Figure 5 As shown, in the playback error state, the playback error state instance ErrorState can issue an instruction to stop all operations on the audio player and wait for the audio resource to be reloaded.
[0092] This embodiment sets a state instance that is not related to the playback control operation, so that when the audio resource is not loaded completely or loaded incorrectly, no operation is performed on the audio player, thereby reducing the risk of errors in the flow process between states.
[0093] In some optional implementations, the audio player is a multi-audio player for playing multiple audios simultaneously. Specifically, in an audio production scenario, a 2.0-channel or 5.1-channel audio file is synthesized based on multiple independent channel audios, and multiple channel audio files need to be played simultaneously before the synthesis to preview the effect. The multi-audio player of this embodiment is used to play audios under multiple channels simultaneously.
[0094] Step 103 may be performed as follows:
[0095] For each playback state instance in the playback state instance set, if the states of at least N audios among multiple audios meet the detection conditions corresponding to the playback state instance, the playback state instance is determined as the target playback state instance, where N is the preset number of detection conditions corresponding to the playback state instance.
[0096] As an example, for any one of the ready state instance, the playing state instance, the pause state instance, the segment jump state instance, the playing state instance, etc., the corresponding N may be equal to the number of the above-mentioned multiple audios. That is, all audios are loaded, the current state is determined to be the ready state, and the target playing state instance is the ready state instance;
[0097] All audios start playing, the current state is determined to be the playing state, and the target playing state instance is the playing state instance;
[0098] All audios are played and paused, the current state is determined to be the paused state, and the target playback state instance is the paused state instance;
[0099] All audio clips start to jump, the current state is determined to be the clip jump state, and the target playback state instance is the clip jump state instance;
[0100] All audios are played, the current state is determined to be the playback completion state, and the target playback state instance is the playback completion state instance.
[0101] As another example, for the unprepared state instance and the play error state instance, N is set to 1, that is, when any audio is unprepared or a play error occurs, the current state is determined to be the prepared state or the play error state, and the target play state instance is the unprepared state instance or the play error state instance.
[0102] This embodiment achieves unified management of the playback status of multiple audios by applying this method in a multi-audio player. Compared with the existing status management method, this embodiment can ignore the asynchrony between multiple audios, thereby improving the state control efficiency and accuracy in the multi-audio playback scenario.
[0103] In some optional implementations, the audio player instance also includes a state change operation method. Figure 3B As shown, changeState() is the state change operation method.
[0104] like Figure 6 As shown, step 104 includes:
[0105] Step 1041: The target play state instance calls the state change operation method included in the audio player instance to set the target play state instance as the current play state instance included in the audio player instance.
[0106] like Figure 3B As shown, currentState declares the current playback state instance. The state change operation method is used to change the current playback state instance. For example, if the original current playback state instance is a playback state instance, when it is detected that the current state is in a paused state, the target playback state instance is a paused state instance, then the above-mentioned state change operation method is executed to adjust the current playback state instance to a paused state instance.
[0107] Step 105 includes:
[0108] Step 1051, the current playback state instance executes corresponding operations.
[0109] Optionally, if the current playback state instance is an instance related to playback control, the playback control method contained in the current playback state instance can be executed to implement the corresponding playback control operation. If the current playback instance is an instance unrelated to playback control, a preset operation can be executed. For example, if the current playback state instance is an unready state instance, the unready state instance can instruct the audio player to output an unready prompt message; if the current playback state instance is a playback error state instance, the playback error state instance can instruct the audio player to output a playback error prompt message.
[0110] This embodiment sets the state change operation method and the current playback state instance in the audio player instance, so that when the player is operated, the playback state instance corresponding to the currently detected state is executed, thereby associating specific operations on the player only with the current playback state instance, thereby simplifying the complexity of logical judgment between player operations and states, further simplifying the logical structure, and helping to improve the accuracy of state flow and playback control during audio playback.
[0111] Figure 7A structural diagram of an audio playback state control device provided in an embodiment of the present application. Specifically comprising: a creation module 701, for creating a playback state instance set of an audio player in response to the start of an audio player; a detection module 702, for using the playback state instance set to detect the state of the audio played by the audio player in real time; a determination module 703, for determining the target playback state instance that currently meets the corresponding detection condition from the playback state instance set according to the detection condition corresponding to each playback state instance in the playback state instance set; a setting module 704, for setting the target state detected by the target playback state instance as the current state of the audio player; and a first execution module 705, for executing the corresponding operation of the audio player according to the current state.
[0112] In some optional implementations, the creation module includes: a first creation unit, used to create a playback state base class, wherein the playback state base class includes a playback control method; a second creation unit, used to create an audio player instance, and in the audio player instance, create at least two playback state instances belonging to the playback state base class as a playback state instance set; an implementation unit, used to implement the corresponding playback control method in the playback state instance in the playback state instance set.
[0113] In some optional implementations, the device further includes: a second execution module, configured to execute a playback control operation corresponding to the playback control method if the playback control method included in the target playback state instance is triggered in the current state.
[0114] In some optional implementations, the playback state instance set includes at least two of the following state instances related to the playback control operation: a ready state instance, a playback state instance, a pause state instance, a segment jump state instance, and a playback completion state instance; the second execution module includes: a first execution unit, which is used to, if the current state is the ready state, respond to triggering the audio playback method contained in the ready state instance, execute an audio playback operation; respond to triggering the segment jump method contained in the ready state instance, execute an audio segment jump operation; a second execution unit, which is used to, if the current state is the playback state, respond to triggering the pause playback method contained in the playback state instance, execute a pause playback operation; respond to triggering the segment jump method contained in the playback state instance, execute an audio segment jump operation operation; a third execution unit, for, if the current state is a pause state, in response to the audio playback method contained in the triggering pause state instance, executing the audio playback operation; in response to the segment jump method contained in the triggering pause state instance, executing the audio segment jump operation; a fourth execution unit, for, if the current state is a segment jump state, in response to the audio playback method contained in the triggering segment jump state instance, executing the audio playback operation; in response to the pause playback method contained in the triggering segment jump state instance, executing the pause playback operation; a fifth execution unit, for, if the current state is a playback completion state, in response to the audio playback method contained in the triggering playback completion state instance, executing the audio playback operation; in response to the segment jump method contained in the triggering playback completion state instance, executing the audio segment jump operation.
[0115] In some optional implementations, the set of playback state instances includes at least one of the following state instances that are not related to the playback control operation: an unprepared state instance, a playback error state instance; the device also includes: a sixth execution unit, which is used to, if the current state is an unprepared state, in response to the completion of audio resource loading, jump the current state to the prepared state by the prepared state instance; in response to the playback error state instance detecting an audio resource loading error, jump the current state to the playback error state by the playback error state instance; a seventh execution unit, which is used to, if the current state is a playback state, in response to the playback error state instance detecting an audio clip loading error, jump the current state to the playback error state by the playback error state instance; an eighth execution unit, which is used to, if the current state is a playback state, stop all operations on the audio player.
[0116] In some optional implementations, the audio player is a multi-audio player for playing multiple audios simultaneously; the determination module is further used to: for each playback state instance in the playback state instance set, if the states of at least N audios among the multiple audios meet the detection conditions corresponding to the playback state instance, determine the playback state instance as the target playback state instance, wherein N is the preset number of detection conditions corresponding to the playback state instance.
[0117] In some optional implementations, the audio player instance also includes a state change operation device; the setting module is further used to: call the state change operation method included in the audio player instance by the target playback state instance, and set the target playback state instance to the current playback state instance included in the audio player instance; the first execution module is further used to: execute the corresponding operation by the current playback state instance.
[0118] The audio playback state control device provided in this embodiment can be as follows Figure 7 The audio playback state control device shown in can execute all the steps of the above audio playback state control methods, thereby achieving the technical effects of the above audio playback state control methods. Please refer to the above related description for details. For the sake of brevity, it will not be repeated here.
[0119] Figure 8 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application, Figure 8 The electronic device 800 shown includes: at least one processor 801, a memory 802, at least one network interface 804 and other user interfaces 803. The various components in the electronic device 800 are coupled together via a bus system 805. It is understood that the bus system 805 is used to achieve connection and communication between these components. In addition to the data bus, the bus system 805 also includes a power bus, a control bus and a status signal bus. However, for the sake of clarity, the bus system 805 is not described in detail. Figure 8 Various buses are labeled as bus system 805 .
[0120] The user interface 803 may include a display, a keyboard, or a pointing device (eg, a mouse, a trackball, a touch pad, or a touch screen).
[0121] It can be understood that the memory 802 in the embodiment of the present application can be a volatile memory or a non-volatile memory, or can include both volatile and non-volatile memories. Among them, the non-volatile memory can be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory can be a random access memory (RAM), which is used as an external cache. By way of example but not limitation, many forms of RAM are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM) and direct RAM bus random access memory (DRRAM). The memory 802 described herein is intended to include, but is not limited to, these and any other suitable types of memory.
[0122] In some implementations, the memory 802 stores the following elements, executable units or data structures, or a subset thereof, or an extended set thereof: an operating system 8021 and an application program 8022 .
[0123] The operating system 8021 includes various system programs, such as a framework layer, a core library layer, a driver layer, etc., which are used to implement various basic services and process hardware-based tasks. The application 8022 includes various application programs, such as a media player (Media Player), a browser (Browser), etc., which are used to implement various application services. The program for implementing the method of the embodiment of the present application can be included in the application 8022.
[0124] In this embodiment, by calling the program or instruction stored in the memory 802, specifically, the program or instruction stored in the application 8022, the processor 801 is used to execute the method steps provided by each method embodiment, for example, including:
[0125] In response to the audio player being started, a play state instance set of the audio player is created; the state of the audio played by the audio player is detected in real time using the play state instance set; based on the detection condition corresponding to each play state instance in the play state instance set, a target play state instance that currently meets the corresponding detection condition is determined from the play state instance set; a target state detected by the target play state instance is set as the current state of the audio player; and based on the current state, corresponding operations of the audio player are executed.
[0126] The method disclosed in the above embodiment of the present application can be applied to the processor 801, or implemented by the processor 801. The processor 801 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 801. The above processor 801 can be a general processor, a digital signal processor (Digital Signal Processor, DSP), an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), a field programmable gate array (Field Programmable Gate Array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present application can be implemented or executed. The general processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in the embodiment of the present application can be directly embodied as a hardware decoding processor to execute, or the hardware and software units in the decoding processor can be executed. The software unit can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 802, and the processor 801 reads the information in the memory 802 and completes the steps of the above method in combination with its hardware.
[0127] It is understood that the embodiments described herein may be implemented in hardware, software, firmware, middleware, microcode, or a combination thereof. For hardware implementation, the processing unit may be implemented in one or more application specific integrated circuits (ASIC), digital signal processors (DSP), digital signal processing devices (DSPDevice, DSPD), programmable logic devices (PLD), field programmable gate arrays (FPGA), general purpose processors, controllers, microcontrollers, microprocessors, other electronic units for performing the above-mentioned functions of the present application, or a combination thereof.
[0128] For software implementation, the technology described above in this article can be implemented by a unit that performs the functions described above in this article. The software code can be stored in a memory and executed by a processor. The memory can be implemented in the processor or outside the processor.
[0129] The electronic device provided in this embodiment may be Figure 8 The electronic device shown in can execute all the steps of the above-mentioned audio playback state control methods, thereby achieving the technical effects of the above-mentioned audio playback state control methods. Please refer to the above related description for details. For the sake of brevity, it will not be repeated here.
[0130] The embodiment of the present application also provides a storage medium (computer-readable storage medium). The storage medium here stores one or more programs. The storage medium may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a read-only memory, a flash memory, a hard disk or a solid-state drive; the memory may also include a combination of the above-mentioned types of memory.
[0131] When one or more programs in the storage medium can be executed by one or more processors, the audio playback state control method executed on the electronic device side can be implemented.
[0132] The processor is used to execute the program stored in the memory to implement the following steps of the audio playback state control method executed on the electronic device side:
[0133] In response to the audio player being started, a play state instance set of the audio player is created; the state of the audio played by the audio player is detected in real time using the play state instance set; based on the detection condition corresponding to each play state instance in the play state instance set, a target play state instance that currently meets the corresponding detection condition is determined from the play state instance set; a target state detected by the target play state instance is set as the current state of the audio player; and based on the current state, corresponding operations of the audio player are executed.
[0134] The professionals should further realize that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented by electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different circuits to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0135] The steps of the circuits or algorithms described in conjunction with the embodiments disclosed herein may be implemented using hardware, software modules executed by a processor, or a combination of the two. The software modules may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0136] It should be understood that the terms used in the text are only for the purpose of describing specific example embodiments, and are not intended to be limiting. Unless the context clearly indicates otherwise, the singular forms "one", "an" and "said" as used in the text may also be meant to include plural forms. The terms "include", "comprise", "contain", and "have" are inclusive, and therefore specify the existence of stated features, steps, operations, elements and / or parts, but do not exclude the existence or addition of one or more other features, steps, operations, elements, parts, and / or combinations thereof. The steps, processes, and operations described in the text are not interpreted as necessarily requiring them to be performed in the specific order described or illustrated, unless the execution order is clearly indicated. It should also be understood that additional or alternative steps may be used.
[0137] The above description is only a specific implementation of the present application, so that those skilled in the art can understand or implement the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest range consistent with the principles and novel features applied for herein.
Claims
1. A method for controlling audio playback status, characterized in that: The method comprises: In response to the audio player being started, creating a set of play state instances of the audio player; Using the play status instance set, detecting the state of the audio played by the audio player in real time; According to the detection condition corresponding to each play state instance in the play state instance set, determining a target play state instance that currently meets the corresponding detection condition from the play state instance set; Setting the target state detected by the target playback state instance as the current state of the audio player; According to the current state, the operation corresponding to the audio player is performed.
2. The method according to claim 1, characterized in that The step of creating a set of play status instances of the audio player includes: Creating a playback status base class, wherein the playback status base class includes a playback control method; Creating an audio player instance, and in the audio player instance, creating at least two play state instances belonging to the play state base class as the play state instance set; In the play state instance in the play state instance set, a corresponding play control method is implemented.
3. The method according to claim 2, characterized in that After performing the operation corresponding to the audio player according to the current state, the method further includes: In the current state, if the play control method included in the target play state instance is triggered, the play control operation corresponding to the play control method is executed.
4. The method according to claim 3, characterized in that: The set of playback state instances includes at least two of the following state instances related to playback control operations: a preparation state instance, a playback state instance, a pause state instance, a segment jump state instance, and a playback completion state instance; In the current state, if the play control method included in the target play state instance is triggered, the play control operation corresponding to the play control method is performed, including: If the current state is the ready state, in response to triggering the audio playing method included in the ready state instance, an audio playing operation is performed; in response to triggering the segment jumping method included in the ready state instance, an audio segment jumping operation is performed; If the current state is the playing state, in response to triggering the pause playing method included in the playing state instance, executing the pause playing operation; in response to triggering the segment jumping method included in the playing state instance, executing the audio segment jumping operation; If the current state is the pause state, in response to triggering the audio play method included in the pause state instance, an audio play operation is performed; in response to triggering the segment jump method included in the pause state instance, an audio segment jump operation is performed; If the current state is a segment jump state, in response to triggering the audio play method included in the segment jump state instance, an audio play operation is performed; in response to triggering the pause play method included in the segment jump state instance, a pause play operation is performed; If the current state is the playback completion state, in response to triggering the audio playback method contained in the playback completion state instance, an audio playback operation is performed; in response to triggering the segment jump method contained in the playback completion state instance, an audio segment jump operation is performed.
5. The method according to claim 4, characterized in that The set of playback state instances includes at least one of the following state instances that are not related to the playback control operation: an unprepared state instance, a playback error state instance; After performing the operation corresponding to the audio player according to the current state, the method further includes: If the current state is an unprepared state, in response to the completion of audio resource loading, the prepared state instance jumps the current state to the prepared state; in response to the playback error state instance detecting an audio resource loading error, the playback error state instance jumps the current state to the playback error state; If the current state is the playing state, in response to the playing error state instance detecting an audio clip loading error, the playing error state instance jumps the current state to the playing error state; If the current state is a playback error state, all operations on the audio player are stopped.
6. The method according to claim 1, characterized in that The audio player is a multi-audio player for playing multiple audios simultaneously; The step of determining, according to the detection condition corresponding to each play state instance in the play state instance set, a target play state instance that currently meets the corresponding detection condition from the play state instance set includes: For each playback state instance in the playback state instance set, if the states of at least N audios among the multiple audios meet the detection conditions corresponding to the playback state instance, the playback state instance is determined as the target playback state instance, wherein N is the preset number of detection conditions corresponding to the playback state instance.
7. The method according to claim 2, characterized in that: The audio player instance also includes a state change operation method; The step of setting the target state detected by the target playback state instance as the current state of the audio player includes: The target play state instance calls the state change operation method included in the audio player instance, and sets the target play state instance as the current play state instance included in the audio player instance; The performing an operation corresponding to the audio player according to the current state includes: The corresponding operation is performed by the current playback state instance.
8. An audio playback state control device, characterized in that: The device comprises: A creation module, used for creating a set of play status instances of the audio player in response to the audio player starting; A detection module, used to detect the state of the audio played by the audio player in real time using the set of playback state instances; a determination module, configured to determine, from the set of play state instances, a target play state instance that currently meets the corresponding detection condition according to the detection condition corresponding to each play state instance in the set of play state instances; A setting module, used for setting the target state detected by the target playback state instance as the current state of the audio player; The first execution module is used to execute the operation corresponding to the audio player according to the current state.
9. An electronic device, characterized in that: include: Memory for storing computer programs; The processor is used to execute the computer program stored in the memory, and when the computer program is executed, the audio playback state control method described in any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the audio playback status control method described in any one of claims 1 to 7 is implemented.