作者ciafbi007 ( 我有恐女症YA )
看板MacDev
标题[问题] 关於AVAudioPlayer停止播放
时间Fri Nov 21 17:13:30 2014
各位板友好,在下开始接触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://webptt.com/cn.aspx?n=bbs/MacDev/M.1416561214.A.F78.html
1F:→ darktt: 你看一下第二次的 [playsound stop]; playsound是不是nil 11/21 17:54
2F:→ darktt: 在arc的状态下这个是会发生的 11/21 17:54
3F:→ ciafbi007: 果然显示nill (囧) 有没有改善方法? 11/21 18:24
4F:→ ciafbi007: 把[playsound stop]改成[playsound pause]好像就可以 11/21 21:33
5F:→ ciafbi007: 抱歉 问题没解决 有时候音效会重复到 就没用了orz 11/21 21:49
6F:→ ciafbi007: 除了AVFoundation我另外调了AudioToolbox来处理另一个 11/21 23:21
7F:→ ciafbi007: 音效档 写法满奇怪就是 暂时解决了问题... 11/21 23:22