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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:58:32+00:00 2026-06-03T09:58:32+00:00

In my android application(Audio Processing) i use a long type variable to calculate the

  • 0

In my android application(Audio Processing) i use a long type variable to calculate the position where it is being paused, but the application gave me strange results for large audio files. After putting some effort i found out that the position calculation is going out of limits in android. Though a long type in java has a minimum value of -9,223,372,036,854,775,808 and a maximum value of 9,223,372,036,854,775,807, i wondered why my calculation went out of limits.

After going through some posts i found that android support limited value ranges unlike java. But my question is how i can perform this calculation in android? Is there any other android specific data types?

This is the calculation i perform in my app:
position=((bufferSize*currentPosition)/duration);

  • 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-03T09:58:33+00:00Added an answer on June 3, 2026 at 9:58 am

    As noted in my comment, the post you’re taking your information from is simply incorrect. long is always 64 bits. There may be some limitations in NIO, but that’s a different matter.

    However, your problem can easily be explained without any trickery. Here’s your code again:

    position = (bufferSize * currentPosition) / duration;
    

    You haven’t said what the types of bufferSize and currentPosition are, but I’ll assume they’re long. If you’ve got a very large buffer and a “late” currentPosition value, it’s possible that the result of the multiplication will overflow into a negative number. When you divide that negative number by duration, you’ll still get a negative (but smaller in magnitude) number.

    If bufferSize and currentPosition are int variables instead of long, that overflow will occur much sooner. Indeed, if that’s the case then you may well just be able to fix your problem just by forcing the arithmetic to be done in 64 bits:

    position = ((long)bufferSize * currentPosition) / duration;
    

    You should work out what range of currentPosition this would work up to, based on your buffer size – I’d expect it to be fine for any sensibly-sized file length and buffer size combination, to be honest.

    If that doesn’t help, please post more information – including the variable types and what values you’re observing (for all variables, including the results).

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

Sidebar

Related Questions

I'm making an Android application where I need to slow down the audio being
I am currently trying to create an Android application that loops Audio from the
Our android application is getting fairly big and we would like to use functional
I created a sample audio player application in android. In my application I used
I have developed an Android application for changing ringtones. It works quite well, but
I work one application for android audio recording in which i used mediaRecorder class
I'm trying to develop an Audio Capture application using the AudioRecord class from android
I need to play long audio files using the Android SDK. I am aware
I need to develop application for Android which decrypts audio and video files saved
I'm developing an AIR for Android application, and am current sending audio to fms

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.