|
41 | 41 | ) |
42 | 42 | public class PlayAudioFiles extends BaseFragment implements View.OnClickListener, SeekBar.OnSeekBarChangeListener { |
43 | 43 | private static final String TAG = PlayAudioFiles.class.getSimpleName(); |
| 44 | + private static final int EFFECT_SOUND_ID = 0; |
44 | 45 | private EditText et_channel; |
45 | 46 | private Button mute, join, speaker, bgm, effect; |
46 | 47 | private SeekBar mixingPublishVolBar, mixingPlayoutVolBar, mixingVolBar; |
@@ -143,24 +144,31 @@ private void preloadAudioEffect(){ |
143 | 144 | // Only mp3, aac, m4a, 3gp, and wav files are supported. |
144 | 145 | // You may need to record the sound IDs and their file paths. |
145 | 146 | int id = 0; |
146 | | - int preloadRet = audioEffectManager.preloadEffect(id++, Constant.EFFECT_FILE_PATH); |
| 147 | + audioEffectManager.preloadEffect(id++, Constant.EFFECT_FILE_PATH); |
| 148 | + } |
| 149 | + |
| 150 | + private void playEffect() { |
147 | 151 | /** Plays an audio effect file. |
148 | 152 | * Returns |
149 | 153 | * 0: Success. |
150 | 154 | * < 0: Failure. |
151 | 155 | */ |
152 | 156 | int playRet = audioEffectManager.playEffect( |
153 | | - 0, // The sound ID of the audio effect file to be played. |
| 157 | + EFFECT_SOUND_ID, // The sound ID of the audio effect file to be played. |
154 | 158 | Constant.EFFECT_FILE_PATH, // The file path of the audio effect file. |
155 | 159 | -1, // The number of playback loops. -1 means an infinite loop. |
156 | 160 | 1, // pitch The pitch of the audio effect. The value ranges between 0.5 and 2. The default value is 1 (no change to the pitch). The lower the value, the lower the pitch. |
157 | 161 | 0.0, // Sets the spatial position of the effect. 0 means the effect shows ahead. |
158 | 162 | 100, // Sets the volume. The value ranges between 0 and 100. 100 is the original volume. |
159 | 163 | true // Sets whether to publish the audio effect. |
160 | 164 | ); |
161 | | - // Pauses all audio effects. |
162 | | - int pauseRet = audioEffectManager.pauseAllEffects(); |
163 | | - Log.i(TAG, "result preloadRet:" + preloadRet + ", playRet:"+ playRet + ", pauseRet:"+ pauseRet); |
| 165 | + Log.i(TAG, "result playRet:"+ playRet); |
| 166 | + } |
| 167 | + |
| 168 | + private void stopEffect() { |
| 169 | + audioEffectManager.stopEffect( |
| 170 | + EFFECT_SOUND_ID // The sound ID of the audio effect file to be played. |
| 171 | + ); |
164 | 172 | } |
165 | 173 |
|
166 | 174 | @Override |
@@ -266,11 +274,11 @@ else if (v.getId() == R.id.btn_effect) |
266 | 274 | effect.setText(!effect.isActivated() ? getString(R.string.effect_on): getString(R.string.effect_off)); |
267 | 275 | if(effect.isActivated()){ |
268 | 276 | // Resumes playing all audio effects. |
269 | | - audioEffectManager.resumeAllEffects(); |
| 277 | + playEffect(); |
270 | 278 | } |
271 | 279 | else { |
272 | 280 | // Pauses all audio effects. |
273 | | - audioEffectManager.pauseAllEffects(); |
| 281 | + stopEffect(); |
274 | 282 | } |
275 | 283 | } |
276 | 284 | } |
|
0 commit comments