0

It prints the statement however but it is not playing the music. I have posted my code below.

    if(intent.getAction().toString().equalsIgnoreCase("android.provider.Telephony.SMS_RECEIVED") ) //.equalsIgnoreCase("android.provider.Telephony.SMS_RECEIVED"))

    {
        notificationfunction();
        System.out.println("message receive inside power receiver");
    }
}

private void notificationfunction() 
{
    /*  // TODO Auto-generated method stub
                        if ( mMediaPlayer.isPlaying() )  // Checking if already playing any song
                        {
                             mMediaPlayer.reset();
                             //mMediaPlayer.stop();

                        }
     */
    switch (np)
    {
    case R.id.nradioButton1:
        mMediaPlayer = MediaPlayer.create(context, R.raw.notification1);
        mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mMediaPlayer.setLooping(true);

        if ( mMediaPlayer.isPlaying() )  // Checking if already playing any song
        {
            mMediaPlayer.reset();
        }
        mMediaPlayer.start();
        break;

    case R.id.nradioButton2:
        mMediaPlayer = MediaPlayer.create(context, R.raw.notification2);
        mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mMediaPlayer.setLooping(true);
        if ( mMediaPlayer.isPlaying() )  // Checking if already playing any song
        {
            mMediaPlayer.reset();
        }
        mMediaPlayer.start();
        break;

    case R.id.nradioButton3:
        mMediaPlayer = MediaPlayer.create(context, R.raw.notification3);
        mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mMediaPlayer.setLooping(true);
        if ( mMediaPlayer.isPlaying() )  // Checking if already playing any song
        {
            mMediaPlayer.reset();
        }
        mMediaPlayer.start();
        break;

    case  R.id.nradioButton4:
        mMediaPlayer = MediaPlayer.create(context, R.raw.notification4);
        mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mMediaPlayer.setLooping(true);

        if ( mMediaPlayer.isPlaying() )  // Checking if already playing any song
        {
            mMediaPlayer.reset();
        }
        mMediaPlayer.start();
        break;

    case R.id.nradioButton5:
        mMediaPlayer = MediaPlayer.create(context, R.raw.notification5);
        mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mMediaPlayer.setLooping(true);

        if ( mMediaPlayer.isPlaying() )  // Checking if already playing any song
        {
            mMediaPlayer.reset();
        }
        mMediaPlayer.start();

        break;
    }
}

I don't know where I'm wrong. Can anyone help me with this?

Lucifer
  • 29,392
  • 25
  • 90
  • 143
Somasundaram NP
  • 1,018
  • 1
  • 12
  • 36
  • Please, provide proper piece of code. Currently it's completely not clear and difficult to understand (e.g. what is first function, what is 'np')? Have You tried http://stackoverflow.com/questions/3289038/play-audio-file-from-the-assets-directory or http://stackoverflow.com/questions/8106694/play-media-files-located-in-assets-folder ? – sandrstar Mar 03 '14 at 05:47

1 Answers1

0

You haven't handed your switch a variable to check against,

     notificationfunction(View np){
     switch(np.getId()){
        //cases
        }
     }

if you aren't going to hand in the view of the checked radiobutton, you should use if and else if conditions on the status of the radiobuttons instead of a switch on the view ids:

    if(RadioButton1.ischecked()){
        //do something
    }else if (RadioButton2.isChecked(){
        //do something else
    }//etc.
me_
  • 681
  • 1
  • 8
  • 18