2222import com .yanzhenjie .permission .AndPermission ;
2323import com .yanzhenjie .permission .runtime .Permission ;
2424
25- import java .text .SimpleDateFormat ;
26-
2725import io .agora .api .component .Constant ;
2826import io .agora .api .example .R ;
2927import io .agora .api .example .annotation .Example ;
@@ -202,7 +200,6 @@ public void onDestroy()
202200 /**leaveChannel and Destroy the RtcEngine instance*/
203201 if (engine != null )
204202 {
205- stopProgressTimer ();
206203 engine .leaveChannel ();
207204 }
208205 handler .post (RtcEngine ::destroy );
@@ -270,12 +267,11 @@ else if(v.getId() == R.id.bgmStart)
270267 {
271268 sliderSpeed .setProgress (50 );
272269 engine .startAudioMixing (currentMusic , false , false , -1 , 0 );
270+ engine .getAudioFileInfo (currentMusic );
273271 startProgressTimer ();
274272 }
275273 else if (v .getId () == R .id .bgmStop ){
276274 engine .stopAudioMixing ();
277- progressText .setText ("00:00" );
278- mixingProgressBar .setProgress (0 );
279275 stopProgressTimer ();
280276 }
281277 else if (v .getId () == R .id .bgmResume ){
@@ -327,15 +323,19 @@ else if (v.getId() == R.id.btn_effect)
327323 }
328324
329325 private void stopProgressTimer () {
326+ mixingProgressBar .setProgress (0 );
330327 handler .removeCallbacksAndMessages (null );
331328 }
332329
333330 private void startProgressTimer () {
334- engine .getAudioFileInfo (Constant .URL_PLAY_AUDIO_FILES );
335- int position = engine .getAudioMixingCurrentPosition ();
336- handler .post (()->mixingProgressBar .setProgress (position ));
337- handler .postDelayed (this ::startProgressTimer , 500 );
331+ if (engine != null ) {
332+ int currentPosition = engine .getAudioMixingCurrentPosition ();
333+ if (mixingProgressBar .getMax () != 0 && !mixingProgressBar .isPressed ())
334+ mixingProgressBar .setProgress (currentPosition );
335+ handler .postDelayed (this ::startProgressTimer , 1000 );
336+ }
338337 }
338+
339339 /**
340340 * @param channelId Specify the channel name that you want to join.
341341 * Users that input the same channel name join the same channel.*/
@@ -512,17 +512,8 @@ public void onUserOffline(int uid, int reason)
512512
513513 @ Override
514514 public void onRequestAudioFileInfo (AudioFileInfo info , int error ) {
515- if (info .durationMs > 0 && progressText .getText ().equals ("00:00" )) {
516- Log .d (TAG , "onRequestAudioFileInfo: " +info .durationMs );
517- handler .post (new Runnable () {
518- @ Override
519- public void run () {
520- mixingProgressBar .setMax (info .durationMs );
521- String timeString = new SimpleDateFormat ("mm:ss" ).format (info .durationMs );
522- progressText .setText (timeString );
523- }
524- });
525- }
515+ Log .d (TAG , "onRequestAudioFileInfo: " +info .durationMs );
516+ handler .post (()-> mixingProgressBar .setMax (info .durationMs ));
526517 }
527518 };
528519
@@ -549,6 +540,9 @@ else if(seekBar.getId() == R.id.mixingVolBar){
549540 * @param volume: Audio mixing volume. The value ranges between 0 and 100 (default).
550541 */
551542 engine .adjustAudioMixingVolume (progress );
543+ }else if (seekBar .getId () == R .id .mixingProgress ){
544+ String durationText = io .agora .api .example .utils .TextUtils .durationFormat ((long ) progress );
545+ progressText .setText (durationText );
552546 }else if (seekBar .getId () == R .id .slider_speed_fg_audio_file ){
553547 updateSpeedTitle ();
554548 }
0 commit comments