package tw.edu.hust.bn98111;

import java.io.IOException;

import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;

public class BallGameActivity extends Activity implements Callback {
	//
	private SurfaceHolder sHolder;
	private MediaPlayer mp3;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.main);
        final GameSurfaceView gv = new GameSurfaceView(this);
		sHolder = gv.getHolder();
		sHolder.addCallback(this);
        setContentView(gv);
        //
        new Thread() {
			public void run() {
				// TODO Auto-generated method stub
				while (true) {
					gv.moveBall(sHolder);
					try {
						sleep(30);
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
		}.start();
		mp3 = MediaPlayer.create(this, R.raw.apologize);
        mp3.start();
    }
	public void surfaceChanged(SurfaceHolder holder, int format, int width,
			int height) {
		// TODO Auto-generated method stub
		
	}
	public void surfaceCreated(SurfaceHolder holder) {
		// TODO Auto-generated method stub
		
	}
	public void surfaceDestroyed(SurfaceHolder holder) {
		// TODO Auto-generated method stub
		
	}
//	public void onPause() {
//		if (mp3 != null ) 
//			mp3.pause();
//	}
//	//
//	boolean bStopped = false;
//	int pos;
//	public void onStop() {
//		if (mp3 != null) {
//			pos = mp3.getCurrentPosition();
//			mp3.stop();
//			bStopped = true;
//		}
//	}
//	//
//	public void onResume() {
//		mp3.start();
//	}
//	//
//	public void onStart() {
//		if (bStopped) {
//			try {
//				mp3.prepare();
//				mp3.seekTo(pos);
//			} catch (IllegalStateException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			} catch (IOException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//		}
//	}
}