@@ -90,6 +90,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
9090 mixingPlayoutVolBar = view .findViewById (R .id .mixingPlayoutVolBar );
9191 mixingVolBar = view .findViewById (R .id .mixingVolBar );
9292 mixingProgressBar = view .findViewById (R .id .mixingProgress );
93+ mixingProgressBar .setOnSeekBarChangeListener (this );
9394 mixingPlayoutVolBar .setOnSeekBarChangeListener (this );
9495 mixingPublishVolBar .setOnSeekBarChangeListener (this );
9596 mixingVolBar .setOnSeekBarChangeListener (this );
@@ -228,15 +229,10 @@ public void onClick(View v)
228229 else if (v .getId () == R .id .bgmStart )
229230 {
230231 engine .startAudioMixing (Constant .MIX_FILE_PATH , false , false , -1 , 0 );
231- // String timeString = new SimpleDateFormat("mm:ss").format(engine.getAudioMixingDuration(Constant.MIX_FILE_PATH));
232- String timeString = new SimpleDateFormat ("mm:ss" ).format (engine .getAudioFileInfo (Constant .MIX_FILE_PATH ));
233- progressText .setText (timeString );
234232 startProgressTimer ();
235233 }
236234 else if (v .getId () == R .id .bgmStop ){
237235 engine .stopAudioMixing ();
238- progressText .setText ("00:00" );
239- mixingProgressBar .setProgress (0 );
240236 stopProgressTimer ();
241237 }
242238 else if (v .getId () == R .id .bgmResume ){
@@ -261,38 +257,17 @@ else if (v.getId() == R.id.btn_effect)
261257 }
262258
263259 private void stopProgressTimer () {
264- if (!progressTimer .isCancelled ()){
265- progressTimer .cancel (true );
266- }
260+ mixingProgressBar .setProgress (0 );
261+ handler .removeCallbacksAndMessages (null );
267262 }
268263
269264 private void startProgressTimer () {
270- if (!progressTimer .getStatus ().equals (AsyncTask .Status .RUNNING )){
271- progressTimer .execute ();
272- }
265+ int currentPosition = engine .getAudioMixingCurrentPosition ();
266+ if (mixingProgressBar .getMax ()!=0 && !mixingProgressBar .isPressed ())
267+ mixingProgressBar .setProgress (currentPosition );
268+ handler .postDelayed (this ::startProgressTimer , 1000 );
273269 }
274270
275- private final AsyncTask progressTimer = new AsyncTask () {
276- @ Override
277- protected Object doInBackground (Object [] objects ) {
278- while (true ){
279- try {
280- handler .post (new Runnable () {
281- @ Override
282- public void run () {
283- // final int result = (int) ((float) engine.getAudioMixingCurrentPosition() / (float) engine.getAudioMixingDuration(Constant.MIX_FILE_PATH) * 100);
284- final int result = (int ) ((float ) engine .getAudioMixingCurrentPosition () / (float ) engine .getAudioFileInfo (Constant .MIX_FILE_PATH ) * 100 );
285- mixingProgressBar .setProgress (Long .valueOf (result ).intValue ());
286- }
287- });
288- Thread .sleep (500 );
289- } catch (InterruptedException e ) {
290- Log .e (TAG , e .getMessage ());
291- }
292- }
293- }
294- };
295-
296271 /**
297272 * @param channelId Specify the channel name that you want to join.
298273 * Users that input the same channel name join the same channel.*/
@@ -395,6 +370,7 @@ public void run()
395370 bgm_pause .setEnabled (true );
396371 bgm_stop .setEnabled (true );
397372 effect .setEnabled (true );
373+ engine .getAudioFileInfo (Constant .MIX_FILE_PATH );
398374 }
399375 });
400376 }
@@ -466,6 +442,12 @@ public void onUserOffline(int uid, int reason)
466442 Log .i (TAG , String .format ("user %d offline! reason:%d" , uid , reason ));
467443 showLongToast (String .format ("user %d offline! reason:%d" , uid , reason ));
468444 }
445+
446+ @ Override
447+ public void onRequestAudioFileInfo (AudioFileInfo info , int error ) {
448+ Log .d (TAG , "onRequestAudioFileInfo: " +info .filePath );
449+ handler .post (()-> mixingProgressBar .setMax (info .durationMs ));
450+ }
469451 };
470452
471453 @ Override
@@ -491,16 +473,26 @@ else if(seekBar.getId() == R.id.mixingVolBar){
491473 * @param volume: Audio mixing volume. The value ranges between 0 and 100 (default).
492474 */
493475 engine .adjustAudioMixingVolume (progress );
476+ }else if (seekBar .getId () == R .id .mixingProgress ){
477+ String durationText = io .agora .api .example .utils .TextUtils .durationFormat ((long ) progress );
478+ progressText .setText (durationText );
494479 }
480+
495481 }
496482
497483 @ Override
498484 public void onStartTrackingTouch (SeekBar seekBar ) {
499-
485+ // no need to update when user changes
486+ if (seekBar .getId () == R .id .mixingProgress )
487+ handler .removeCallbacksAndMessages (null );
500488 }
501489
502490 @ Override
503491 public void onStopTrackingTouch (SeekBar seekBar ) {
504-
492+ if (seekBar .getId () == R .id .mixingProgress ) {
493+ engine .setAudioMixingPosition (seekBar .getProgress ());
494+ handler .postDelayed (this ::startProgressTimer , 1000 );
495+ }
505496 }
497+
506498}
0 commit comments