0

私はここでこのクラスを取得しました:

public class ViewBeat1 extends MasterView {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        try {
            stream = getAssets().open("some_gif.gif");
        } catch (IOException e) {
            e.printStackTrace();
        }
        GifMovieView view = new GifMovieView(this, stream);

        setContentView(view);
        run();
    }

    public void run() {

        // Get the ringtone

        int milliseconds = 0;
        final SoundPool sp = new SoundPool(2, AudioManager.STREAM_MUSIC, 0);
        final int loaded = sp.load(this, R.raw.beat, 1);

        boolean played = false;


        while (milliseconds < 300000) {
            if (milliseconds >= 20000 && !played) {
                sp.stop(loaded);
                sp.release();
                played = true;
                playSong(this.getClass().getSimpleName().toLowerCase(),
                        View6.class.getName(), 4000);
                finish();
            } else if (milliseconds <= 20000) {
                try {
                    sp.play(loaded, 1, 1, 1, 0, 1);
                    Thread.sleep(500);
                    milliseconds += 500;


                } catch (Exception e) {
                    Log.v("out of the thread", e.getMessage().toString());
                }
            }
        }
    }
}

MasterView は Activity から拡張され、おそらくここでは不要な処理を実行します。GifMovieView は gif アニメーションを設定し、それを Contentview に入れます。

ここで、この 500 ミリ秒の長さのウェーブ ファイルを 500 ミリ秒ごとに再生したいと思います。これは、速いハートビート (120 bpm) のようなものです。どういうわけか、このようにすると、正しく機能せず、アプリが応答しなくなります。これを達成するためのより良い解決策はありますか?

すでにあなたの助けに乾杯 - StackOverflow コミュニティは最高です!

4

2 に答える 2