0

I have code that creates smaller wav file "events" from one larger wav file based on energy levels.

Depending on the structure of the orignial wav file the amount of wav file events created will vary.

I would like to create a dynamic amount of play buttons for each event that will play each event out loud.

The method to create an event has the following signature:

   public  void createEventWav(ArrayList<Double> event, String fileName, Context context) {

This will create a wav file with a unique filename.

This is the code I have currently that plays an event:

      public Button playEvent;

   playEvent= (Button) findViewById(R.id.btnPlayEvent);
    playEvent.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            playEvent( );
        }
    });





public static void playEvent(){
    try {
        MediaPlayer player = new MediaPlayer();
        player = new  MediaPlayer();
        player.setDataSource("/data/data/com.example.androidaudiorecorder/files/recording_DOG.wav");
        player.prepare();
        player.start();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (Exception e) {
        System.out.println("Exception of type : " + e.toString());
        e.printStackTrace();
    }

I would like to have one for each event created.

Please see attched for layout of app

I have already tried many of the solutions found at : How to add a button dynamically in Android?

None have worked so far.

Zoe
  • 27,060
  • 21
  • 118
  • 148
Lcarrins
  • 47
  • 5
  • You should not be creating new MediaPlayers for each sound/play event. This causes massive memory issues and other resource contention problems. Reuse the same media player, no more than 1 per activity. – Gabe Sechan Jun 14 '19 at 15:35
  • You can create a RecyclerView with the list of created events – miibpa Jun 14 '19 at 16:01

0 Answers0