Quantcast
Viewing all articles
Browse latest Browse all 941

Using Android MediaPlayer to play sound.

Hi all, I'm trying to use the code posted here by yelele_brother to play sound in Android mode. (Code posted below for ease of reference.)

It is currently throwing an error that the getAssets(); method does not exist. I checked the Media Player reference here and can't see a getAssets() method. So since this method is no longer available, my question is: How do I make this code work? I've tried looking for ApWidgets but the google code page is shutdown, Cassette doesn't work for me and there appear to be few other solutions as far as I can find.

    import android.media.*;
    import android.content.res.*;
    void setup()
    {
      size(10,10,P2D);
      try {
        MediaPlayer snd = new MediaPlayer();
        AssetManager assets = this.getAssets();
        AssetFileDescriptor fd = assets.openFd("test.mp3");
        snd.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength());
        snd.prepare();
        snd.start();
      }
      catch (IllegalArgumentException e) {
        e.printStackTrace();
      }
      catch (IllegalStateException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }

Viewing all articles
Browse latest Browse all 941

Trending Articles