marvan021
چهارشنبه 28 مرداد 1394, 11:46 صبح
سلام دوستان ..من ی مشکلی دارم..دکمه رو ک لمس میکنم ی موزیک اجرا میشه و هرچند دفه ک بزنم پش سر هم یکی جدید اجرا میشه...حالا ی تایمر گذاشتن ک بعد 300 میلی ثانیه موقعی ک دسمو از رو دکمه ورداشتم استاپ شه.. ولی اگه این بار پش سر هم این دکمه پخشو لمس کنم موزیک دیگه ب طور کامل پخش قطع نمیشه...اون موزیک هم دو ثانیه بیشتر نیس مث پیانو میمونه ..اینم کدم::قلب::گریه::گریه:
public class MainActivity extends Activity{
public static int streamId[]={0};
public static int soundId[]={0};
private SoundPool soundPool;
final static int MAX_STREAMS = 5;
private boolean isLoaded = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn=(Button)findViewById(R.id.button1);
this.setVolumeControlStream(AudioManager.STREAM_MU SIC);
// Load the sound
soundPool = new SoundPool(MAX_STREAMS, AudioManager.STREAM_MUSIC,100);
soundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
@Override
public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
Log.d("TESTING", "sampleId :" + sampleId + " status :" + status);
isLoaded = true;
}
});
soundId[0] = soundPool.load(getBaseContext(), R.raw.b4, 1);
btn.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction()){
case MotionEvent.ACTION_DOWN : {
soundPool.pause(streamId[0]);
streamId[0]= streamId[0]=soundPool.play(soundId[0], 1, 1,10 , -1, 1f);
return true;
}
case MotionEvent.ACTION_UP : {
CountDownTimer countDownTimer = new CountDownTimer(300,1000) {
public void onTick(long millisUntilFinished) {
}
public void onFinish() {
//code fire after finish
soundPool.pause(streamId[0]);
}
};countDownTimer.start();
return true;
}
}
return false;
}
});
}
}
Plz KOOOmak
public class MainActivity extends Activity{
public static int streamId[]={0};
public static int soundId[]={0};
private SoundPool soundPool;
final static int MAX_STREAMS = 5;
private boolean isLoaded = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn=(Button)findViewById(R.id.button1);
this.setVolumeControlStream(AudioManager.STREAM_MU SIC);
// Load the sound
soundPool = new SoundPool(MAX_STREAMS, AudioManager.STREAM_MUSIC,100);
soundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
@Override
public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
Log.d("TESTING", "sampleId :" + sampleId + " status :" + status);
isLoaded = true;
}
});
soundId[0] = soundPool.load(getBaseContext(), R.raw.b4, 1);
btn.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction()){
case MotionEvent.ACTION_DOWN : {
soundPool.pause(streamId[0]);
streamId[0]= streamId[0]=soundPool.play(soundId[0], 1, 1,10 , -1, 1f);
return true;
}
case MotionEvent.ACTION_UP : {
CountDownTimer countDownTimer = new CountDownTimer(300,1000) {
public void onTick(long millisUntilFinished) {
}
public void onFinish() {
//code fire after finish
soundPool.pause(streamId[0]);
}
};countDownTimer.start();
return true;
}
}
return false;
}
});
}
}
Plz KOOOmak