You are on page 1of 3

// This sketch has been tested in Processing 2.0a4 // Android SDK was installed as described at // http://wiki.processing.

org/w/Android // In that page, note the part that says Processing 2.0 is required // Remember to use "Run on Device" // (CTRL + SHIFT + R or SHIFT + click on play) import apwidgets.*; APMediaPlayer player; void setup() { player = new APMediaPlayer(this); } void draw() { } void mousePressed() { if(mouseY > height / 2) { player.setMediaFile("test2.mp3"); } else { player.setMediaFile("test.mp3"); } player.start(); } public void onDestroy() { super.onDestroy(); if(player != null) { player.release(); } } import apwidgets.*; APMediaPlayer player; void setup() { player = new APMediaPlayer(this); //create new APMediaPlayer player.setMediaFile("test.mp3"); //set the file (files are in data folder) player.start(); //start play back player.setLooping(true); //restart playback end reached player.setVolume(1.0, 1.0); //Set left and right volumes. Range is from 0.0 to 1.0 } void draw() { background(0); //set black background text(player.getDuration(), 10, 10); //display the duration of the sound text(player.getCurrentPosition(), 10, 30); //display how far the sound has pla yed }

void keyPressed() { if (key == CODED) { if (keyCode == LEFT) { player.seekTo(0); //"rewind" } else if (keyCode == RIGHT) { player.start(); //start playing sound file } else if (keyCode == DPAD) { player.pause(); //pause player } else if (keyCode == DOWN) { player.setMediaFile("test2.mp3"); //switch to other sound file } } } //The MediaPlayer must be released when the app closes public void onDestroy() { super.onDestroy(); //call onDestroy on super class if(player!=null) { //must be checked because or else crash when return from la ndscape mode player.release(); //release the player import apwidgets.*; APMediaPlayer player; void setup() { player = new APMediaPlayer(this); //create new APMediaPlayer player.setMediaFile("test.mp3"); //set the file (files are in data folder) player.start(); //start play back player.setLooping(true); //restart playback end reached player.setVolume(1.0, 1.0); //Set left and right volumes. Range is from 0.0 to 1.0 } void draw() { background(0); //set black background text(player.getDuration(), 10, 10); //display the duration of the sound text(player.getCurrentPosition(), 10, 30); //display how far the sound has pla yed } void mousePressed() { player.start(); //start playing sound file } //The MediaPlayer must be released when the app closes public void onDestroy() { super.onDestroy(); //call onDestroy on super class

if(player!=null) { //must be checked because or else crash when return from la ndscape mode player.release(); //release the player } } REMINDER: Try putting your mp3 resource in a folder named "data" ... When exporting your a pplet, Processing will move files in this "data" folder in the "assets" folder, for correct loading on your Android device. } }

You might also like