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

  • Home
  • SEARCH
  • 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 7049303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:59:49+00:00 2026-05-28T02:59:49+00:00

My application makes a short announcement once in a while, either via TextToSpeech or

  • 0

My application makes a short announcement once in a while, either via TextToSpeech or using the MediaPlayer. If there is some other music running in the background probably by some application using the MediaPlayer, I would like to interrupt this music for a moment and after my announcement resume playing the “background music”.

Is there a way to do it?

  • 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-28T02:59:50+00:00Added an answer on May 28, 2026 at 2:59 am

    If you can target API level 8 and above (Android 2.2), then have a look into the AudioManager, specifically requestAudioFocus() with AUDIOFOCUS_GAIN_TRANSIENT and AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK, and abandonAudioFocus().

    These give hints to the currently-playing music stream that your app would like to play a brief sound. If you use AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK with requestAudioFocus() you can get a nice effect where the already-playing music pauses, your sound plays, and then the playing music fades back in again when you call abandonAudioFocus().

    This works nicely with the built-in media players on the 2.2 devices I’ve tried it with (Samsung Galaxy S Wi-Fi and HTC Wildfire.) I’ve not tried it extensively with other music-playing apps, but it definitely works with Spotify, at least, and is the official way of doing exactly what you want to do.

    Note that you’ll need to work out for yourself when to call abandonAudioFocus() as most sounds are played asynchronously. Luckily, both MediaPlayer and TextToSpeech provide callback mechanisms so they can give you a prod when they’ve finished playing your sound (this isn’t true of SoundPool, so that’s more annoying to use audio focus with.)

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

Sidebar

Related Questions

My Android application contains an EditText view where you can type some short messages
I'm developing an ASP.Net web application which makes use of MySQL via the MySQL-Provided
My application makes use of a SQLite database to store the user's inputs. The
My application makes several calls to an Action method (ASP .NET MVC) which returns
When a PHP application makes a database connection it of course generally needs to
My Rails application makes use of Time.zone so that each user can set their
I've a database consisting of about 1 million records. My application makes frequent incremental
I have application that makes different queries with different results so the caching in
I have a web application that makes heavy use of the Session state to
We have a Linux application that makes use of OpenSSL's Python bindings and I

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.