-1
내가 모든 것을 시도하고, 아무것도 내가 stackflow에서 많은 코드를 시도하지 여전히 아무것도 ... 작동하지 않습니다는 다음 노래를 재생하지 않음 자동으로 다음 노래를 재생할 수 있습니다. 당신은 단지 MediaPlayer를위한 새로운 데이터 소스를 설정할 수 없습니다MediaPlayer를 자동으로
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.ImageButton;
import android.widget.TextView;
import java.io.IOException;
public class MainActivity extends ActionBarActivity {
final String songs_url[] = {
"http://www.aap.nl/images/stories/audio/am2012-10sec-bel.mp3",
"http://www.cse.org.uk/downloads/file/42187%20CSE%20-%20Free%20loft%20&%20Cavity%20Wall%20Insulation%20-%2010%20sec.mp3",
"http://soundsleepstudio.com/soundsleep/Sounds/washing-machine-10-sec.mp3"
};
private TextView SongTitle;
private int counter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
supportRequestWindowFeature(Window.FEATURE_NO_TITLE); //fullscreen
setContentView(R.layout.activity_main);
counter = 0;
final ImageButton btnPlay = (ImageButton) findViewById(R.id.playAndPauseButton);
SongTitle = (TextView) findViewById(R.id.textViewSongTitle);
final MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
btnPlay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
SongTitle.setText(songs_url[counter]);
if (mediaPlayer.isPlaying()) {
btnPlay.setBackgroundResource(R.drawable.playbutton);
mediaPlayer.pause();
} else {
btnPlay.setBackgroundResource(R.drawable.pausebutton);
try {
mediaPlayer.setDataSource(songs_url[0]);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
mediaPlayer.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
mediaPlayer.start();
}
}
});
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
for (int i = 0; i < 10; i++) {
try {
mediaPlayer.setDataSource(songs_url[counter]);
} catch (IOException e) {
e.printStackTrace();
}
try {
mediaPlayer.prepare();
} catch (IOException e) {
e.printStackTrace();
}
mediaPlayer.start();
}
}
});
}
실패하는 방법에 대해 자세히 설명해 주시겠습니까? – pquest
충돌을 클릭하고 첫 번째 노래를 계속해서 재생하고 다시 클릭하면 첫 번째 노래를 재생 한 다음 중지합니다. –