Question

enter image description here

I am trying to draw a graph for a recorded sound using the byte array fetched from the file and trying to set it as a background for a seek bar. I had succeeded to draw till the amount shown above, but its not accurate. For getting an accurate graph I need to convert the pixels to milliseconds. Actually the max and progress updates done in the seek bar are in milliseconds.But I am drawing the graph using the pixels of the Display width inside a loop.So I think if I can convert the pixels to milliseconds and draw the graph loping it inside milliseconds could make out an accurate progreesbargraph (Hope so).

So can any one help me to convert the pixels to milliseconds???If the Display width of the phone is 480, I need to convert 480 to milliseconds, Any way??Help me out!!!

width=number of pixels of display width
for (int iPixel = 0; iPixel < width; iPixel++)
            { 
                   {
            int start = (int) ((float) iPixel * ((float) width));
            int end = (int) ((float) (iPixel + 1) * ((float) width));

            for (int i = start; i < end; i++) {
            //code to find the pixel to draw
            }

   //code to draw in canvas
        }
Was it helpful?

Solution

Try this :

total width(unit) / total file length(milliseconds) = result(unit/milliseconds)

then move your draw by result per milliseconds

Edit:

My suggestion is:

1- Set SeekBar max=100; and min=0;

2- Convert media lenght to percent by use this method:

public int getProgressPercentage(long currentDuration, long totalDuration){
        Double percentage = (double) 0;

        long currentSeconds = (int) (currentDuration);
        long totalSeconds = (int) (totalDuration);

        // calculating percentage
        percentage =(((double)currentSeconds)/totalSeconds)*100;

        // return percentage
        return percentage.intValue();
    }

then use this persent in SeekBar like setProgress(getProgressPercentage(long currentDuration, long totalDuration));

3- Implements OnSeekBarChangeListener and use its progress parameter to draw your graph:

@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) {
    // Here use int progress to draw graph. It is percent
    // Current width = 400*percent/100 = result;
    // draw until result value;
}

/**
 * When user starts moving the progress handler
 * */
@Override
public void onStartTrackingTouch(SeekBar seekBar) {}

/**
 * When user stops moving the progress hanlder
 * */
@Override
public void onStopTrackingTouch(SeekBar seekBar) {}

Hope this helped you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top