0

I don't seem to able to playback sounds using AVQueuePlayer. The application compiles and runs fine but i'm not getting any audio when the `imageTouched' method is called. Can anyone help?

-(void) imageTouched
{
    NSString * path1 = [[NSBundle mainBundle] pathForResource:@"sound1" ofType:@"wav"];
    NSString * path2 = [[NSBundle mainBundle] pathForResource:@"sound2" ofType:@"wav"];
    NSURL *url1 = [NSURL fileURLWithPath:path1];
    NSURL *url2 = [NSURL fileURLWithPath:path2];

    AVPlayerItem *firstSound = [AVPlayerItem playerItemWithURL:url1];
    AVPlayerItem *secondSound = [AVPlayerItem playerItemWithURL:url2];

    NSArray *sounds = [NSArray arrayWithObjects:firstSound, secondSound, nil];
    AVQueuePlayer *player = [AVQueuePlayer queuePlayerWithItems:sounds];

    [player play];
    NSLog(@"%d",player.status);

}

EDIT 1: I've checked to see if there was any problem with the filenames (case, spelling, etc) and there doesn't seem to be. I've been able to play the sounds with the following code but i really need to get AVQueuePlayer working. Please help!

NSString *path;
SystemSoundID soundId;
path = [[NSBundle mainBundle] pathForResource:@"sound1" ofType:@"wav"];
NSURL *url = [NSURL fileURLWithPath:path];
AudioServicesCreateSystemSoundID( (CFURLRef)objc_unretainedPointer( url), &soundId);
AudioServicesPlaySystemSound(soundId);
garethdn
  • 12,022
  • 11
  • 49
  • 83
  • Check that the sound files are actually included in your app bundle and with their file names spelled correctly (including case). – hotpaw2 May 16 '12 at 18:34
  • The sounds are copied to my resources folder and the spelling is correct; unfortunately that's not the problem. My nslog is printing 0 if that's any help – garethdn May 16 '12 at 21:15
  • I should have also mentioned that i can play the sounds fine using `AudioServicesPlaySystemSound(soundId);` but i want to use `AVQueuePlayer`. Is there maybe something i'm missing out in my .h file? – garethdn May 17 '12 at 00:06

2 Answers2

0

I realise it may be too late for you by now, but I suspect that reason is that the AVQueuePlayer is being autoreleased immediately, so no sound is played. Try [[AVQueuePlayer alloc] initWithItems:sounds] instead.

Craig McMahon
  • 1,550
  • 1
  • 14
  • 36
0

I did nearly the same think but instead of declaring the AVQueuePlayer *player in the function, I declared it in the interface.

attin83
  • 115
  • 3
  • 8