2009-07-19 14 views
1

Hier ist der Code:System Sound mit Sounds spielen

-(void)stop 
{ 
    NSLog(@"Disposing Sounds"); 
    AudioServicesDisposeSystemSoundID (soundID); 
    //AudioServicesRemoveSystemSoundCompletion (soundID); 
} 

static void completionCallback (SystemSoundID mySSID, void* myself) { 
    NSLog(@"completion Callback"); 
} 
- (void) playall: (id) sender { 

    [self stop]; 

    AudioServicesAddSystemSoundCompletion (soundID,NULL,NULL, 
    completionCallback, 
    (void*) self); 


    OSStatus err = kAudioServicesNoError; 
    NSString *aiffPath = [[NSBundle mainBundle] pathForResource:@"slide1" ofType:@"m4a"]; 
    NSURL *aiffURL = [NSURL fileURLWithPath:aiffPath]; 
    err = AudioServicesCreateSystemSoundID((CFURLRef) aiffURL, &soundID); 
    AudioServicesPlaySystemSound (soundID); 
    NSLog(@"Done Playing"); 
} 

Ausgang:

Disposing Sounds 
Done Playing 

In Wirklichkeit wird kein Ton überhaupt spielen und Rückabwicklung Anruf wird nicht so gut bezeichnet. Irgendeine Idee, was hier falsch sein könnte? Ich möchte jeden vorherigen Ton stoppen, bevor ich den aktuellen Ton anspiele.

Antwort

0

Was enthält Fehler? Daraus sollten Sie das Problem ableiten können.

+0

I gedruckt err mit NSLog und apears zu sein (null) – Shoaibi

+0

Meinst du (Null) oder Null? Ich denke, Sie müssen etwas vorsichtiger mit Ihrem NSLog sein ... (null) ist keine ganze Zahl ...;) –

+0

ich tat dies: NSLog (@ "Fehler:% @", err); Also ich denke, ich drucke Zeichenfolge, und es sagt mir seine "(null)" auf der Konsole. – Shoaibi

1

AFAIK, die nur unterstützt Dateien sind .caf, .aif oder .wav:

To play your own sounds, add the sound file to your application bundle; the sound file must adhere to the following requirements:

  • Must be .caf, .aif, or .wav files.
  • The audio data in the file must be in PCM or IMA/ADPCM (IMA4) format.
  • The file's audio duration must be less than 30 seconds.

Audio & Video Coding How-To's

0

Sie AudioToolBox Rahmen dafür verwenden können:

CFBundleRef mainbundle = CFBundleGetMainBundle(); 
CFURLRef soundFileURLRef = CFBundleCopyResourceURL(mainbundle, CFSTR("tap"), CFSTR("aif"), NULL); 
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundFileObject); 
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); 
AudioServicesPlaySystemSound(1100); 
Verwandte Themen