所以我有8个图像,每个图像开始8个不同的声音循环。 我在每张图像下都有一个搜索栏来控制该声音的音量。
搜索栏在声音第一次开始时正常工作,但当停止并再次开始时,搜索栏不再控制音量。 我究竟做错了什么? `noiseVolumeControl.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener(){
@Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { double noiseVol = (double) progress / (double) maxVolume; Log.i("Noise Volume", String.valueOf(progress) + " " + String.valueOf((float) noiseVol)); mySound.setVolume(whiteNoiseId, (float) noiseVol, (float) noiseVol); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } });public void whiteNoiseTapped(View view){
Log.i("White Noise", "button tapped"); if (whiteNoisePlaying) { Log.i("White Noise", "already playing"); mySound.stop(noiseStreaming); whiteNoisePlaying = false; ((ImageView) view).setImageResource(R.drawable.whitenoise); isPlaying--; } else if (isPlaying < 3) { Log.i("White Noise", "start playing"); noiseStreaming = mySound.play(whiteNoiseId, (float) noiseVol, (float) noiseVol, 1, -1, 1); whiteNoisePlaying = true; ((ImageView) view).setImageResource(R.drawable.whitenoisepressed); isPlaying++; } }`So I have 8 images, each starts a loop of 8 different sounds. I have a seekbar under each image to control the volume for that sound.
The seekbar works fine the first time the sounds starts, but when stopped and started again, the seekbar no longer controls the volume. What am I doing wrong? `noiseVolumeControl.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { double noiseVol = (double) progress / (double) maxVolume; Log.i("Noise Volume", String.valueOf(progress) + " " + String.valueOf((float) noiseVol)); mySound.setVolume(whiteNoiseId, (float) noiseVol, (float) noiseVol); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } });public void whiteNoiseTapped(View view) {
Log.i("White Noise", "button tapped"); if (whiteNoisePlaying) { Log.i("White Noise", "already playing"); mySound.stop(noiseStreaming); whiteNoisePlaying = false; ((ImageView) view).setImageResource(R.drawable.whitenoise); isPlaying--; } else if (isPlaying < 3) { Log.i("White Noise", "start playing"); noiseStreaming = mySound.play(whiteNoiseId, (float) noiseVol, (float) noiseVol, 1, -1, 1); whiteNoisePlaying = true; ((ImageView) view).setImageResource(R.drawable.whitenoisepressed); isPlaying++; } }`最满意答案
我想到了。 我需要一种方法来了解我是否已经在之前点击过按钮。 我将noiseStreaming设置为0,然后在按下按钮时检查它。 如果它是0,那么我将whiteNoiseId设置为noiseStreaming。 下一次它不会是0,会跳过那一点 -
public void whiteNoiseTapped(View view){
Log.i("White Noise", "button tapped"); if (whiteNoisePlaying) { Log.i("White Noise", "already playing"); mySound.pause(noiseStreaming); whiteNoisePlaying = false; ((ImageView) view).setImageResource(R.drawable.whitenoise); isPlaying--; } else if (isPlaying < 3) { Log.i("White Noise", "start playing"); if (noiseStreaming == 0) { noiseStreaming = mySound.play(whiteNoiseId, (float) noiseVol, (float) noiseVol, 1, -1, 1); } else { mySound.resume(noiseStreaming); } whiteNoisePlaying = true; ((ImageView) view).setImageResource(R.drawable.whitenoisepressed); isPlaying++; } }现在可以通过点击和关闭来控制音量。
I figured it out. I needed a way of knowing if I had already tapped the button before or not. I set noiseStreaming to 0 initially and then checked it when the button was pressed. If it was 0 then I set the whiteNoiseId into noiseStreaming. Next time it wouldn't be 0 and would skip that bit -
public void whiteNoiseTapped(View view) {
Log.i("White Noise", "button tapped"); if (whiteNoisePlaying) { Log.i("White Noise", "already playing"); mySound.pause(noiseStreaming); whiteNoisePlaying = false; ((ImageView) view).setImageResource(R.drawable.whitenoise); isPlaying--; } else if (isPlaying < 3) { Log.i("White Noise", "start playing"); if (noiseStreaming == 0) { noiseStreaming = mySound.play(whiteNoiseId, (float) noiseVol, (float) noiseVol, 1, -1, 1); } else { mySound.resume(noiseStreaming); } whiteNoisePlaying = true; ((ImageView) view).setImageResource(R.drawable.whitenoisepressed); isPlaying++; } }The volume can now be controlled through clicks on and off.
更多推荐
发布评论