ȸ¿ø°¡ÀԡžÆÀ̵ð/ºñ¹øã±â
ȨÀ¸·Î

[Source] °£´ÜÇÑ MP3 Ç÷¹ÀÌ¾î ¿¹Á¦
8³â Àü
http://www.androidpub.com/?module=file&act=procFileDownload&file_srl=206343&sid=1fb9ba36f4fe9f3df9537406ca7f9ccf

import java.io.File;
import java.io.IOException;

import android.app.Activity;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

public class PlayingMp3 extends Activity implements OnClickListener,Runnable, OnCompletionListener
{
  private static final String TAG = "TEST_DEBUG";
  
  private TextView title;
  private TextView time;
  
  private ImageView plus_btn;
  private ImageView minus_btn;
  
  private ImageView rew_btn;
  private ImageView stop_btn;
  private ImageView play_btn;
  private ImageView pause_btn;
  private ImageView ff_btn;
  
  private static MediaPlayer mp;
  private ProgressBar pb;
  //private mp3Thread mp3t;
  private Thread mp3t;
  private int myDuration;
  private AudioManager am;
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.play);
    
    
    Bundle b = getIntent().getExtras();
    File basepath = Environment.getExternalStorageDirectory();
    String mp3name = b.getString("mp3name");
    
    try {
      title = (TextView)findViewById(R.id.title);
      
      time = (TextView)findViewById(R.id.time);
      
      plus_btn = (ImageView)findViewById(R.id.plus_btn);
      
      minus_btn = (ImageView)findViewById(R.id.minus_btn);
      
      rew_btn = (ImageView)findViewById(R.id.rew_btn);
      
      stop_btn = (ImageView)findViewById(R.id.stop_btn);
      
      play_btn = (ImageView)findViewById(R.id.play_btn);
      
      pause_btn = (ImageView)findViewById(R.id.pause_btn);
      
      ff_btn = (ImageView)findViewById(R.id.ff_btn);
    } catch (Exception e) {
      // TODO: handle exception
      Log.e(TAG,"ERROR: "+e.getMessage());
    }
    
    
    title.setText(mp3name);
    
    plus_btn.setOnClickListener(this);
    minus_btn.setOnClickListener(this);
    
    rew_btn.setOnClickListener(this);
    stop_btn.setOnClickListener(this);
    play_btn.setOnClickListener(this);
    pause_btn.setOnClickListener(this);
    ff_btn.setOnClickListener(this);
    
    mp = new MediaPlayer();
    
    mp.setOnCompletionListener(this);
    
    
    
    pb = new ProgressBar(this);
    try {
      mp.setDataSource(basepath.getPath()+"/"+mp3name);
      mp.prepare();
      //mp.setLooping(false);
      Log.d(TAG,"MP3 FILE ¡¼"+mp3name+"¡½ LOAD COMPLETE.");
    } catch (IllegalArgumentException e) {
      // TODO Auto-generated catch block
      Log.e(TAG,e.getMessage());
    } catch (IllegalStateException e) {
      // TODO Auto-generated catch block
      Log.e(TAG,e.getMessage());
    } catch (IOException e) {
      // TODO Auto-generated catch block
      Log.e(TAG,e.getMessage());
    }
    myDuration = mp.getDuration();
    String mp3time = changeToMinutes(myDuration);
    time.setText(mp3time);
    
    //mp3t = new mp3Thread();
    mp3t = new Thread(this);
    pb = (ProgressBar)findViewById(R.id.ProgressBar01);
    pb.setIndeterminate(false);
    
    am = (AudioManager)getSystemService(AUDIO_SERVICE);
  }
  
  
  
  public void onClick(View view)
  {
    if(view == plus_btn)
    {
      try {
        
        int vol = am.getStreamVolume(AudioManager.STREAM_MUSIC);
        //mp.setVolume(vol, vol);
        am.setStreamVolume(AudioManager.STREAM_MUSIC, vol+1, AudioManager.FLAG_SHOW_UI);
        //Toast.makeText(this, "vol:"+vol, 500).show();
        
      } catch (Exception e) {
        // TODO: handle exception
      }
    }
    else if(view == minus_btn)
    {
      try {
        int vol = am.getStreamVolume(AudioManager.STREAM_MUSIC);
        //mp.setVolume(vol, vol);
        //Toast.makeText(this, "vol:"+vol, 500).show();
        am.setStreamVolume(AudioManager.STREAM_MUSIC, vol-1, AudioManager.FLAG_SHOW_UI);
      } catch (Exception e) {
        // TODO: handle exception
      }
    }
      else if(view == rew_btn)
    {
      try {
        int curSeek = mp.getCurrentPosition();
        if(curSeek>10000)
        {
          mp.seekTo(curSeek-10000);
        }
        else
        {
          mp.seekTo(0);
        }
        Toast.makeText(this, "REW", 500).show();
      } catch (Exception e) {
        // TODO: handle exception
      }
    }
    else if(view == stop_btn)
    {
      try {
        mp.stop();
        mp.prepare();
        mp.seekTo(0);
        mp3t.stop();
        Toast.makeText(this, "STOP", 500).show();
        //mp3t = new Thread(this);
      } catch (Exception e) {
        // TODO: handle exception
      }
      
      Log.d(TAG,"MP3 FILE STOPED.");
    }
    else if(view == play_btn)
    {
      Toast.makeText(this, "PLAY", 500).show();
      try {
        mp.start();
        mp3t.start();
        
      } catch (Exception e) {
        // TODO: handle exception
      }
      
      Log.d(TAG,"MP3 FILE STARTED.");
    }
    else if(view == pause_btn)
    {
      try {
        mp.pause();
        mp3t.stop();
        Toast.makeText(this, "PAUSE", 500).show();
        //mp3t = new Thread(this);
      } catch (Exception e) {
        // TODO: handle exception
      }
      Log.d(TAG,"MP3 FILE PAUSED.");
    }
    else if(view == ff_btn)
    {
      try {
        int curSeek = mp.getCurrentPosition();
        int allSeek = mp.getDuration();
        if(curSeek+10000 < allSeek)
        {
          mp.seekTo(curSeek+10000);
        }
        else
        {
          mp.seekTo(allSeek);
        }
        Toast.makeText(this, "FF", 500).show();
      } catch (Exception e) {
        // TODO: handle exception
      }
      
    }
  }
  
  private String changeToMinutes(int mseconds)
  {
    int min = 0;
    int sec = 0;
    String minStr = "";
    String secStr = "";
    
    min = (int) Math.floor(mseconds/(1000*60));
    sec = (int) Math.floor((mseconds-(1000*60)*min)/1000);
    
    minStr = min < 10 ? "0"+min:""+min;
    secStr = sec < 10 ? "0"+sec:""+sec;
    
    return minStr+":"+secStr;
  }
  private int makePercent(int child,int parent)
  {
    int per = (int) Math.floor((child*100)/parent);
    return per;
  }
  
  private final Handler h = new Handler();
  private boolean done = false;
  
  private final Runnable mp3Run = new Runnable() {
    public void run() {
      int currentDuration = mp.getCurrentPosition();
      //time.setText(makePercent(currentDuration, myDuration));
      //time.setText(currentDuration+"_"+myDuration+"_"+makePercent(currentDuration,myDuration));
      time.setText(changeToMinutes(myDuration-currentDuration));
      pb.setProgress(makePercent(currentDuration, myDuration));
      //Toast.makeText(PlayingMp3.this, makePercent(currentDuration, myDuration)+"", 1000);
    }
  };
  
  @Override
  public void run() {
    // TODO Auto-generated method stub
    while(!done)
    {
      try {
        Thread.sleep(200);
      } catch (Exception e) {
        // TODO: handle exception
      }
      h.post(mp3Run);
    }
  }



  private void sleep(int i) {
    // TODO Auto-generated method stub
    
  }



  @Override
  public void onCompletion(MediaPlayer mp) {
    // TODO Auto-generated method stub
    try {
      mp.stop();
      mp.prepare();
      mp.seekTo(0);
      mp3t.stop();
      Toast.makeText(this, "STOP", 500).show();
    } catch (Exception e) {
      // TODO: handle exception
    }
    
  }

  
}
ÃßõÃßõ : 231 Ãßõ ¸ñ·Ï
¹øÈ£ Á¦¸ñ
1,346
À©µµ¿ì ¼­¹ö 2019 Ãë¾àÁ¡ Á¡°Ë º¸¾È
1,345
À©µµ¿ì ¼­¹ö 2019 Ãë¾àÁ¡ Á¡°Ë º¸¾È (windows server 2019)
1,344
Windows Ãë¾àÁ¡Áø´Ü º¸¾È°¡À̵å¶óÀÎ
1,343
Windows Admin Center¸¦ ÅëÇÑ ¼­¹ö °ü¸®
1,342
À©µµ¿ì ¼­¹ö¿¡¼­ ½ÇÇàµÇ´Â ¼­ºñ½º È®ÀÎ
1,341
Chrome NET::ERR CERT REVOKED ÇØ°á¹æ¹ý
1,340
cmd ¸í·É¾î (¸í·É ÇÁ·ÒÇÁÆ® ¸í·É¾î) ¸ðÀ½
1,339
Windows10 ƯÁ¤ ÇÁ·Î±×·¥(OCS 2007 R2)¿¡¼­ ÷ºÎÆÄÀÏ µå·¡±×¾Øµå·ÓÀÌ ¾È µÇ´Â Çö»ó
1,338
À©µµ¿ì ·Î±×, °ü¸® À̺¥Æ® »èÁ¦
1,337
Ŭ¸° ºÎÆÃ
1,336
Windows ±¸¼º ¿ä¼Ò ÀúÀå¼Ò¿¡¼­ ÆÄÀÏ ¼Õ»ó °Ë»ç
1,335
Windows Defender °Ë»ç ±â·Ï »èÁ¦Çϱâ
1,334
°£´ÜÇÑ À©µµ¿ì 10 Á¤Ç° ÀÎÁõ (Å©·¢ÇÁ·Î±×·¥ ÇÊ¿ä¾øÀ½)
1,333
¿À·ù³­ Æú´õ °­Á¦»èÁ¦ ¹æ¹ý
1,332
Å©·Ò¿¡¼­ Ç÷¡½Ã Ç×»ó Çã¿ëÇϵµ·Ï ¼³Á¤Çϱâ (·¹Áö½ºÆ®¸®) reg ÆÄÀÏ ¸¸µé±â
1,331
GPT µð½ºÅ©¸¦ MBR µð½ºÅ©·Î º¯È¯
1,330
MBR µð½ºÅ©¸¦ GPT µð½ºÅ©·Î º¯È¯
1,329
±¸±Û °Ë»öÀ» 200% È°¿ëÇÏ°Ô ÇØÁÖ´Â °Ë»ö ¸í·É¾î ÃÑÁ¤¸®
1,328
[Jquery] jQuery·Î ¿ìŬ¸¯ ¹æÁö, µå·¡±× ¹æÁö, ¼±Åà ¹æÁö (IE10, ÆÄÀ̾îÆø½º, Å©·Ò È®ÀÎ)
1,327
php »ç¿ëÀÚ Á¢¼ÓIP, ºê¶ó¿ìÀúÁ¤º¸, osÁ¤º¸, http, https Á¢¼ÓÇÁ·ÎÅäÄÝ ¾Ë¾Æ¿À±â
1,326
[PHP] IE ºê¶ó¿ìÀú Á¢¼Ó °ËÃâÇϱâ
1,325
À©µµ¿ì10 ½Ã½ºÅÛ ¿¹¾à ÆÄƼ¼Ç È®ÀÎ ¹× »èÁ¦
1,324
À©µµ¿ì10 º¹±¸ ÆÄƼ¼Ç »èÁ¦ ¹æ¹ý
1,323
À©µµ¿ì10 ºÎÆÃÁö¿¬ °ËÀºÈ­¸é¿¡¼­ ¸îºÐ°£ ¸Ó¹«´Â Çö»ó ÇØ°á¹æ¹ý
1,322
»ï¼º³ëÆ®ºÏ ¹ÙÀÌ¿À½º ÁøÀÔÀÌ ºÒ°¡´ÉÇÑ °æ¿ì ¹ÙÀÌ¿À½º À缳ġ¿Í NVRAM ÃʱâÈ­
1,321
ÀͽºÇ÷η¯(IE)ÀÇ ±¸±Û °Ë»ö°ø±ÞÀÚ Çѱ۷Πº¯°æ ¹æ¹ý
1,320
À©µµ¿ì 10 ±âº» ¾Û »èÁ¦ ¹× º¹±¸
1,319
meta ÅÂ±× http-equiv ¼³Á¤¹æ¹ý°ú Â÷ÀÌÁ¡
1,318
±¸±Û(Google)°Ë»ö¿¡¼­ °í±Þ¿¬»êÀÚ¸¦ ÀÌ¿ëÇÏ¿© ¸¹Àº Á¤º¸¸¦ ¾ò´Â ¹æ¹ý
1,317
ÇÁ·Î±×·¥ ¾øÀÌ Çϵåµð½ºÅ© º¹»ç ¹× ¹é¾÷Çϱâ
¸ñ·Ï
¹ÂÁ÷Æ®·ÎÆ® ºÎ»ê±¤¿ª½Ã ºÎ»êÁø±¸ °¡¾ßµ¿ ¤Ó °³ÀÎÁ¤º¸Ãë±Þ¹æħ
Copyright ¨Ï musictrot All rights reserved.