Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6911321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:56:16+00:00 2026-05-27T08:56:16+00:00

This is my first self taught project .. in this project in webview i

  • 0

This is my first self taught project .. in this project in webview i am playing a flash video from my website…

I is working fine … i mean its palying music etc no problem on that side..

only trouble is when i someone ring media player does not mute and in conversation i still listening to music..

i would like to mute media volume while in call or in ringing mode..then resume back after call finishes…

here are the codes i m using ( only the main part)

public void onAudioFocusChange(int focus) {
    //focus = audio.getMode();
    switch(focus){
    case AudioManager.MODE_RINGTONE :
        Pause();
        Toast.makeText(this, "PAUSE... RINGTONE", 15000).show(); //just need to see if this function really been called...
        break;
    case AudioManager.MODE_IN_CALL :
        Pause();
        Toast.makeText(this, "PAUSE.. IN CALL", 15000).show(); //just need to see if this function really been called...
        break;
    case AudioManager.MODE_IN_COMMUNICATION :
        Pause();
        Toast.makeText(this, "PAUSE... IN COMMUNICATION", 15000).show(); //just need to see if this function really been called...
        break;
    case AudioManager.MODE_NORMAL :
        Resume();
        Toast.makeText(this, "RESUME... NORMAL MODE", 15000).show(); //just need to see if this function really been called...
        break;   
    }       
}    
public void  Pause(){
    audio.setStreamSolo(AudioManager.STREAM_VOICE_CALL, true);
    audio.setMode(AudioManager.MODE_IN_CALL);
    audio.setStreamMute(AudioManager.STREAM_MUSIC, true); 

}
public void  Resume(){
    audio.setStreamSolo(AudioManager.STREAM_VOICE_CALL, false);
    audio.setMode(AudioManager.MODE_NORMAL);
    audio.setStreamMute(AudioManager.STREAM_MUSIC, false);   
}

my activity class is like

public class MyActivity extends Activity implements OnAudioFocusChangeListener, OnSeekBarChangeListener {

private static final String MY_AD_UNIT_ID = "a14xxxxx";
private AdView adView;
private WebView myWebView;
private AudioManager audio;
private SeekBar sb;
private int result = AudioManager.MODE_NORMAL;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    audio =(AudioManager) MyActivity.this.getSystemService(Context.AUDIO_SERVICE);
    //result = AudioManager.MODE_NORMAL;
    result = audio.requestAudioFocus(this, AudioManager.STREAM_MUSIC,          AudioManager.AUDIOFOCUS_GAIN);
    while(audio.isMusicActive())
    {
       this.onAudioFocusChange(result);

    }           

    //control SeekBar
    int maxV = audio.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    int curV = audio.getStreamVolume(AudioManager.STREAM_MUSIC);
    sb = (SeekBar) findViewById(R.id.sb);
    sb.setMax(maxV);
    sb.setProgress(curV);
    sb.setOnSeekBarChangeListener(this);

    myWebView = (WebView) findViewById(R.id.webview);
    WebSettings webSettings = myWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setPluginsEnabled(true);
    myWebView.loadUrl("http://www.testpage.co.uk/live.html");        
    // Create the adView
    adView = new AdView(this, AdSize.BANNER, MY_AD_UNIT_ID);
    // Lookup your LinearLayout 
    LinearLayout myAdview = (LinearLayout) findViewById(R.id.adsDisplay);
    // Add the adView to it
    myAdview.addView(adView);        
    // Initiate a generic request to load it with an ad
    AdRequest request = new AdRequest();

    adView.loadAd(request);        
}   

Please advise/help…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:56:17+00:00Added an answer on May 27, 2026 at 8:56 am

    Audio focus is a different thing from what you are trying to do.

    You need a PhoneStateListener and monitor when a call comes and when it goes away. Something like this:

    PhoneStateListener mPhoneStateListener = new PhoneStateListener()
    {
        protected boolean mWasPlayingWhenCalled = false;
    
        @Override
        public void onCallStateChanged(int state, String incomingNumber)
        {
            if( state == TelephonyManager.CALL_STATE_RINGING )
            { // Incoming call: Pause music
                if( mPlaying )
                {
                    stop();
                    mWasPlayingWhenCalled = true;
                }
            }
            else if(state == TelephonyManager.CALL_STATE_IDLE )
            {  // Not in call: Play music
                if( mWasPlayingWhenCalled )
                {
                    start();
                    mWasPlayingWhenCalled = false;
                }
            }
            else if( state == TelephonyManager.CALL_STATE_OFFHOOK )
            { // A call is dialing, active or on hold
            }
    
            super.onCallStateChanged(state, incomingNumber);
        }
    };
    

    Then in your onCreate() or similar:

    TelephonyManager mgr = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
    mgr.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a humble website with my mediocre, self-taught PHP skills, and the
This is the first http programming i've done and I'm self-taught so this may
Code first: '''this is main structure of my program''' from twisted.web import http from
I'm a self-taught programmer who jumped into Python as my first language about 7-8
I'm new to C++, this is my first week since the upgrade from fortran.
This first bit works: $my_id = 617; $post_id_7 = get_post($my_id); $title = $post_id_7->post_excerpt; echo
Saw this piece of code in a Ruby on Rails book. This first one
problem euler #5 i found the solution but i don't know why this first
Using Dozer to map two objects, I have: /** /* This first class uses
#include <iostream> using namespace std; // This first class contains a vector and a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.