Android Media Player在3个活动后停止

时间:2012-10-20 16:23:36

标签: android view android-activity media-player

我正在尝试为我的应用程序播放所有活动的歌曲。 我在第一个Activity中设置MediaPlayer并且它播放所有活动,但在游戏Activity中它停止。我尝试在游戏活动中再创建一个媒体,但它不会播放

第一项活动:

public class MainStage extends Activity implements OnClickListener {


 private Button newGameBtn,highScoreBtn;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.main_game);
    final MediaPlayer themeSong =MediaPlayer.create(this, R.raw.main_song);
    themeSong.start();
    newGameBtn=(Button)findViewById(R.id.new_game);
    newGameBtn.setOnClickListener(this);

    highScoreBtn=(Button)findViewById(R.id.high_score_btn);

    highScoreBtn.setOnClickListener(this);



}

游戏活动:

 @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    club=new Club();
    clubView = new ClubView(this, club);
    mole=new Mole();
    stageView=new StageView(this);
    moleView=new MoleView(this,mole);
    pointsView=new PointsView(this);

    time=new Time(this);
    timerView=new TimerView(this, time);

    allViews=new AllViews(this);
    allViews.setViews(stageView, moleView, pointsView, timerView,clubView);
    setContentView(allViews);
    MediaPlayer themeSong =MediaPlayer.create(this, R.raw.main_song);
    themeSong.start();

    allViews.setOnTouchListener((View.OnTouchListener)this);

0 个答案:

没有答案