I am having trouble playing a local WAV file. My AVPlayerStatus
prints 0
, which I assume is not ready for playback. I cannot understand this, but having said that, I am trying for the first time to use something that is related to AVPlayer, so maybe something simple. I would appreciate any help. Here is the code:
I must add that my sounds do not play!
-(void) playWordSound:(UILabel *)label { NSString *path; switch (label.tag) { case 1: path = [[NSBundle mainBundle] pathForResource:@"humpty" ofType:@"wav"]; break; case 2: path = [[NSBundle mainBundle] pathForResource:@"dumpty" ofType:@"wav"]; break; case 3: path = [[NSBundle mainBundle] pathForResource:@"saty" ofType:@"wav"]; break; case 4: path = [[NSBundle mainBundle] pathForResource:@"on 2" ofType:@"wav"]; break; case 5: path = [[NSBundle mainBundle] pathForResource:@"a 3" ofType:@"wav"]; break; case 6: path = [[NSBundle mainBundle] pathForResource:@"wall" ofType:@"wav"]; break; } NSURL *url = [NSURL fileURLWithPath:path]; AVQueuePlayer *player; static const NSString *ItemStatusContext; AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:url]; [playerItem addObserver:self forKeyPath:@"status" options:0 context:&ItemStatusContext]; player = [AVPlayer playerWithPlayerItem:playerItem]; NSLog(@"%d",player.status); [player play]; } - (void)playerItemDidReachEnd:(NSNotification *)notification { NSLog(@"Sound finished"); }
source share