Сообщество IT-специалистов
Ответы на любые вопросы об IT
Профессиональное развитие в IT
Удаленная работа для IT-специалистов
package com.stortor.tolyapp; import android.app.Activity; import android.content.Intent; import android.media.AudioManager; import android.media.MediaPlayer; import android.media.SoundPool; import android.os.Bundle; import android.widget.Button; import android.view.View; import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; public class MainActivity extends AppCompatActivity { public Button bottomQuest; public Button bottomSettings; public Button buttonCreators; public Button playButton; public Button pauseButton; public Button stopButton; final int MAX_STREAMS = 100; MediaPlayer mediaPlayer1; int list; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mediaPlayer1 = MediaPlayer.create(this, R.raw.dragon); mediaPlayer1.setOnCompletionListener(mp -> stopPlay()); playButton = findViewById(R.id.PlayButton); pauseButton = findViewById(R.id.pauseButton); stopButton = findViewById(R.id.stopButton); pauseButton.setEnabled(false); stopButton.setEnabled(false); } public void stopPlay() { mediaPlayer1.stop(); pauseButton.setEnabled(false); stopButton.setEnabled(false); try { mediaPlayer1.prepare(); mediaPlayer1.seekTo(0); playButton.setEnabled(true); } catch (Throwable t) { Toast.makeText(this, t.getMessage(), Toast.LENGTH_SHORT).show(); } } public void play(View view) { mediaPlayer1.start(); playButton.setEnabled(false); pauseButton.setEnabled(true); stopButton.setEnabled(true); } public void pause(View view) { mediaPlayer1.pause(); playButton.setEnabled(true); pauseButton.setEnabled(false); stopButton.setEnabled(true); } public void stop(View view) { stopPlay(); } public void onDestroy() { super.onDestroy(); if (mediaPlayer1.isPlaying()) { stopPlay(); } } { SoundPool sp2 = new SoundPool(MAX_STREAMS, AudioManager.STREAM_ALARM, 1); list = sp2.load(this, R.raw.listanie, 2); bottomQuest = (Button) findViewById(R.id.bottomQuest); bottomQuest.setOnClickListener(view -> { sp2.play(1, 0, 1, 100, 0, 2); Intent intent = new Intent(MainActivity.this, QuestActivity.class); startActivity(intent); }); bottomSettings = (Button) findViewById(R.id.bottomSettings); bottomSettings.setOnClickListener(view -> { sp2.play(1, 0, 1, 100, 0, 2); Intent intent = new Intent(MainActivity.this, SettingActivity.class); startActivity(intent); }); buttonCreators = (Button) findViewById(R.id.buttonCreators); buttonCreators.setOnClickListener(view -> { sp2.play(1, 0, 1, 100, 0, 2); Intent intent = new Intent(MainActivity.this, CreatorsActivity.class); startActivity(intent); }); } }