1

我正在尝试在我的应用程序中为所有活动制作一首歌曲。我在第一个活动中设置了 MediaPlayer,它播放所有活动,但在游戏活动中它停止了。我尝试在游戏活动中再创建一个媒体,但它无法播放

第一个活动:

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);
4

0 回答 0