Dynamic control method for volume of player

文档序号:812525 发布日期:2021-03-26 浏览:18次 中文

阅读说明:本技术 一种播放器音量动态控制方法 (Dynamic control method for volume of player ) 是由 李金国 雷媛媛 于 2020-12-09 设计创作,主要内容包括:本发明公开了一种播放器音量动态控制方法,在播放器起播时,读取系统音量,根据系统音量与受控阈值,利用音量控制函数进行计算得到需要调整的音量缩放因子scale,并设置给播放器;注册系统音量变化的监听广播,在收到系统音量变化广播后,读取系统音量,重新利用音量控制函数进行计算得到新的音量缩放因子scale,并设置给播放器。本发明能够保证播放器在起播瞬间,实际的播放音量就在受控阈值内,同时系统音量发生变化,实际的播放音量也不会超出阈值,保证播放器的播放体验。并且,所有的音量调整都是基于系统音量调整MediaPlayer的音量,不会影响用户设置的系统音量。(The invention discloses a dynamic control method for volume of a player, which comprises the steps of reading system volume when the player plays, calculating by using a volume control function according to the system volume and a controlled threshold value to obtain a volume scaling factor scale needing to be adjusted, and setting the volume scaling factor scale to the player; and registering a monitoring broadcast of the system volume change, reading the system volume after receiving the system volume change broadcast, calculating by using the volume control function again to obtain a new volume scaling factor scale, and setting the new volume scaling factor scale to the player. The invention can ensure that the actual playing volume is within the controlled threshold value at the moment of starting playing of the player, and meanwhile, the system volume changes, so that the actual playing volume does not exceed the threshold value, thereby ensuring the playing experience of the player. Moreover, all volume adjustment is based on the system volume to adjust the volume of the MediaPlayer, and the system volume set by the user is not influenced.)

1. A method for dynamically controlling the volume of a player is characterized by comprising the following steps:

when the player plays, the system volume is read, the volume scaling factor scale needing to be adjusted is obtained by calculating by using the volume control function according to the system volume and the controlled threshold value, and the volume scaling factor scale is set for the player.

2. Player volume dynamic control method as claimed in claim 1, characterized in that the volume control function is called before the start () function of MediaPlayer.

3. The method of claim 1, wherein the controlled threshold is provided by a local fixed and/or cloud delivery.

4. The method for dynamically controlling the volume of a player according to any one of claims 1 to 3, further comprising:

and registering a monitoring broadcast of the system volume change, reading the system volume after receiving the system volume change broadcast, calculating by using the volume control function again to obtain a new volume scaling factor scale, and setting the new volume scaling factor scale to the player.

5. Player volume dynamic control method according to claim 4,

the system volume change broadcast registration is called before the start () function of MediaPlayer.

Technical Field

The invention relates to the technical field of data communication, in particular to a dynamic player volume control method.

Background

On an Android device, when a media player is used for playing audio and video, the default condition is that the system volume is followed, and the system volume is changed along with the adjustment of a user on the volume. In some scenes, such as scenes of pushed advertisements and the like which may be presented at any time, if the volume of the system is too large, the sound at the moment of playing the advertisement video is very large, and the user experience is seriously affected, so a method is needed for dynamically balancing and controlling the audio and video volume in such scenes. In the conventional method, after the media starts to be played, the system volume is set to be a smaller value, and the system volume is restored after the playing is finished. Another method is to directly adjust the volume of MediaPlayer, but there may still be a problem of loud sound due to uncertainty of the system volume.

Disclosure of Invention

The invention provides a dynamic player volume control method, which aims to solve the problem of poor user experience caused by overlarge volume in a part of playing scenes in the prior art.

The technical scheme adopted by the invention is as follows: a dynamic player volume control method comprises the following steps:

when the player plays, the system volume is read, the volume scaling factor scale needing to be adjusted is obtained by calculating by using the volume control function according to the system volume and the controlled threshold value, and the volume scaling factor scale is set for the player.

Preferably, the volume control function is called before a start () function of MediaPlayer.

Preferably, the providing manner of the controlled threshold includes local fixing and/or cloud sending.

Preferably, the method further comprises:

and registering a monitoring broadcast of the system volume change, reading the system volume after receiving the system volume change broadcast, calculating by using the volume control function again to obtain a new volume scaling factor scale, and setting the new volume scaling factor scale to the player.

Preferably, the system volume change broadcast registry is called before the start () function of MediaPlayer.

The invention has the beneficial effects that: based on the method provided by the patent, the actual playing volume of the player can be guaranteed to be within the controlled threshold value at the moment of starting playing, meanwhile, the system volume changes, the actual playing volume cannot exceed the threshold value, and the playing experience of the player is guaranteed. Moreover, all volume adjustment is based on the system volume to adjust the volume of the MediaPlayer, and the system volume set by the user is not influenced.

Drawings

Fig. 1 is a schematic flow chart of a method for dynamically controlling the volume of a player according to the present invention.

Detailed Description

In order to make the objects, technical solutions and advantages of the present invention clearer, the present invention will be described in further detail below with reference to the accompanying drawings, but embodiments of the present invention are not limited thereto.

It should be understood that the various steps recited in the method embodiments of the present disclosure may be performed in a different order, and/or performed in parallel. Moreover, method embodiments may include additional steps and/or omit performing the illustrated steps. The scope of the present disclosure is not limited in this respect.

Example 1:

referring to fig. 1, a method for dynamically controlling the volume of a player, when the player plays, the system volume at that time may be set to be very large, and the sound at the moment of playing is abnormally large, resulting in poor user experience. Aiming at the problem, the invention controls the volume of the player during playing as follows:

step A1: after initialization during playing, monitoring the loading of the player is added, and the volume control function can be inserted before the start () function is ready to be called after the loading is finished.

Step A2: based on step a1, after the preparation of the player, the volume control function is called to adjust the volume before the start is ready for playing.

Step A3: based on step a2, the volume control function is implemented by reading the current system volume value x through getStreamVolume function of AudioManager, and adjusting according to the controlled threshold (a, b) and the function, for example: scale ═ 1.0(x < a), scale ═ a + (x-a)/(100-a)/(b-a))/x; (x > ═ a, x < ═ 100). The volume control function is a scaling value which can map the system volume to the controlled threshold value according to the current system volume value and the controlled threshold value, and the function can be adjusted according to actual control requirements.

Based on the steps a1-A3, the dynamic adjustment of the volume at the time of playing the player is completed, but the volume may still be large because the user may manually adjust the system volume during playing. Aiming at the problem, the invention controls the dynamic volume in the playing process by the following method:

step B1: listening to system volume change broadcast (android. media. volume _ CHANGED _ ACTION ") is synchronously added while the player is playing.

And B2, immediately executing the volume control function realized in the step A3 after receiving the system volume change broadcast, reading the changed system volume, recalculating the volume to obtain a zoom value and adjusting the zoom value.

Specifically, based on the volume adjustments mentioned in steps a1-A3 and B1-B2, the volume adjustment is specifically performed in the following manner:

the volume scale factor scale value calculated in a1-A3 and B1-B2 is set to MediaPlayer by setVolume method of MediaPlayer.

The above examples are only intended to illustrate the technical solution of the present invention, but not to limit it; although the invention has been described in detail with reference to the foregoing embodiments, it will be understood by those skilled in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions of the embodiments of the present invention.

5页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:一种确定起始及其在数码信号中的位置的方法、数码信号处理器以及声频系统

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!