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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:46:25+00:00 2026-06-09T07:46:25+00:00

I want to create the wave forms of audio file in android. Can anyone

  • 0

I want to create the wave forms of audio file in android. Can anyone provide me an example source code?

  • 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-09T07:46:27+00:00Added an answer on June 9, 2026 at 7:46 am

    Create class and extend View. Then create Listener interface for your class.

    public class WaveformCls extends View {
        public interface WaveformListener {
            public void waveformTouchStart(float x);
            public void waveformTouchMove(float x);
            public void waveformTouchEnd();
            public void waveformFling(float x);
            public void waveformDraw();
        };  
    

    Create Paint object as per your requirement.
    Create one method which is initialized all Paint object.

    public WaveformView(Context context, AttributeSet attrs) {
            super(context, attrs);
    
            // We don't want keys, the markers get these
            setFocusable(false);
    
            mGridPaint = new Paint();
            mGridPaint.setAntiAlias(false);
            mGridPaint.setColor(
                getResources().getColor(R.drawable.grid_line));
            mSelectedLinePaint = new Paint();
            mSelectedLinePaint.setAntiAlias(false);
            mSelectedLinePaint.setColor(
                getResources().getColor(R.drawable.waveform_selected));
            mUnselectedLinePaint = new Paint();
            mUnselectedLinePaint.setAntiAlias(false);
            mUnselectedLinePaint.setColor(
                getResources().getColor(R.drawable.waveform_unselected));
            mUnselectedBkgndLinePaint = new Paint();
            mUnselectedBkgndLinePaint.setAntiAlias(false);
            mUnselectedBkgndLinePaint.setColor(
                getResources().getColor(
                    R.drawable.waveform_unselected_bkgnd_overlay));
            mBorderLinePaint = new Paint();
            mBorderLinePaint.setAntiAlias(true);
            mBorderLinePaint.setStrokeWidth(1.5f);
            mBorderLinePaint.setPathEffect(
                new DashPathEffect(new float[] { 3.0f, 2.0f }, 0.0f));
            mBorderLinePaint.setColor(
                getResources().getColor(R.drawable.selection_border));
            mPlaybackLinePaint = new Paint();
            mPlaybackLinePaint.setAntiAlias(false);
            mPlaybackLinePaint.setColor(
                getResources().getColor(R.drawable.playback_indicator));
            mTimecodePaint = new Paint();
            mTimecodePaint.setTextSize(12);
            mTimecodePaint.setAntiAlias(true);
            mTimecodePaint.setColor(
                getResources().getColor(R.drawable.timecode));
            mTimecodePaint.setShadowLayer(
                2, 1, 1,
                getResources().getColor(R.drawable.timecode_shadow));
    
        mGestureDetector = new GestureDetector(
                context,
            new GestureDetector.SimpleOnGestureListener() {
                public boolean onFling(
                        MotionEvent e1, MotionEvent e2, float vx, float vy) {
                mListener.waveformFling(vx);
                return true;
                }
            });
    
            mSoundFile = null;
            mLenByZoomLevel = null;
            mValuesByZoomLevel = null;
            mHeightsAtThisZoomLevel = null;
            mOffset = 0;
            mPlaybackPos = -1;
            mSelectionStart = 0;
            mSelectionEnd = 0;
            mDensity = 1.0f;
            mInitialized = false;
        }
    

    You need to override onTouchEvent

    @Override
        public boolean onTouchEvent(MotionEvent event) {
        if (mGestureDetector.onTouchEvent(event)) {
            return true;
        }
    
            switch(event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                mListener.waveformTouchStart(event.getX());
                break;
            case MotionEvent.ACTION_MOVE:
                mListener.waveformTouchMove(event.getX());
                break;
            case MotionEvent.ACTION_UP:
                mListener.waveformTouchEnd();
                break;
            }
            return true;
        }
    
    public void setSoundFile(CheapSoundFile soundFile) {
        mSoundFile = soundFile;
        mSampleRate = mSoundFile.getSampleRate();
        mSamplesPerFrame = mSoundFile.getSamplesPerFrame();
        computeDoublesForAllZoomLevels();
        mHeightsAtThisZoomLevel = null;
    }
    

    override the draw method which draw wave on your screen.

    @Override
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            if (mSoundFile == null)
                return;
    
            if (mHeightsAtThisZoomLevel == null)
                computeIntsForThisZoomLevel();
    
            // Draw waveform
            int measuredWidth = getMeasuredWidth();
            int measuredHeight = getMeasuredHeight();
            int start = mOffset;
            int width = mHeightsAtThisZoomLevel.length - start;
            int ctr = measuredHeight / 2;
    
            if (width > measuredWidth)
                width = measuredWidth;
    
            // Draw grid
            double onePixelInSecs = pixelsToSeconds(1);
            boolean onlyEveryFiveSecs = (onePixelInSecs > 1.0 / 50.0);
            double fractionalSecs = mOffset * onePixelInSecs;
            int integerSecs = (int) fractionalSecs;
            int i = 0;
            while (i < width) {
                i++;
                fractionalSecs += onePixelInSecs;
                int integerSecsNew = (int) fractionalSecs;
                if (integerSecsNew != integerSecs) {
                    integerSecs = integerSecsNew;
                    if (!onlyEveryFiveSecs || 0 == (integerSecs % 5)) {
                        canvas.drawLine(i, 0, i, measuredHeight, mGridPaint);
                    }
                }
            }
    
            // Draw waveform
            for (i = 0; i < width; i++) {
                Paint paint;
                if (i + start >= mSelectionStart &&
                    i + start < mSelectionEnd) {
                    paint = mSelectedLinePaint;
                } else {
                    drawWaveformLine(canvas, i, 0, measuredHeight,
                                     mUnselectedBkgndLinePaint);
                    paint = mUnselectedLinePaint;
                }
                drawWaveformLine(
                    canvas, i,
                    ctr - mHeightsAtThisZoomLevel[start + i],
                    ctr + 1 + mHeightsAtThisZoomLevel[start + i],
                    paint);
    
                if (i + start == mPlaybackPos) {
                    canvas.drawLine(i, 0, i, measuredHeight, mPlaybackLinePaint);
                }
            }
    
            // If we can see the right edge of the waveform, draw the
            // non-waveform area to the right as unselected
            for (i = width; i < measuredWidth; i++) {
                drawWaveformLine(canvas, i, 0, measuredHeight,
                                 mUnselectedBkgndLinePaint);            
            }
    
            // Draw borders
            canvas.drawLine(
                mSelectionStart - mOffset + 0.5f, 30,
                mSelectionStart - mOffset + 0.5f, measuredHeight,
                mBorderLinePaint);
            canvas.drawLine(
                mSelectionEnd - mOffset + 0.5f, 0,
                mSelectionEnd - mOffset + 0.5f, measuredHeight - 30,
                mBorderLinePaint);
    
            // Draw timecode
            double timecodeIntervalSecs = 1.0;
            if (timecodeIntervalSecs / onePixelInSecs < 50) {
                timecodeIntervalSecs = 5.0;
            }
            if (timecodeIntervalSecs / onePixelInSecs < 50) {
                timecodeIntervalSecs = 15.0;
            }
    
            // Draw grid
            fractionalSecs = mOffset * onePixelInSecs;
            int integerTimecode = (int) (fractionalSecs / timecodeIntervalSecs);
            i = 0;
            while (i < width) {
                i++;
                fractionalSecs += onePixelInSecs;
                integerSecs = (int) fractionalSecs;
                int integerTimecodeNew = (int) (fractionalSecs /
                                                timecodeIntervalSecs);
                if (integerTimecodeNew != integerTimecode) {
                    integerTimecode = integerTimecodeNew;
    
                    // Turn, e.g. 67 seconds into "1:07"
                    String timecodeMinutes = "" + (integerSecs / 60);
                    String timecodeSeconds = "" + (integerSecs % 60);
                    if ((integerSecs % 60) < 10) {
                        timecodeSeconds = "0" + timecodeSeconds;
                    }
                    String timecodeStr = timecodeMinutes + ":" + timecodeSeconds;
                    float offset = (float) (
                        0.5 * mTimecodePaint.measureText(timecodeStr));
                    canvas.drawText(timecodeStr,
                                    i - offset,
                                    (int)(12 * mDensity),
                                    mTimecodePaint);
                }
            }
    
            if (mListener != null) {
                mListener.waveformDraw();
            }
        }  
    

    Here is complete source code of Rindroid which is useful for you
    Source code for waveform

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

Sidebar

Related Questions

i want create XML file here is my following code String fileName = jasstech.xml;
I want to create a sine wave file and apply some modifications like change
I want create an application with animate button? how can i do? after click
i want create Dynamic Slideshow in Jquery i'm Write this code var ctx =
I want create something that looks like the MSN Messenger chat forms. I am
I want to read bytes from a wave file into an array. Since the
I want create a ruby script that I can run on the command line
I want create a site by command line using appcmd. How can I associate
I want create a command that has the following structure command path/to/some/file How do
I want create a Circular Text with JQuery or CSS how can i do

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.