package COM.TQC.GDD03;

import android.app.Activity; 
import android.media.MediaPlayer; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.ImageButton;
import android.widget.TextView; 

public class GDD03 extends Activity {
	  
	  private ImageButton mButtonPlay, mButtonPause, mButtonStop;
	  private TextView mTextView; 
	  private MediaPlayer mMediaPlayer;
	  private boolean bIsPaused = false; 
	  
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        /*透過findViewById建構子建立TextView與ImageView物件*/ 
       
        
         
         
        mMediaPlayer = new MediaPlayer();  
        /* 將音樂以Import的方式儲存在res/raw/always.mp3 */ 
        
        

        /* 執行播放音樂的按鈕 */ 
        mButtonPlay.setOnClickListener(new ImageButton.OnClickListener() 
        { 
          
          /*覆寫OnClick事件*/
          public void onClick(View v) 
          { 
            // TODO Auto-generated method stub         
            try 
            { 
              
              
            	
            	
            } 
            catch (Exception e) 
            { 
              // TODO Auto-generated catch block 
              mTextView.setText(e.toString()); 
              e.printStackTrace(); 
            } 
          } 
        }); 
         
        /* 停止播放 */ 
        mButtonStop.setOnClickListener(new ImageButton.OnClickListener() 
        { 
         // @Override
          public void onClick(View arg0) 
          { 
            // TODO Auto-generated method stub 
            try 
            { 
              if (mMediaPlayer != null) 
              { 
                
            	  
            	  
              } 
                
            } 
            catch (Exception e) 
            { 
              // TODO Auto-generated catch block 
              mTextView.setText(e.toString()); 
              e.printStackTrace(); 
            } 
          } 
        }); 
        
        /* 暫停播放 */ 
        mButtonPause.setOnClickListener(new ImageButton.OnClickListener() 
        { 
          //@Override
          public void onClick(View arg0) 
          { 
            // TODO Auto-generated method stub 
            try 
            { 
              
            	
            	
            	
            	
            	
            	
            	
            	
            	
            } 
            catch (Exception e) 
            { 
              // TODO Auto-generated catch block 
              mTextView.setText(e.toString()); 
              e.printStackTrace(); 
            } 
          } 
        }); 
         
        /* 當MediaPlayer.OnCompletionLister會執行的Listener */  
        mMediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() 
        { 
          // @Override 
          /*覆寫檔案播出完畢事件*/
          public void onCompletion(MediaPlayer arg0) 
          { 
            try 
            { 
              
            	
            	
            	
            	
            	
            } 
            catch (Exception e) 
            { 
              mTextView.setText(e.toString()); 
              e.printStackTrace(); 
            } 
          } 
        }); 
         
        /* 當MediaPlayer.OnErrorListener會執行的Listener */ 
        mMediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() 
        { 
         // @Override //p530
          /*覆寫錯誤處理事件*/
          public boolean onError(MediaPlayer arg0, int arg1, int arg2) 
          { 
            // TODO Auto-generated method stub 
            try 
            { 
              
            	
             
            	
            	
            	
            } 
            catch (Exception e) 
            { 
              mTextView.setText(e.toString()); 
              e.printStackTrace(); 
            } 
            return false; 
          } 
        }); 
      } 

      @Override 
      /*覆寫主程式暫停狀態事件*/
      protected void onPause() 
      { 
        // TODO Auto-generated method stub 
        try 
        { 
         
        	
        	
        	
        } 
        catch (Exception e) 
        { 
          mTextView.setText(e.toString()); 
          e.printStackTrace(); 
        } 
        super.onPause(); 
      } 
    } 