[問題] 關於AVAudioPlayer停止播放
各位板友好,在下開始接觸objective-c沒多久,請多指教。
在下想要用晃動改變聲音,但發覺上一個聲音在晃動後關不掉,
if ( [accelerometer[0]floatValue]<-1.0
&& [accelerometer[1]floatValue]<1.0)
{NSURL *fileURL=[[NSBundle mainBundle]
URLForResource:@"showregun.wav" withExtension:nil];
playsound=[[AVAudioPlayer alloc]
initWithContentsOfURL:fileURL error:nil];
playsound.numberOfLoops=-1;
[playsound play];
}else if([accelerometer[0]floatValue]>2.0
&& [accelerometer[1]floatValue]>1.0)
{[playsound stop];
NSURL *fileURL=[[NSBundle mainBundle]
URLForResource:@"GUNSHOW.wav" withExtension:nil];
playsound=[[AVAudioPlayer alloc]
initWithContentsOfURL:fileURL error:nil];
playsound.numberOfLoops=0;
[playsound play];
}
第一個聲音為循環播放,希望晃動後播第二個聲音時能關掉第一個聲音,
懇請板友指教,謝謝。
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 39.8.157.115
※ 文章網址: http://www.ptt.cc/bbs/MacDev/M.1416561214.A.F78.html
→
11/21 17:54, , 1F
11/21 17:54, 1F
→
11/21 17:54, , 2F
11/21 17:54, 2F
→
11/21 18:24, , 3F
11/21 18:24, 3F
→
11/21 21:33, , 4F
11/21 21:33, 4F
→
11/21 21:49, , 5F
11/21 21:49, 5F
→
11/21 23:21, , 6F
11/21 23:21, 6F
→
11/21 23:22, , 7F
11/21 23:22, 7F
MacDev 近期熱門文章
PTT數位生活區 即時熱門文章