1

ここに画像の説明を入力

ファイルから取得したバイト配列を使用して録音したサウンドのグラフを描画し、それをシーク バーの背景として設定しようとしています。上記の金額まで抽選に成功しましたが、正確ではありません。正確なグラフを取得するには、ピクセルをミリ秒に変換する必要があります。実際には、シークバーで行われる最大値と進行状況の更新はミリ秒単位です.しかし、ループ内の表示幅のピクセルを使用してグラフを描画しています.したがって、ピクセルをミリ秒に変換してグラフを描画できればと思います。ミリ秒単位で正確な進行状況バーグラフを作成できます (そう願っています)。

それで、ピクセルをミリ秒に変換するのを手伝ってくれる人はいますか?電話の表示幅が 480 の場合、480 をミリ秒に変換する必要があります。

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
        }
4

1 に答える 1

1

これを試して :

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

次に、ドローをresultperごとに移動しますmilliseconds

編集

私の提案は次のとおりです。

1- SeekBar の最大値を 100 に設定します。そして最小= 0;

2- 次のメソッドを使用して、メディアの長さをパーセントに変換します。

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();
    }

次に、このパーセンテージを SeekBar のように使用しますsetProgress(getProgressPercentage(long currentDuration, long totalDuration));

3- パラメータを実装OnSeekBarChangeListenerして使用しprogress、グラフを描画します。

@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) {}

これがお役に立てば幸いです。

于 2013-03-18T11:55:14.170 に答える