2012-08-27 1 views
0

J'utilise le code suivant: Le son est placé mY dans myapp/Ressources partagées/background_music.aiffPas de musique de fond tout en jouant sur Xcode 4.2

@synthesize window = _window; 
- (void)dealloc 
{ 
    [backgroundSound release]; 
    [_window release]; 
    [super dealloc]; 
} 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    // Override point for customization after application launch. 
    sleep(3); 
    //this variable can be named differently 

    NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/background_music.aiff",[[NSBundle mainBundle] resourcePath]]]; 
    NSError *error; 

    backgroundSound = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error]; 

    backgroundSound.numberOfLoops = -1; 
    //>> this will allow the file to //play an infinite number of times */ 

    return YES; 
} 



@interface AppDelegate : UIResponder <UIApplicationDelegate>{ 
    AVAudioPlayer *backgroundSound; 

} 

@property (strong, nonatomic) UIWindow *window; 
@end 

Il n'y a pas d'erreur et il n'y a pas de boucle dire sound.Kindly moi ce qui se passe.

Cordialement

+1

Rien à voir avec le problème, mais l'utilisation de 'sleep (3);' dans 'didFinishLaunchingWithOptions' entraînera de gros problèmes. Parce que si votre application ne démarre pas assez vite, iOS la détruira. Il est préférable de superposer le rootviewcontroller à 'default.png' et de le supprimer lorsque votre application est complètement chargée. – rckoenes

+0

@NSPostWhenIdle pas de son –

+0

La journalisation de l'URL du son est-elle correcte? –

Répondre

2

ok j'ajouté [background play]; et il a commencé à travailler très bien ..... qui n'a pas été mentionné dans le tutoriel que je suivais ..

0
player = [[MPMoviePlayerController alloc] initWithContentURL:url]; 
    player.movieSourceType = MPMovieSourceTypeStreaming; 
    if(player.playbackState == MPMoviePlaybackStatePlaying) 
     [player stop]; 
    [player play];