Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there an Eclipse project example of a soundboard using only one mediaplayer
    primarykey
    data
    text
    <p>I have been trying to develop an Andriod app of a simple sound board, which will play several long sounds, and only one at a time, not simultaneously. I can easily do a soundboard that uses repetitive code and many mediaplayers, but that will likely crash many devices due to allocating too many instances of MediaPlayer. I want to use a map so that I only use one mediaplayer, but after several hours, I’m still having compile problems. I could also use the App Inventor at MIT, but I don’t think I could upload that to market place without extensive key/signing hacks, so I don’t think that is a good option.</p> <p>Does anyone know if there a working code example with just a couple of sounds that use just 1 mediaplayer included with the SDK, or available online? If I could start with just a basic working design, it would save me so much time. </p> <p>My code looks like the below:</p> <pre><code>public class newBoard extends Activity { int selectedSoundId; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); *//below line causes an error due to use of "newboard"* setContentView(R.layout.newboard); final MediaPlayer player = new MediaPlayer(); final Resources res = getResources(); //just keep them in the same order, e.g. button01 is tied to backtoyou final int[] buttonIds = { R.id.button01, R.id.button02, R.id.button03, R.id.button04, R.id.button05, R.id.button06, R.id.button07, R.id.button08, R.id.button09, R.id.button10, R.id.button11, R.id.button12, R.id.button13, R.id.button14, R.id.button15, R.id.button16, R.id.button16, R.id.button17, R.id.button18, R.id.button19, R.id.button20, R.id.button21, R.id.button22, R.id.button23, R.id.button24, R.id.button25 }; final int[] soundIds = { R.raw.sound01, R.raw.sound02, R.raw.sound03, R.raw.sound04, R.raw.sound05, R.raw.sound06, R.raw.sound07, R.raw.sound08, R.raw.sound09, R.raw.sound10, R.raw.sound11, R.raw.sound12, R.raw.sound13, R.raw.sound14, R.raw.sound15, R.raw.sound16, R.raw.sound16, R.raw.sound17, R.raw.sound18, R.raw.sound19, R.raw.sound20, R.raw.sound21, R.raw.sound22, R.raw.sound23, R.raw.sound24, R.raw.sound25 }; View.OnClickListener listener = new View.OnClickListener() { public void onClick(View v) { //find the index that matches the button's ID, and then reset //the MediaPlayer instance, set the data source to the corresponding //sound effect, prepare it, and start it playing. for(int i = 0; i &lt; buttonIds.length; i++) { if(v.getId() == buttonIds[i]) { selectedSoundId = soundIds[i]; AssetFileDescriptor afd = res.openRawResourceFd(soundIds[i]); player.reset(); try { player.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength()); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { player.prepare(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } player.start(); break; } } } }; //set the same listener for every button ID, no need //to keep a reference to every button for(int i = 0; i &lt; buttonIds.length; i++) { Button soundButton = (Button)findViewById(buttonIds[i]); registerForContextMenu(soundButton); soundButton.setOnClickListener(listener); } } } </code></pre> <p>I have only one error:</p> <p>newboard cannot be resolved, or is not a field Type: Java problem</p> <p>A nice project download that could be used as a foundation would be optimal, if that exists! </p> <p>Thanks in advance for any guidance!</p> <p>Maytag87</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload