KulArtist
KulArtist

Reputation: 962

Store audio files in an array

I am working on an offline android quiz app and i want to store audio files in an array and play audio for different questions in a quiz. Can array be used to store audio files ? If Yes,How?

Upvotes: 3

Views: 2260

Answers (2)

KulArtist
KulArtist

Reputation: 962

Thanx to all who tried, i solved this probllem myself:

     int [] songs;
         MediaPlayer mediaPlayer;
         int current_index = 0; 

          mediaPlayer = MediaPlayer.create(this, songs[current_index]);               
                  Button play_button = (Button)this.findViewById(R.id.play);
                  play_button.setOnClickListener(new View.OnClickListener() {
                      public void onClick(View v) {
                          Log.v(TAG, "Playing sound...");
                          mediaPlayer.start();
                current_index ;
                  }
                  });

Upvotes: 3

Fahim
Fahim

Reputation: 12358

Store the audio file in the array as shown and put the audio files in raw folder

res/raw

Array of audio

int[] clips= { R.raw.button_a, R.raw.button_2, R.raw.button_3, R.raw.button_4, R.raw.button_5, R.raw.button_6 };

Pick up the audio from this array

Upvotes: 0

Related Questions