使用android处理程序

时间:2015-03-30 19:01:02

标签: android

我正在尝试在服务中运行处理程序...

当我使用它时,一切都运行良好

Handler handler1 = new Handler();
    handler1.postDelayed(new Runnable() {
        @Override
        public void run() {

            if (player.isPlaying()){
                player.stop();
            }
            player = MediaPlayer.create(getApplicationContext(), R.raw.birds);
            player.setLooping(true);
            player.setVolume(100, 100);
            player.start();
        }
    }, *10000*);

    player = MediaPlayer.create(this, R.raw.ship);
    player.setLooping(true); // Set looping
    player.setVolume(100,100);
    player.start();

但是当我使用它时,代码运行没有10000毫秒的延迟

long timer2 = 10000;
Handler handler1 = new Handler();
    handler1.postDelayed(new Runnable() {
        @Override
        public void run() {

            if (player.isPlaying()){
                player.stop();
            }
            player = MediaPlayer.create(getApplicationContext(), R.raw.birds);
            player.setLooping(true);
            player.setVolume(100, 100);
            player.start();
        }
    }, *timer2*);

    player = MediaPlayer.create(this, R.raw.ship);
    player.setLooping(true); // Set looping
    player.setVolume(100,100);
    player.start();
  

上面我使用了长号" 10000"下面我用变量......

知道为什么会这样吗?

0 个答案:

没有答案