1. Download our Official Android App: Forums for Android!

Trouble with playing different sounds

Discussion in 'Music & Media' started by almostlowfatmi, Mar 4, 2011.

  1. almostlowfatmi

    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    2
    Joined:
    Mar 4, 2011

    Mar 4, 2011
    2
    0
    5
    Hello, I'm relatively new to Android development. I've made a few apps, but I decided to try my hand at implementing sound.

    Essentially, I want to play a musical scale along eight different buttons.

    Here's my code:



    Code (Text):
    1. package org.me.fartmusic;
    2.  
    3. import android.app.Activity;
    4. import android.media.MediaPlayer;
    5. import android.os.Bundle;
    6. import android.widget.Button;
    7. import android.widget.ImageView;
    8. import android.view.View;
    9.  
    10. /**
    11.  *
    12.  * @author PC
    13.  */
    14. public class Farter extends Activity {
    15.     ImageView i;
    16.     Button main, Do, Re, Mi, Fa, So, La, Ti, Do2;
    17.     MediaPlayer mp;
    18.  
    19.  
    20.     /** Called when the activity is first created. */
    21.     @Override
    22.     public void onCreate(Bundle icicle) {
    23.         super.onCreate(icicle);
    24.         setContentView(R.layout.main);
    25.         initControls();
    26.     }
    27.     private void initControls(){
    28.         i = (ImageView)  findViewById(R.id.widget19);
    29.         i.setImageResource(R.drawable.intro);
    30.         main = (Button)  findViewById(R.id.widget20);
    31.         main.setOnClickListener(new Button.OnClickListener() {public void onClick(View v) {begin();}});
    32.     }
    33.     private void begin(){
    34.         setContentView(R.layout.main2);
    35.         initControls2();
    36.  
    37.     }
    38.     private void initControls2(){
    39.         Do = (Button) findViewById(R.id.widget27);
    40.         Do.setOnClickListener(new Button.OnClickListener() {public void onClick(View v) {
    41.             mp = MediaPlayer.create(getApplicationContext(), R.raw.do1);
    42.             mp.start();
    43.             }
    44.         });
    45.         Re = (Button) findViewById(R.id.widget28);
    46.         Re.setOnClickListener(new Button.OnClickListener() {public void onClick(View v) {re();}});
    47.         Mi = (Button) findViewById(R.id.widget29);
    48.         Mi.setOnClickListener(new Button.OnClickListener() {public void onClick(View v) {mi();}});
    49.         Fa = (Button) findViewById(R.id.widget30);
    50.         Fa.setOnClickListener(new Button.OnClickListener() {public void onClick(View v) {fa();}});
    51.         So = (Button) findViewById(R.id.widget31);
    52.         So.setOnClickListener(new Button.OnClickListener() {public void onClick(View v) {so();}});
    53.         La = (Button) findViewById(R.id.widget32);
    54.         La.setOnClickListener(new Button.OnClickListener() {public void onClick(View v) {la();}});
    55.         Ti = (Button) findViewById(R.id.widget33);
    56.         Ti.setOnClickListener(new Button.OnClickListener() {public void onClick(View v) {ti();}});
    57.         Do2 = (Button) findViewById(R.id.widget34);
    58.         Do2.setOnClickListener(new Button.OnClickListener() {public void onClick(View v) {do2();}});
    59.  
    60. }
    I know I only have one of the ClickListeners up, but the others would look identical to it with different music files.

    Thanks for any help in advance!!
     

    Advertisement

  2. almostlowfatmi

    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    2
    Joined:
    Mar 4, 2011

    Mar 4, 2011
    2
    0
    5
    Any help?
    If I'm on the wrong board, please let me know to where I should move this thread!

    Thanks again!
     

Share This Page

Loading...