Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/203.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 单击按钮时发出嘟嘟声_Android - Fatal编程技术网

Android 单击按钮时发出嘟嘟声

Android 单击按钮时发出嘟嘟声,android,Android,我想在启动游戏时发出声音,我在oncreate中执行了以下代码: SoundPool sp = new SoundPool(5, AudioManager.STREAM_MUSIC, 0); int iTmp = sp.load(getBaseContext(), R.raw.windows_8_notify, 1); // in 2nd param u have to pass your desire ringtone sp.play(iTmp, 1, 1, 0, 0, 1

我想在启动游戏时发出声音,我在oncreate中执行了以下代码:

SoundPool sp = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);

    int iTmp = sp.load(getBaseContext(), R.raw.windows_8_notify, 1); // in 2nd param u have to pass your desire ringtone

    sp.play(iTmp, 1, 1, 0, 0, 1);

    MediaPlayer mPlayer = MediaPlayer.create(getBaseContext(), R.raw.windows_8_notify); // in 2nd param u have to pass your desire ringtone
    //mPlayer.prepare();
    mPlayer.start();
当我的声音结束时,我如何使它重新开始?我的意思是重放这首歌

Add mPlayer.setLooping(true);

查看

要重新开始音乐,请将loop设置为true:

SoundPool sp = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);

// in 2nd param u have to pass your desire ringtone
int iTmp = sp.load(getBaseContext(), R.raw.windows_8_notify, 1); 

sp.play(iTmp, 1, 1, 0, 0, 1);

// in 2nd param u have to pass your desire ringtone
MediaPlayer mPlayer = MediaPlayer.create(getBaseContext(), R.raw.windows_8_notify); 

// Here set loop to true

mPlayer.setLooping(true);

mPlayer.start();
问候
PS

谢谢你的帮助!你知道我在哪里可以找到我的应用程序的音乐吗?我不想放一首真正的歌曲,我想放一首背景音乐,比如在“请勿轻触白色瓷砖”或其他一些游戏中。不同的问题应该放在不同的帖子中。谢谢,这很有效:)你知道我在哪里可以找到我的应用程序的音乐吗?我不想放一首真正的歌,我想放一首背景音乐,比如在《不要轻触白色瓷砖》或其他一些游戏中。。