Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-02-2011, 05:36 PM   #1 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 23
skydive12 is on a distinguished road
Default AVAudioPlayer delay when played

I am having a problem using AVAudioPlayer. There is a major delay (3-4 seconds) the first time the play method is called. I got around this by calling the play immediately at game load time, while the splash screen displays. A kludge but, at least I can live with that piece.

The problem I continue to have, however, is each and every time I call [audioPlayer play], there is a sub-second delay. I have created a Pong game and am calling one of two sounds each time the ball hits either the sides of the court or the ball hits the face of the paddles. Each time the ball hits one of those there is that very small delay but is noticeable enough to be quite annoying. I only notice it when played on the device. In the Simulator it works like a champ. The audio player is supposed to run asynchronously so I’m not sure why the delay.

Any ideas on how to solve the problem? Code below.

Code:
.h file
#import <AVFoundation/AVFoundation.h>

@interface PongViewController : UIViewController 
{
    AVAudioPlayer *audioPlayer;
}

.m file
- (void)viewDidLoad 
{
    NSURL *url = [NSURL fileURLWithPath:[NSString 
      stringWithFormat:@"%@/ponblipg-5.wav", [[NSBundle mainBundle] 
      resourcePath]]];
    NSError *error;
    audioPlayer = [[AVAudioPlayer alloc] 
      initWithContentsOfURL:url error:&error];
    audioPlayer.numberOfLoops = 0;
    [audioPlayer play];  // Delay here and within the game loop.

}

- (void)dealloc
{
    [audioPlayer release];
    [super dealloc];
}
skydive12 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 375
10 members and 365 guests
apatsufas, comicool, Creativ, Dalia, dansparrow, LunarMoon, mer10, Murphy, pbart, Tomsky
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,127
Posts: 402,916
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 07:00 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0