Handler と Runnable を使用して曲の 1 つのセグメントを繰り返していますが、ミリ秒ごとにチェックしているため、電話のバッテリーを消耗しているようです。これが私のコードです:
ユーザーがループを開始するたびに、次のことを行います。
anotherHandler.post(mPlayLoopTask);
anotherHandler は先頭で宣言されたグローバル変数です」
private Handler anotherHandler = new Handler();
これが私のランナブルです:
private Runnable mPlayLoopTask = new Runnable() {
public void run()
{
if( mp != null)
{
if( isLoopOn && start_position != -1 && end_position != -1 )
{
long currentPosition = mp.getCurrentPosition();
if( currentPosition >=end_position )
{
mp.seekTo(start_position);
}
}
anotherHandler.post(this);
}
}
};
パフォーマンスを向上させる方法はありますか?