this.surfaceView=(SurfaceView)this.findViewById(R.id.surfaceView);
this.surfaceHolder=this.surfaceView.getHolder();
this.surfaceHolder.setKeepScreenOn(true);
this.surfaceHolder.addCallback(this);
this.surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
@Override
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
this.media = MediaPlayer.create(ProductGshTjianjieActivity.this, R.drawable.guanshangtong);
this.media.setAudioStreamType(AudioManager.STREAM_MUSIC);
this.media.setDisplay(surfaceHolder);
this.media.start();
}
/* (非 Javadoc)
* <p>Title : surfaceChanged</p>
* <p>Description : </p>
* @param holder
* @param format
* @param width
* @param height
* @see android.view.SurfaceHolder.Callback#surfaceChanged(android.view.SurfaceHolder, int, int, int)
*/
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
// TODO Auto-generated method stub
}
/* (非 Javadoc)
* <p>Title : surfaceDestroyed</p>
* <p>Description : </p>
* @param holder
* @see android.view.SurfaceHolder.Callback#surfaceDestroyed(android.view.SurfaceHolder)
*/
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
super.onDestroy();
if(media.isPlaying()){
media.stop();
}
media.release();
}
这样就可以完全解决这个问题了!
this.surfaceHolder=this.surfaceView.getHolder();
this.surfaceHolder.setKeepScreenOn(true);
this.surfaceHolder.addCallback(this);
this.surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
@Override
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
this.media = MediaPlayer.create(ProductGshTjianjieActivity.this, R.drawable.guanshangtong);
this.media.setAudioStreamType(AudioManager.STREAM_MUSIC);
this.media.setDisplay(surfaceHolder);
this.media.start();
}
/* (非 Javadoc)
* <p>Title : surfaceChanged</p>
* <p>Description : </p>
* @param holder
* @param format
* @param width
* @param height
* @see android.view.SurfaceHolder.Callback#surfaceChanged(android.view.SurfaceHolder, int, int, int)
*/
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
// TODO Auto-generated method stub
}
/* (非 Javadoc)
* <p>Title : surfaceDestroyed</p>
* <p>Description : </p>
* @param holder
* @see android.view.SurfaceHolder.Callback#surfaceDestroyed(android.view.SurfaceHolder)
*/
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
super.onDestroy();
if(media.isPlaying()){
media.stop();
}
media.release();
}
这样就可以完全解决这个问题了!