1

我正在实现一个新的应用程序,它使用媒体播放器播放两首歌曲。我需要做的是,当第二个玩家输出进入图片时,我需要避开第一个玩家输出。并且需要在第二个玩家完成时解开第一个玩家。这可能吗?

我的代码如下:

public class SampleMediaPlayerActivity extends Activity implements OnClickListener, OnPreparedListener {
/** Called when the activity is first created. */
Button playSong;
MediaPlayer player1;
MediaPlayer player2;
@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    playSong = (Button) findViewById(R.id.playSongButton);
    playSong.setOnClickListener(this);
    player1 = MediaPlayer.create(SampleMediaPlayerActivity.this, R.raw.song);
    player1.setVolume(100.0f, 100.0f);
    player1.setOnPreparedListener(this);
}
@Override
public void onClick(View v) 
{
    // TODO Auto-generated method stub
    System.out.println("Play song");
    //player1.setVolume(0.5, rightVolume)
    player2 = MediaPlayer.create(SampleMediaPlayerActivity.this, R.raw.song);
    player2.setVolume(100.0f, 100.0f);
    //player.
    player2.start();
}
@Override
public void onPrepared(MediaPlayer mp) 
{
    // TODO Auto-generated method stub
    player1.start();

}
}
4

0 回答 0