Play sound randomly from an array?

All your problems with Audio, Video and Images.

Play sound randomly from an array?

Postby Cypha Signals » Mon May 10, 2010 6:50 pm

So I have a array of around 8 files in array.clm specified like this :

<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer-array name="myArray">
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
<item>5</item>
<item>6</item>
<item>7</item>
<item>8</item>
</integer-array>
</resources>

and basically I want to play a different sound randomly based on an onClick or onShake event...I having the Listeners setup and working and I'm using MediaPlayer mp.start() to play them successfully (which seems it will only take one int at a time...The problem is

1. I'm having a bit of trouble converting the whole array to be specified by one string such as:
String soundArrayString = getArray(R.array.myArray); (I know this will not work, just trying to paint a picture :P)

2. Getting one of the items from the array randomly as the randomocity is continuously cycling through (if necessary)...

3. Using that randomly called item in the array to play the corresponding sound (String to int technique I just can't seem to understand)

Here's my code so far without any random or array codes (I've tried a lot and nothing is working):

ImageButton testbutton = (ImageButton)findViewById(R.id.button1);
testbutton.setOnClickListener(new OnClickListener() {
MediaPlayer mp = MediaPlayer.create(Project1.this,
R.raw.sound1);
public void onClick(View v) {
mp.seekTo(0);
mp.start();

Does this even seem like I'm heading the right direction for what I'm trying to accomplish?
I am the pop-locking app
Cypha Signals
Freshman
Freshman
 
Posts: 3
Joined: Mon May 03, 2010 10:43 pm
Location: California

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: Google [Bot], Google Feedfetcher and 22 guests