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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:01:37+00:00 2026-06-04T07:01:37+00:00

im trying to make it so when the user opens the app it sets

  • 0

im trying to make it so when the user opens the app it sets the volume of the music to whatever they have their phones ringer volume at. This is my code so far but im not exactly sure what the paramters on setVolume(float, float) are. The android documentation doesn’t explain it well. What is my code doing wrong here?

  AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
  int currentVolume = audio.getStreamVolume(AudioManager.STREAM_RING);

   mPlayer = MediaPlayer.create(this, R.raw.song);
   mPlayer.setOnErrorListener(this);

   if(mPlayer!= null)
    {         
    mPlayer.setLooping(true);
    mPlayer.setVolume(currentVolume,1);
}
  • 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-06-04T07:01:38+00:00Added an answer on June 4, 2026 at 7:01 am

    Looks like audio.setStreamVolume is what you want, but pass in STREAM_MUSIC instead of STREAM_RING.

    Note: the music volume and ringer volume are likely to have different maximum values, so you will need to normalize them. Use getStreamMaxVolume for that.

    I have not done this before, and I haven’t compiled this, but the code should look something like this

    AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    
    // Get the current ringer volume as a percentage of the max ringer volume.
    int currentVolume = audio.getStreamVolume(AudioManager.STREAM_RING);
    int maxRingerVolume = audio.getStreamMaxVolume(AudioManager.STREAM_RING);
    double proportion = currentVolume/(double)maxRingerVolume;
    
    // Calculate a desired music volume as that same percentage of the max music volume.
    int maxMusicVolume = audio.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    int desiredMusicVolume = (int)(proportion * maxMusicVolume);
    
    // Set the music stream volume.
    audio.setStreamVolume(AudioManager.STREAM_MUSIC, desiredMusicVolume, 0 /*flags*/);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make my own user control and have almost finished it,
I am trying to make an app that opens android market page of selected
I am trying to make a Facebook app and need user id from Facebook
Here is jsfiddle ! I am trying to make user page where he can
I am trying to make the same user interface to preview image like on
So I'm trying to make a custom user control for a Windows Phone 7
I'm trying to make it possible for the user to download an Excel spreadsheet
I am trying to make a map where a user can outline any shape
I am trying to make it so that a user can ctrl-click outside of
I'm trying to make a field where user will enter amount of time per

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.