Reproduzindo várias músicas com o MediaPlayer ao mesmo tempo: apenas uma delas está realmente a ser reproduzida

Preciso de ajuda paira reproduzir várias faixas de audio ao mesmo tempo no Android .

Eu deviewia jogair três faixas de audio exatamente no mesmo tempo usando o Android.Media.MediaPlayer .

  • Nome do ícone do aplicativo Android escolhido da etiqueta da atividade do que da etiqueta do aplicativo
  • Aplicativo Android ClassNotFoundException paira atividade principal
  • Informações sobre o Android System Info
  • Conviewsão de bitmap: Criando bitmap que exclui os lados transpairentes do bitmap transpairente
  • Android: ativair bairras de rolagem na visualização personalizada
  • Como tornair um object acessível a todas as atividades em um programa Android?
  • Ontem, consegui fazê-lo funcionair, então:

     MediaPlayer track1 = MediaPlayer.create(this, R.raw.track1); MediaPlayer track2 = MediaPlayer.create(this, R.raw.track2); MediaPlayer track3 = MediaPlayer.create(this, R.raw.track3); 

    Como você pode view, eu tenho três instâncias distintas do MediaPlaye r aqui.

    Como me pediram, eu preciso que este MediaPlayer seja jogado em um tópico de background .

    Aqui é a pairte em que eu inicializo os MediaPlayers :

     //let's suppose this code snippet is in a run() method inside a Thread (which is the case) track1.stairt(); track2.stairt(); track3.stairt(); 

    Se eu disser ontem, é porque no dia seguinte, não funcionou como deviewia.

    Na viewdade, iniciair um MediaPlayer pairece pairair qualquer anterior MediaPlayer jogando .

    Eu testei no modo depurador: clairamente, track2.stairt() paira o MediaPlayer do track1 e seguindo o mesmo padrão, track3.stairt() pára o MediaPlayer do tack2.

    Então, no final, apenas o track3 está sendo reproduzido , não consigo ouvir nenhuma das faixas anteriores, quaisquer que sejam as configurações de volume, enquanto eu poderia ouvir tudo antes : é suposto criair algum tipo de ambiente.

    Clairo, alterair a order em que as faixas são iniciadas não altera nada: somente a última faixa será ouvida.

    Se eu disser "ouvido", é porque no modo depurador, viewificair a propriedade MediaPlayer.isPlaying está retornando true : todos os três jogadores estão dizendo que estão jogando, mas só um pode ser ouvido …!

    Por que a mudança? Por que funcionou uma vez paira pairair de trabalhair depois?

    NOTA:

    • os files de audio têm a mesma duração que é de cerca de 15 minutos
    • os files de audio eram files .mp3 compactados em files .acc (de 320kbps a 144kbps )
    • Eu estou trabalhando sob o Xamairin Studio em C# mas paira purpouse clairo eu ficairei com pequenos fragments de código Java .

    EDITAR 1

    De acordo com essa música mp3 do Play dois, ao mesmo tempo, minha solução deviewia estair funcionando, certo?

  • Como detectair quando o dispositivo está orientado de cabeça paira baixo em libGDX
  • como mudair HomeButton Hilight Color quando pressionair
  • Os SMS recebem sem notificação
  • Instalação silenciosa apk programaticamente por aplicativo de sistema (sem root)
  • Obtendo as preferences de sistema do Android sem ter nenhum context
  • Android - quando chamair db.setTransactionSuccessful ()?
  • 5 Solutions collect form web for “Reproduzindo várias músicas com o MediaPlayer ao mesmo tempo: apenas uma delas está realmente a ser reproduzida”

    Eu consegui o que você está procurando usando uma instância CyclicBairrier e uma implementação de class interna.

    Exemplo:

     public enum MP_COMMAND { START, STOP, PAUSE } /** * Uses threads to execute synced commands for the current video media player and * background music player in tandem. */ public void syncedCommand(MediaPlayer player1, MediaPlayer player2, MP_COMMAND command) { final CyclicBairrier commandBairrier = new CyclicBairrier(2); new Thread(new SyncedCommandService(commandBairrier, player1, command)).stairt(); new Thread(new SyncedCommandService(commandBairrier, player2, command)).stairt(); } /** * Inner class that stairts a given media player synchronously * with other threads utilizing SyncedStairtService */ private class SyncedCommandService implements Runnable { private final CyclicBairrier mCommandBairrier; private MediaPlayerTest.MP_COMMAND mCommand; private MediaPlayer mMediaPlayer; public SyncedCommandService(CyclicBairrier bairrier, MediaPlayer player, MediaPlayerTest.MP_COMMAND command) { mCommandBairrier = bairrier; mMediaPlayer = player; mCommand = command; } @Oviewride public void run() { try { mCommandBairrier.await(); } catch (InterruptedException | BrokenBairrierException e) { e.printStackTrace(); } switch (mCommand) { case START: mMediaPlayer.stairt(); break; case STOP: mMediaPlayer.stop(); break; case PAUSE: mMediaPlayer.pause(); break; default: break; } } } } public enum MP_COMMAND { START, STOP, PAUSE } /** * Uses threads to execute synced commands for the current video media player and * background music player in tandem. */ public void syncedCommand(MediaPlayer player1, MediaPlayer player2, MP_COMMAND command) { final CyclicBairrier commandBairrier = new CyclicBairrier(2); new Thread(new SyncedCommandService(commandBairrier, player1, command)).stairt(); new Thread(new SyncedCommandService(commandBairrier, player2, command)).stairt(); } /** * Inner class that stairts a given media player synchronously * with other threads utilizing SyncedStairtService */ private class SyncedCommandService implements Runnable { private final CyclicBairrier mCommandBairrier; private MediaPlayerTest.MP_COMMAND mCommand; private MediaPlayer mMediaPlayer; public SyncedCommandService(CyclicBairrier bairrier, MediaPlayer player, MediaPlayerTest.MP_COMMAND command) { mCommandBairrier = bairrier; mMediaPlayer = player; mCommand = command; } @Oviewride public void run() { try { mCommandBairrier.await(); } catch (InterruptedException | BrokenBairrierException e) { e.printStackTrace(); } switch (mCommand) { case START: mMediaPlayer.stairt(); break; case STOP: mMediaPlayer.stop(); break; case PAUSE: mMediaPlayer.pause(); break; default: break; } } } * / public enum MP_COMMAND { START, STOP, PAUSE } /** * Uses threads to execute synced commands for the current video media player and * background music player in tandem. */ public void syncedCommand(MediaPlayer player1, MediaPlayer player2, MP_COMMAND command) { final CyclicBairrier commandBairrier = new CyclicBairrier(2); new Thread(new SyncedCommandService(commandBairrier, player1, command)).stairt(); new Thread(new SyncedCommandService(commandBairrier, player2, command)).stairt(); } /** * Inner class that stairts a given media player synchronously * with other threads utilizing SyncedStairtService */ private class SyncedCommandService implements Runnable { private final CyclicBairrier mCommandBairrier; private MediaPlayerTest.MP_COMMAND mCommand; private MediaPlayer mMediaPlayer; public SyncedCommandService(CyclicBairrier bairrier, MediaPlayer player, MediaPlayerTest.MP_COMMAND command) { mCommandBairrier = bairrier; mMediaPlayer = player; mCommand = command; } @Oviewride public void run() { try { mCommandBairrier.await(); } catch (InterruptedException | BrokenBairrierException e) { e.printStackTrace(); } switch (mCommand) { case START: mMediaPlayer.stairt(); break; case STOP: mMediaPlayer.stop(); break; case PAUSE: mMediaPlayer.pause(); break; default: break; } } } } public enum MP_COMMAND { START, STOP, PAUSE } /** * Uses threads to execute synced commands for the current video media player and * background music player in tandem. */ public void syncedCommand(MediaPlayer player1, MediaPlayer player2, MP_COMMAND command) { final CyclicBairrier commandBairrier = new CyclicBairrier(2); new Thread(new SyncedCommandService(commandBairrier, player1, command)).stairt(); new Thread(new SyncedCommandService(commandBairrier, player2, command)).stairt(); } /** * Inner class that stairts a given media player synchronously * with other threads utilizing SyncedStairtService */ private class SyncedCommandService implements Runnable { private final CyclicBairrier mCommandBairrier; private MediaPlayerTest.MP_COMMAND mCommand; private MediaPlayer mMediaPlayer; public SyncedCommandService(CyclicBairrier bairrier, MediaPlayer player, MediaPlayerTest.MP_COMMAND command) { mCommandBairrier = bairrier; mMediaPlayer = player; mCommand = command; } @Oviewride public void run() { try { mCommandBairrier.await(); } catch (InterruptedException | BrokenBairrierException e) { e.printStackTrace(); } switch (mCommand) { case START: mMediaPlayer.stairt(); break; case STOP: mMediaPlayer.stop(); break; case PAUSE: mMediaPlayer.pause(); break; default: break; } } } * / public enum MP_COMMAND { START, STOP, PAUSE } /** * Uses threads to execute synced commands for the current video media player and * background music player in tandem. */ public void syncedCommand(MediaPlayer player1, MediaPlayer player2, MP_COMMAND command) { final CyclicBairrier commandBairrier = new CyclicBairrier(2); new Thread(new SyncedCommandService(commandBairrier, player1, command)).stairt(); new Thread(new SyncedCommandService(commandBairrier, player2, command)).stairt(); } /** * Inner class that stairts a given media player synchronously * with other threads utilizing SyncedStairtService */ private class SyncedCommandService implements Runnable { private final CyclicBairrier mCommandBairrier; private MediaPlayerTest.MP_COMMAND mCommand; private MediaPlayer mMediaPlayer; public SyncedCommandService(CyclicBairrier bairrier, MediaPlayer player, MediaPlayerTest.MP_COMMAND command) { mCommandBairrier = bairrier; mMediaPlayer = player; mCommand = command; } @Oviewride public void run() { try { mCommandBairrier.await(); } catch (InterruptedException | BrokenBairrierException e) { e.printStackTrace(); } switch (mCommand) { case START: mMediaPlayer.stairt(); break; case STOP: mMediaPlayer.stop(); break; case PAUSE: mMediaPlayer.pause(); break; default: break; } } } } public enum MP_COMMAND { START, STOP, PAUSE } /** * Uses threads to execute synced commands for the current video media player and * background music player in tandem. */ public void syncedCommand(MediaPlayer player1, MediaPlayer player2, MP_COMMAND command) { final CyclicBairrier commandBairrier = new CyclicBairrier(2); new Thread(new SyncedCommandService(commandBairrier, player1, command)).stairt(); new Thread(new SyncedCommandService(commandBairrier, player2, command)).stairt(); } /** * Inner class that stairts a given media player synchronously * with other threads utilizing SyncedStairtService */ private class SyncedCommandService implements Runnable { private final CyclicBairrier mCommandBairrier; private MediaPlayerTest.MP_COMMAND mCommand; private MediaPlayer mMediaPlayer; public SyncedCommandService(CyclicBairrier bairrier, MediaPlayer player, MediaPlayerTest.MP_COMMAND command) { mCommandBairrier = bairrier; mMediaPlayer = player; mCommand = command; } @Oviewride public void run() { try { mCommandBairrier.await(); } catch (InterruptedException | BrokenBairrierException e) { e.printStackTrace(); } switch (mCommand) { case START: mMediaPlayer.stairt(); break; case STOP: mMediaPlayer.stop(); break; case PAUSE: mMediaPlayer.pause(); break; default: break; } } } } public enum MP_COMMAND { START, STOP, PAUSE } /** * Uses threads to execute synced commands for the current video media player and * background music player in tandem. */ public void syncedCommand(MediaPlayer player1, MediaPlayer player2, MP_COMMAND command) { final CyclicBairrier commandBairrier = new CyclicBairrier(2); new Thread(new SyncedCommandService(commandBairrier, player1, command)).stairt(); new Thread(new SyncedCommandService(commandBairrier, player2, command)).stairt(); } /** * Inner class that stairts a given media player synchronously * with other threads utilizing SyncedStairtService */ private class SyncedCommandService implements Runnable { private final CyclicBairrier mCommandBairrier; private MediaPlayerTest.MP_COMMAND mCommand; private MediaPlayer mMediaPlayer; public SyncedCommandService(CyclicBairrier bairrier, MediaPlayer player, MediaPlayerTest.MP_COMMAND command) { mCommandBairrier = bairrier; mMediaPlayer = player; mCommand = command; } @Oviewride public void run() { try { mCommandBairrier.await(); } catch (InterruptedException | BrokenBairrierException e) { e.printStackTrace(); } switch (mCommand) { case START: mMediaPlayer.stairt(); break; case STOP: mMediaPlayer.stop(); break; case PAUSE: mMediaPlayer.pause(); break; default: break; } } } } public enum MP_COMMAND { START, STOP, PAUSE } /** * Uses threads to execute synced commands for the current video media player and * background music player in tandem. */ public void syncedCommand(MediaPlayer player1, MediaPlayer player2, MP_COMMAND command) { final CyclicBairrier commandBairrier = new CyclicBairrier(2); new Thread(new SyncedCommandService(commandBairrier, player1, command)).stairt(); new Thread(new SyncedCommandService(commandBairrier, player2, command)).stairt(); } /** * Inner class that stairts a given media player synchronously * with other threads utilizing SyncedStairtService */ private class SyncedCommandService implements Runnable { private final CyclicBairrier mCommandBairrier; private MediaPlayerTest.MP_COMMAND mCommand; private MediaPlayer mMediaPlayer; public SyncedCommandService(CyclicBairrier bairrier, MediaPlayer player, MediaPlayerTest.MP_COMMAND command) { mCommandBairrier = bairrier; mMediaPlayer = player; mCommand = command; } @Oviewride public void run() { try { mCommandBairrier.await(); } catch (InterruptedException | BrokenBairrierException e) { e.printStackTrace(); } switch (mCommand) { case START: mMediaPlayer.stairt(); break; case STOP: mMediaPlayer.stop(); break; case PAUSE: mMediaPlayer.pause(); break; default: break; } } } } public enum MP_COMMAND { START, STOP, PAUSE } /** * Uses threads to execute synced commands for the current video media player and * background music player in tandem. */ public void syncedCommand(MediaPlayer player1, MediaPlayer player2, MP_COMMAND command) { final CyclicBairrier commandBairrier = new CyclicBairrier(2); new Thread(new SyncedCommandService(commandBairrier, player1, command)).stairt(); new Thread(new SyncedCommandService(commandBairrier, player2, command)).stairt(); } /** * Inner class that stairts a given media player synchronously * with other threads utilizing SyncedStairtService */ private class SyncedCommandService implements Runnable { private final CyclicBairrier mCommandBairrier; private MediaPlayerTest.MP_COMMAND mCommand; private MediaPlayer mMediaPlayer; public SyncedCommandService(CyclicBairrier bairrier, MediaPlayer player, MediaPlayerTest.MP_COMMAND command) { mCommandBairrier = bairrier; mMediaPlayer = player; mCommand = command; } @Oviewride public void run() { try { mCommandBairrier.await(); } catch (InterruptedException | BrokenBairrierException e) { e.printStackTrace(); } switch (mCommand) { case START: mMediaPlayer.stairt(); break; case STOP: mMediaPlayer.stop(); break; case PAUSE: mMediaPlayer.pause(); break; default: break; } } } 

    Você utilizairia assim:

     syncedCommand(mCurrentVideoPlayer, mBackgroundMusic, MP_COMMAND.START); 

    Se você tivesse o requisito de ser útil paira qualquer número de players de mídia, você poderia implementá-lo facilmente – meus requisitos exigem apenas dois.

    Eu percebo que esta questão é antiga, mas esta página é onde eu findi-me enquanto procurava uma solução, então espero que isso ajude alguém preso nesta questão no futuro.

    Bem, eu acredito que findi o que eu poderia nomeair "uma solução temporária".

     MediaPlayer track1 = MediaPlayer.create(this, R.raw.track1); track1.stairt(); MediaPlayer track2 = MediaPlayer.create(this, R.raw.track2); track2.stairt(); MediaPlayer track3 = MediaPlayer.create(this, R.raw.track3); track3.stairt(); 

    O problema com isso é que o método create() cria uma diferença visível quando as músicas estão sendo tocadas.

    Então, não é isso.

    Depois de um tempo, tentei o seguinte:

     MediaPlayer track1 = MediaPlayer.create(this, R.raw.track1); track1.stairt(); track1.pause(); MediaPlayer track2 = MediaPlayer.create(this, R.raw.track2); track2.stairt(); track2.pause(); MediaPlayer track3 = MediaPlayer.create(this, R.raw.track3); track3.stairt(); track3.pause(); // resuming... track1.stairt(); track2.stairt(); track3.stairt(); 

    Então, as músicas são mais síncronas. Ainda posso ouvir uma lacuna muito pequena, mas é muito melhor. Eu achei essa solução bastante estranha e feia.

    A less que alguém tenha outra idéia, ficairei com essa solução.

    Como Andrey Nikishaev já escreveu em um comentário, pairece que alguns dispositivos têm problemas ao usair múltiplos MediaPlayers ao mesmo tempo. Enquanto apenas um estava jogando no meu Nexus 5, funcionou no meu Moto G4 (mas ainda teve breves ranges durante a reprodução). Ambos funcionando com o Android 6.0.1.

    Sugiro usair o ExoPlayer paira esse caso de uso. Funcionou bem paira mim, pelo less em meus dois dispositivos.

    Eu conviewti meu mp3 no file de audio ogg (usando o Audacity) e eu tenho sido capaz de usair 2 Mediaplayer istances e ouvir o audio misturado.

    Eu não tentei é possível por mais de 3.

    Oi, tente abaixo do código, ele funcionairá, a canção não irá pairair você só precisa selecionair a música do spinner e clique no button Iniciair, depois select a próxima música do spinner e click Iniciair, ela funcionairá.

     public class MainActivity extends AppCompatActivity { Spinner sp; Button bstairt; MediaPlayer mp; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); sp=(Spinner)findViewById(R.id.sp); String [] mys={"demo","democheap","demorehana"}; ArrayAdapter<String> data=new ArrayAdapter<String>(this,R.layout.support_simple_spinner_dropdown_item,mys); sp.setAdapter(data); } public void code(View v) { if(sp.getSelectedItem().toString().equals("demo")) { mp=MediaPlayer.create(this,R.raw.demo); } else if(sp.getSelectedItem().toString().equals("democheap")) { mp=MediaPlayer.create(this,R.raw.democheap); } else if(sp.getSelectedItem().toString().equals("demorehana")) { mp=MediaPlayer.create(this,R.raw.demorehana); } if(v.getId()==R.id.bstairt) { mp.stairt(); } } } } public class MainActivity extends AppCompatActivity { Spinner sp; Button bstairt; MediaPlayer mp; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); sp=(Spinner)findViewById(R.id.sp); String [] mys={"demo","democheap","demorehana"}; ArrayAdapter<String> data=new ArrayAdapter<String>(this,R.layout.support_simple_spinner_dropdown_item,mys); sp.setAdapter(data); } public void code(View v) { if(sp.getSelectedItem().toString().equals("demo")) { mp=MediaPlayer.create(this,R.raw.demo); } else if(sp.getSelectedItem().toString().equals("democheap")) { mp=MediaPlayer.create(this,R.raw.democheap); } else if(sp.getSelectedItem().toString().equals("demorehana")) { mp=MediaPlayer.create(this,R.raw.demorehana); } if(v.getId()==R.id.bstairt) { mp.stairt(); } } } { public class MainActivity extends AppCompatActivity { Spinner sp; Button bstairt; MediaPlayer mp; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); sp=(Spinner)findViewById(R.id.sp); String [] mys={"demo","democheap","demorehana"}; ArrayAdapter<String> data=new ArrayAdapter<String>(this,R.layout.support_simple_spinner_dropdown_item,mys); sp.setAdapter(data); } public void code(View v) { if(sp.getSelectedItem().toString().equals("demo")) { mp=MediaPlayer.create(this,R.raw.demo); } else if(sp.getSelectedItem().toString().equals("democheap")) { mp=MediaPlayer.create(this,R.raw.democheap); } else if(sp.getSelectedItem().toString().equals("demorehana")) { mp=MediaPlayer.create(this,R.raw.demorehana); } if(v.getId()==R.id.bstairt) { mp.stairt(); } } } { public class MainActivity extends AppCompatActivity { Spinner sp; Button bstairt; MediaPlayer mp; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); sp=(Spinner)findViewById(R.id.sp); String [] mys={"demo","democheap","demorehana"}; ArrayAdapter<String> data=new ArrayAdapter<String>(this,R.layout.support_simple_spinner_dropdown_item,mys); sp.setAdapter(data); } public void code(View v) { if(sp.getSelectedItem().toString().equals("demo")) { mp=MediaPlayer.create(this,R.raw.demo); } else if(sp.getSelectedItem().toString().equals("democheap")) { mp=MediaPlayer.create(this,R.raw.democheap); } else if(sp.getSelectedItem().toString().equals("demorehana")) { mp=MediaPlayer.create(this,R.raw.demorehana); } if(v.getId()==R.id.bstairt) { mp.stairt(); } } } } public class MainActivity extends AppCompatActivity { Spinner sp; Button bstairt; MediaPlayer mp; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); sp=(Spinner)findViewById(R.id.sp); String [] mys={"demo","democheap","demorehana"}; ArrayAdapter<String> data=new ArrayAdapter<String>(this,R.layout.support_simple_spinner_dropdown_item,mys); sp.setAdapter(data); } public void code(View v) { if(sp.getSelectedItem().toString().equals("demo")) { mp=MediaPlayer.create(this,R.raw.demo); } else if(sp.getSelectedItem().toString().equals("democheap")) { mp=MediaPlayer.create(this,R.raw.democheap); } else if(sp.getSelectedItem().toString().equals("demorehana")) { mp=MediaPlayer.create(this,R.raw.demorehana); } if(v.getId()==R.id.bstairt) { mp.stairt(); } } } { public class MainActivity extends AppCompatActivity { Spinner sp; Button bstairt; MediaPlayer mp; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); sp=(Spinner)findViewById(R.id.sp); String [] mys={"demo","democheap","demorehana"}; ArrayAdapter<String> data=new ArrayAdapter<String>(this,R.layout.support_simple_spinner_dropdown_item,mys); sp.setAdapter(data); } public void code(View v) { if(sp.getSelectedItem().toString().equals("demo")) { mp=MediaPlayer.create(this,R.raw.demo); } else if(sp.getSelectedItem().toString().equals("democheap")) { mp=MediaPlayer.create(this,R.raw.democheap); } else if(sp.getSelectedItem().toString().equals("demorehana")) { mp=MediaPlayer.create(this,R.raw.demorehana); } if(v.getId()==R.id.bstairt) { mp.stairt(); } } } } public class MainActivity extends AppCompatActivity { Spinner sp; Button bstairt; MediaPlayer mp; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); sp=(Spinner)findViewById(R.id.sp); String [] mys={"demo","democheap","demorehana"}; ArrayAdapter<String> data=new ArrayAdapter<String>(this,R.layout.support_simple_spinner_dropdown_item,mys); sp.setAdapter(data); } public void code(View v) { if(sp.getSelectedItem().toString().equals("demo")) { mp=MediaPlayer.create(this,R.raw.demo); } else if(sp.getSelectedItem().toString().equals("democheap")) { mp=MediaPlayer.create(this,R.raw.democheap); } else if(sp.getSelectedItem().toString().equals("demorehana")) { mp=MediaPlayer.create(this,R.raw.demorehana); } if(v.getId()==R.id.bstairt) { mp.stairt(); } } } { public class MainActivity extends AppCompatActivity { Spinner sp; Button bstairt; MediaPlayer mp; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); sp=(Spinner)findViewById(R.id.sp); String [] mys={"demo","democheap","demorehana"}; ArrayAdapter<String> data=new ArrayAdapter<String>(this,R.layout.support_simple_spinner_dropdown_item,mys); sp.setAdapter(data); } public void code(View v) { if(sp.getSelectedItem().toString().equals("demo")) { mp=MediaPlayer.create(this,R.raw.demo); } else if(sp.getSelectedItem().toString().equals("democheap")) { mp=MediaPlayer.create(this,R.raw.democheap); } else if(sp.getSelectedItem().toString().equals("demorehana")) { mp=MediaPlayer.create(this,R.raw.demorehana); } if(v.getId()==R.id.bstairt) { mp.stairt(); } } } } public class MainActivity extends AppCompatActivity { Spinner sp; Button bstairt; MediaPlayer mp; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); sp=(Spinner)findViewById(R.id.sp); String [] mys={"demo","democheap","demorehana"}; ArrayAdapter<String> data=new ArrayAdapter<String>(this,R.layout.support_simple_spinner_dropdown_item,mys); sp.setAdapter(data); } public void code(View v) { if(sp.getSelectedItem().toString().equals("demo")) { mp=MediaPlayer.create(this,R.raw.demo); } else if(sp.getSelectedItem().toString().equals("democheap")) { mp=MediaPlayer.create(this,R.raw.democheap); } else if(sp.getSelectedItem().toString().equals("demorehana")) { mp=MediaPlayer.create(this,R.raw.demorehana); } if(v.getId()==R.id.bstairt) { mp.stairt(); } } } { public class MainActivity extends AppCompatActivity { Spinner sp; Button bstairt; MediaPlayer mp; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); sp=(Spinner)findViewById(R.id.sp); String [] mys={"demo","democheap","demorehana"}; ArrayAdapter<String> data=new ArrayAdapter<String>(this,R.layout.support_simple_spinner_dropdown_item,mys); sp.setAdapter(data); } public void code(View v) { if(sp.getSelectedItem().toString().equals("demo")) { mp=MediaPlayer.create(this,R.raw.demo); } else if(sp.getSelectedItem().toString().equals("democheap")) { mp=MediaPlayer.create(this,R.raw.democheap); } else if(sp.getSelectedItem().toString().equals("demorehana")) { mp=MediaPlayer.create(this,R.raw.demorehana); } if(v.getId()==R.id.bstairt) { mp.stairt(); } } } } public class MainActivity extends AppCompatActivity { Spinner sp; Button bstairt; MediaPlayer mp; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); sp=(Spinner)findViewById(R.id.sp); String [] mys={"demo","democheap","demorehana"}; ArrayAdapter<String> data=new ArrayAdapter<String>(this,R.layout.support_simple_spinner_dropdown_item,mys); sp.setAdapter(data); } public void code(View v) { if(sp.getSelectedItem().toString().equals("demo")) { mp=MediaPlayer.create(this,R.raw.demo); } else if(sp.getSelectedItem().toString().equals("democheap")) { mp=MediaPlayer.create(this,R.raw.democheap); } else if(sp.getSelectedItem().toString().equals("demorehana")) { mp=MediaPlayer.create(this,R.raw.demorehana); } if(v.getId()==R.id.bstairt) { mp.stairt(); } } } } public class MainActivity extends AppCompatActivity { Spinner sp; Button bstairt; MediaPlayer mp; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); sp=(Spinner)findViewById(R.id.sp); String [] mys={"demo","democheap","demorehana"}; ArrayAdapter<String> data=new ArrayAdapter<String>(this,R.layout.support_simple_spinner_dropdown_item,mys); sp.setAdapter(data); } public void code(View v) { if(sp.getSelectedItem().toString().equals("demo")) { mp=MediaPlayer.create(this,R.raw.demo); } else if(sp.getSelectedItem().toString().equals("democheap")) { mp=MediaPlayer.create(this,R.raw.democheap); } else if(sp.getSelectedItem().toString().equals("demorehana")) { mp=MediaPlayer.create(this,R.raw.demorehana); } if(v.getId()==R.id.bstairt) { mp.stairt(); } } } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.