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 6924723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:41:55+00:00 2026-05-27T10:41:55+00:00

I am doing an audio online streaming the audio is playing fine both in

  • 0

I am doing an audio online streaming the audio is playing fine both in emulator and device. But the issue is when i make a call to my device simultaneously the streaming also playing. I need to pause and play the audio back while the call is coiming. Can u help how to handle that broadcasting.

    public class BhajanStream extends Activity {
protected static final String TAG = null;
/** Called when the activity is first created. */

final String rs_bhajan_uri = "Media URL";
MediaPlayer mediaPlayer;
AudioManager audioManager;
Button bhajan_play;
Button bhajan_stop;
ImageView loadanim, effectbhajan;
AnimationDrawable loadanimation, effectanimation;
ProgressDialog dialog;
MusicServicePhoneStateListener mPhoneListener;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.bhajan);
    bhajan_play = (Button) findViewById(R.id.btn_play);
    bhajan_stop = (Button) findViewById(R.id.btn_stop);
    bhajan_stop.setVisibility(View.GONE);

    loadanim = (ImageView) findViewById(R.id.loadeffectview);
    effectbhajan = (ImageView) findViewById(R.id.bhajan_effect);

    /*if (mediaPlayer != null) {
           mediaPlayer.stop();
           mediaPlayer= null;    
          }*/


    mediaPlayer = new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    // mediaPlayer.reset();

    bhajan_play.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ConnectivityManager conMan = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo Info = conMan.getActiveNetworkInfo();
            if (Info == null) {
                Toast.makeText(BhajanStream.this, "POOR SIGNALS ",
                        Toast.LENGTH_LONG).show();
                // startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
            }



                loadanim.setBackgroundResource(R.drawable.loader_1);
                loadanim.setBackgroundResource(R.anim.loadanim);
                loadanimation = (AnimationDrawable) loadanim
                        .getBackground();
                loadanimation.isVisible();
                effectbhajan.setBackgroundResource(R.drawable.effect_bhajan1);
                effectbhajan.setBackgroundResource(R.anim.bhajaneffect);
                effectanimation = (AnimationDrawable) effectbhajan
                        .getBackground();

                     bhajan_play.setBackgroundResource(R.drawable.bhajan_start);
                bhajan_play.setVisibility(View.GONE);
                bhajan_stop.setVisibility(View.VISIBLE);
                loadanim.setVisibility(View.VISIBLE);
                effectbhajan.setVisibility(View.VISIBLE);


            try {
                mediaPlayer.reset();
                mediaPlayer.setDataSource(rs_bhajan_uri);

            } catch (IllegalArgumentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            try {
                 mediaPlayer.prepareAsync();

            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            mediaPlayer.setOnPreparedListener(new OnPreparedListener() {
                @Override
                public void onPrepared(MediaPlayer mp) {
                    mediaPlayer.start();

                }
            });
        }

    });

    bhajan_stop.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (mediaPlayer.isPlaying()) {
                if (mediaPlayer != null) {
            bhajan_stop.setVisibility(View.GONE);
            bhajan_play.setVisibility(View.VISIBLE);

            mediaPlayer.stop();
            loadanimation.stop();
            effectanimation.stop();
            loadanim.setVisibility(View.GONE);
            effectbhajan.setVisibility(View.GONE);
                }}

        }
    });

}

protected void onPreExecute() {
    // UI work allowed here

    loadanimation.start();


}

@Override
public void onBackPressed() {
    // do something
    if (mediaPlayer.isPlaying()) {
        if (mediaPlayer != null) {

            mediaPlayer.stop();
            loadanimation.stop();
            effectanimation.stop();
            bhajan_stop.setVisibility(View.GONE);
            bhajan_play.setVisibility(View.VISIBLE);
            loadanim.setVisibility(View.GONE);
            effectbhajan.setVisibility(View.GONE);
        }
    } else{
        startActivity(new Intent(BhajanStream.this, SaiStreams.class));
        finish();
    }
    }

private class MusicServicePhoneStateListener extends PhoneStateListener {
    private boolean mResumeAfterCall = false;

    @Override
    public void onCallStateChanged(int state, String incoming_number) {
        switch (state) {
        case TelephonyManager.CALL_STATE_OFFHOOK:
        case TelephonyManager.CALL_STATE_RINGING:
            Log.i(TAG, "phone active, suspending music service");
            mResumeAfterCall = mediaPlayer.isPlaying();
            mediaPlayer.pause();
            break;
        case TelephonyManager.CALL_STATE_IDLE:
            Log.i(TAG, "phone inactive, resuming music service");
            if (mResumeAfterCall) {
               mediaPlayer.start();
            }
            break;
        default:
            break;
        }
    }
}
public void onCreate(){
    mPhoneListener = new MusicServicePhoneStateListener();
    ((TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE)).listen(mPhoneListener, PhoneStateListener.LISTEN_CALL_STATE);
}
public void onDestroy(){
    mPhoneListener = new MusicServicePhoneStateListener();
    ((TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE)).listen(mPhoneListener, 0);
}

}

  • 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-27T10:41:56+00:00Added an answer on May 27, 2026 at 10:41 am

    In your activity,you can register a phone state listener by calling public void listen (PhoneStateListener listener, int events) in the TelephonyManager class. See here. Also,You can call Context.getSystemService(Context.TELEPHONY_SERVICE) to get an instance of the TelephonyManager object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing audio recording using MediaRecorder, but unfortunately when I playback the recorded
I'm streaming the mic audio between two devices, everything is working but i have
HI, I am doing an iphone application that works with audio files. Application also
I am reading a raw audio file (CD track rip) in, doing byte swapping,
I was wondering, what was a good cross-platform utility for doing audio recording/ playback/
I am trying to access the audio file from the jar,for doing that i
I've been making some progress with audio programming for iPhone. Now I'm doing some
Working with the <audio> tag in some web development I've been doing lately, and
I was doing some basic audio programming in C# using the NAudio package and
After doing some processing on an audio or image array, it needs to be

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.