我在这里上了这门课:
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 社区是最好的!