Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to disable all the sounds in the application
    primarykey
    data
    text
    <p>i am developing a android app.In the app,i have a button in the activity1. on clicking that button it jumps to activity2 and then background music starts for activity2. </p> <p>i have used Media player for playing the music in activity2.</p> <p>Now i have placed a sound button in the activity1 and i want that when user clicks on it,the background music that is to be played in activity2 should be disabled and if user again clicks on the sound button ... the music in activity2 is enabled.</p> <p>how to achieve this task. i m a beginner i have no idea how to do this . can any1 help me with this prob????</p> <p>any help will be appreciable ....</p> <p>activity1 java code..</p> <pre><code>package com.example.quizproject; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.graphics.Color; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.os.Bundle; import android.view.KeyEvent; import android.view.View; import android.widget.Button; import android.widget.ImageButton; public class Menu extends Activity implements View.OnClickListener{ Button btn4,btn5,btn6,btn7,btn8; ImageButton imgbtn1,imgbtn2; MediaPlayer mp2; public void onCreate(Bundle icici) { super.onCreate(icici); setContentView(R.layout.menupg); mp2=MediaPlayer.create(this, R.drawable.buttonsound); btn4=(Button)findViewById(R.id.btn4); btn5=(Button)findViewById(R.id.btn5); btn6=(Button)findViewById(R.id.btn6); btn7=(Button)findViewById(R.id.btn7); btn8=(Button)findViewById(R.id.btn8); imgbtn1=(ImageButton)findViewById(R.id.imgbtn1); imgbtn2=(ImageButton)findViewById(R.id.imgbtn2); btn4.setOnClickListener(this); btn5.setOnClickListener(this); btn6.setOnClickListener(this); btn7.setOnClickListener(this); btn8.setOnClickListener(this); imgbtn1.setOnClickListener(this); imgbtn2.setOnClickListener(this); } public void onClick(View v) { mp2.start(); if((v.getId())==(R.id.btn5)) { startActivity(new Intent("com.example.quizproject.Highscore")); } if((v.getId())==(R.id.btn4)) { startActivity(new Intent("com.example.quizproject.Ques")); } if((v.getId())==(R.id.btn6)) { startActivity(new Intent("com.example.quizproject.About")); } if((v.getId())==(R.id.btn7)) { startActivity(new Intent("com.example.quizproject.Addques")); } if((v.getId())==(R.id.imgbtn2)) { } if((v.getId())==(R.id.btn8)) { Intent intent = new Intent(this, StartQuiz.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } } public boolean onKeyDown(int keycode, KeyEvent event) { if(keycode==(KeyEvent.KEYCODE_DPAD_CENTER)) { finish(); } return super.onKeyDown(keycode, event); } } </code></pre> <p>xml code for activity1....</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/dar" android:gravity="center" android:orientation="vertical" &gt; &lt;Button android:id="@+id/btn4" android:layout_width="250dp" android:layout_height="40dp" android:text="PLAY" android:layout_marginBottom="10dp" android:textStyle="bold" android:background="@drawable/quesbtn_shape"/&gt; &lt;Button android:id="@+id/btn5" android:layout_width="250dp" android:layout_height="40dp" android:text="HIGH SCORE" android:layout_marginTop="10dp" android:layout_marginBottom="10dp" android:textStyle="bold" android:background="@drawable/quesbtn_shape"/&gt; &lt;Button android:id="@+id/btn6" android:layout_width="250dp" android:layout_height="40dp" android:text="ABOUT QUIZ" android:layout_marginTop="10dp" android:layout_marginBottom="10dp" android:textStyle="bold" android:background="@drawable/quesbtn_shape"/&gt; &lt;Button android:id="@+id/btn7" android:layout_width="250dp" android:layout_height="40dp" android:text="ADD QUESTION" android:layout_marginTop="10dp" android:layout_marginBottom="10dp" android:textStyle="bold" android:background="@drawable/quesbtn_shape"/&gt; &lt;Button android:id="@+id/btn8" android:layout_width="250dp" android:layout_height="40dp" android:text="Exit" android:layout_marginTop="10dp" android:layout_marginBottom="10dp" android:textStyle="bold" android:background="@drawable/quesbtn_shape"/&gt; &lt;TableLayout android:layout_width="fill_parent" android:layout_height="wrap_content"&gt; &lt;TableRow &gt; &lt;ImageButton android:id="@+id/imgbtn1" android:layout_width="50dp" android:layout_height="50dp" android:src="@drawable/sound" android:layout_marginLeft="87dp" android:layout_marginTop="20dp" android:background="@drawable/quesbtn_shape"/&gt; &lt;ImageButton android:id="@+id/imgbtn2" android:layout_width="50dp" android:layout_height="50dp" android:src="@drawable/music" android:layout_marginLeft="40dp" android:layout_marginTop="20dp" android:background="@drawable/quesbtn_shape"/&gt; &lt;/TableRow&gt; &lt;/TableLayout&gt; &lt;/LinearLayout&gt; </code></pre> <p>activity2 java code..</p> <pre><code>package com.example.quizproject; import java.lang.reflect.Method; import java.security.PublicKey; import java.util.Random; import java.util.Set; import java.util.Timer; import java.util.concurrent.DelayQueue; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Intent; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.graphics.Color; import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.os.Bundle; import android.os.CountDownTimer; import android.os.Handler; import android.view.View; import android.widget.Button; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; public class Ques extends Activity implements View.OnClickListener{ TextView txt17,txt18,txt21,txt19,txt20; Button btn10,btn11,btn12; MediaPlayer mp1,mp5,mp; ImageView imgv; int score=0,ch=3,q=1; String ans; public void onCreate(Bundle icici) { super.onCreate(icici); setContentView(R.layout.activity_main); mp1=MediaPlayer.create(this, R.drawable.buzzer); mp5=MediaPlayer.create(this, R.drawable.belltone); mp=MediaPlayer.create(this, R.drawable.bgmusic); mp.setVolume(50,50); mp.start(); mp.setOnCompletionListener(new OnCompletionListener() { public void onCompletion(MediaPlayer mp) { mp.release(); // TODO Auto-generated method stub } }); txt17=(TextView)findViewById(R.id.txt17); txt21=(TextView)findViewById(R.id.txt21); txt19=(TextView)findViewById(R.id.txt19); txt20=(TextView)findViewById(R.id.txt20); txt18=(TextView)findViewById(R.id.txt18); btn10=(Button)findViewById(R.id.btn10); btn10.setOnClickListener(this); btn11=(Button)findViewById(R.id.btn11); btn11.setOnClickListener(this); btn12=(Button)findViewById(R.id.btn12); btn12.setOnClickListener(this); imgv=(ImageView)findViewById(R.id.imageButton1); } public void stopMusic() { mp.stop(); mp.release(); mp = null; } public void stopMusic1() { mp1.stop(); } public void stopMusic2() { mp5.stop(); } public void onClick(View v) { // TODO Auto-generated method stub stopMusic1(); stopMusic(); stopMusic2(); </code></pre> <p>}</p> <p>here are the codes there is no problem in actcivity2 ... the imagebutton with the id imgbtn2 in activity1 should disable the music of activity2.</p> <p>for instance, if user press the imagebutton then when it jumps to activity2 .the music should not be played and if the user press the image button again then when it jumps to activty2 the music should b played in the background.....</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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