반응형
Notice
Recent Posts
Recent Comments
«   2024/12   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
Archives
Today
Total
관리 메뉴

Do Something IT

[안드로이드] MediaPlayer SeekBar 연동 본문

Android

[안드로이드] MediaPlayer SeekBar 연동

아낙시만더 2010. 12. 20. 13:51
반응형

MediaPlayer의 진행항태를 seekbar를 통하여 나타내고 싶었다 그래서 나는 CountDownTimer를 이용하여 작성 해보았다.

seekPlayBar = (SeekBar) findViewById(R.id.mp_seekbar_playbar);
  mp = Cmp.getMp();
  date = new Date();
  date.setMinutes(0);
  int sec = mp.getDuration() / 1000;
  date.setSeconds(sec);
  SimpleDateFormat formatter = new SimpleDateFormat("mm:ss");
  String str = formatter.format(date.getTime());
  fulltime.setText(str);
  if (str.equals("00:00")) {
   new AlertDialog.Builder(MusicPlayerActivity.this)
     .setMessage(new TextGroup().NETWORKERRORMESSAGE)
     .setPositiveButton("확인",
       new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog,
          int which) {
         onBackPressed();
        }
       }).setNegativeButton("안함", null).show();
  }
  runtime.setText("00:00");

  timer = new CountDownTimer(mp.getDuration() * 1000, 500) {
   public synchronized void onTick(long millisUntilFinished) {
    if (CoolTimerFlag) {
     sum = sum + 500;
     time = (int) sum / 1000;
     date.setSeconds((int) time);
     SimpleDateFormat formatter = new SimpleDateFormat("mm:ss");
     String str = formatter.format(date.getTime());
     runtime.setText(str);
     seekPlayBar.setProgress(time * 1000);
    }
   }

   public void onFinish() {
   }
  };

  seekPlayBar.setMax(mp.getDuration());
  seekPlayBar.setProgress(mp.getCurrentPosition());

  seekPlayBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
   public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
   }

   public synchronized void onStartTrackingTouch(SeekBar seekBar) {
    CoolTimerFlag = false;
    mp.pause();
   }

   public synchronized void onStopTrackingTouch(SeekBar seekBar) {
    mp.seekTo(seekBar.getProgress());
    sum = mp.getCurrentPosition();
    mp.start();
    Mpbutton[2].setBackgroundResource(R.drawable.btn_b_alb_stop);
    CoolTimerFlag = true;
   }
  });

반응형
Comments