TQC-310 背景播放
這是TQC的310題,
程式碼為自行撰寫,
僅供參考。
主要練習MediaPlayer,
並在背景播放。
//是否正在播放
if (mMediaPlayer.isPlaying())
{
mMediaPlayer.pause()
}
package COM.TQC.GDD03;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.widget.TextView;
public class GDD03 extends Activity
{
private MediaPlayer mMediaPlayer01;
private TextView TextView1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findview();
setmedia();
}
public void findview()
{
TextView1=(TextView)findViewById(R.id.textView1);
TextView1.setText("ready");
}
public void setmedia()
{
mMediaPlayer01=MediaPlayer.create(this,R.raw.light);
mMediaPlayer01.start();
if(mMediaPlayer01.isPlaying())
{
TextView1.setText("isPlaying");
}
}
protected void onPause()
{
mMediaPlayer01.stop();
if(!mMediaPlayer01.isPlaying())
{
TextView1.setText("stop");
}
super.onPause();
}
protected void onResume()
{
mMediaPlayer01.start();
if(mMediaPlayer01.isPlaying())
{
TextView1.setText("isPlaying");
}
super.onResume();
}
}
自我LV~