Solution
You have defined and initialized the AVAudioPalyer method inside viewDidLoad. Therefore, the life of an audioPlayer is limited by the viewDidLoad method. The object dies at the end of the method, and because of this, the sound will not play. You must save the object until it finishes playing the audio.
Define avPlayer globally,
@property(nonatomic, strong) AVAudioPlayer *theAudio;
in viewDidLoad,
- (void)viewDidLoad { [super viewDidLoad]; [UIView animateWithDuration:1.5 animations:^{[self.view setBackgroundColor:[UIColor redColor]];}]; [UIView animateWithDuration:0.2 animations:^{title.alpha = 0.45;}];
source share