[英]Oscillating AVAudioPlayer Volume in Xcode
我正在嘗試使AVAudioPlayer
的音量隨着時間的推移而振盪。
例如:每10秒鍾,將音量調整為0.5,然后調整為1.0,依此類推。
我試過使用NSTimer
但它只能在第一次使用並且不會循環。
oscillateTimer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(oscillateRun) userInfo:nil repeats:YES];
oscillateRun function
- (void)oscillateRun {
BOOL oscillation;
oscillation = NO;
if(oscillation = YES) {
oscillation = NO;
audioPlayer.volume = 0.50;
}
else {
oscillation = YES;
audioPlayer.volume = 1;
}
}
不確定該怎么辦,在此先感謝!
這里的problem
是,每次創建新的bool變量時,每次都需要NO,這就是為什么值不改變AVPlayer
音量的原因。
全局創建振盪對象,
BOOL oscillation;
像這樣稱呼這個方法
[self oscillateRun];
- (void)oscillateRun {
if(oscillation == YES) {
oscillation = NO;
[audioPlayer setVolume : 0.50];
}
else {
oscillation = YES;
[audioPlayer setVolume : 1.0];
}
[NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(oscillateRun) userInfo:nil repeats:YES];
}
編輯:-
for camparing the two variables use '==' change this one in if condition then it'l works fine.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.