Enregistrement Audio- Pb de mémoire

SalmaSalma Membre
02:28 modifié dans API UIKit #1
Bonjour à  tous,

J'ai utilisé l'exemple fournit dans la documentation:SpeakHere pour créer un enregistreur Audio dans l'application et lire ce fichier Audio.
Le problème c'est que des fois il m'affiche un message d'erreur en indicant que je n'ai plus d'espace mémoire alors que j'ai 5Go de mémoire libre et ceci génére des erreurs et ça plante des fois...ou refuse d'enregistrer.
Je vous met une partie du code:

- (id) initWithNibName: (NSString *) nibNameOrNil bundle: (NSBundle *) nibBundleOrNil {<br /><br />	self = [super initWithNibName: nibNameOrNil bundle: nibBundleOrNil];<br /><br />	if (self != nil) {<br /><br />		// this app uses a fixed file name at a fixed location, so it makes sense to set the name and <br />		// URL here.<br />		NSArray *filePaths =	NSSearchPathForDirectoriesInDomains (<br />		<br />									NSDocumentDirectory, <br />									NSUserDomainMask,<br />									YES<br />								); <br />								<br />		self.recordingDirectory = [filePaths objectAtIndex: 0];<br />		appDelegate = (MyAlertsAppDelegate *)[[UIApplication sharedApplication] delegate];<br />		NSString *nameFile = [[NSString alloc] initWithString:[NSString stringWithFormat: @&quot;%@/Recording&quot;, self.recordingDirectory]];<br />		nameFile = [nameFile stringByAppendingString:[appDelegate typeConfig]];<br />		nameFile = [nameFile stringByAppendingString:@&quot;.caf&quot;];<br />		NSLog(nameFile);<br />		CFStringRef fileString = (CFStringRef) nameFile;<br /><br />		// create the file URL that identifies the file that the recording audio queue object records into<br />		CFURLRef fileURL =	CFURLCreateWithFileSystemPath (<br />								NULL,<br />								fileString,<br />								kCFURLPOSIXPathStyle,<br />								false<br />							);<br />		NSLog (@&quot;Recorded file path: %@&quot;, fileURL); // shows the location of the recorded file<br />		<br />		// save the sound file URL as an object attribute (as an NSURL object)<br />		if (fileURL) {<br />			self.soundFileURL	= (NSURL *) fileURL;<br />			CFRelease (fileURL);<br />		}<br />		<br />		// allocate memory to hold audio level values<br />		audioLevels = calloc (2, sizeof (AudioQueueLevelMeterState));<br />		peakLevels = calloc (2, sizeof (AudioQueueLevelMeterState));<br /><br />		// initialize the audio session object for this application,<br />		//		registering the callback that Audio Session Services will invoke <br />		//		when there&#39;s an interruption<br />		AudioSessionInitialize (<br />			NULL,<br />			NULL,<br />			interruptionListenerCallback,<br />			self<br />		);<br />		<br />		AudioSessionAddPropertyListener (<br />			kAudioSessionProperty_AudioRouteChange,<br />			audioRouteChangeListenerCallback,<br />			self<br />		);<br />	}<br />	return self;<br />}


<br />// respond to a tap on the Record button. If stopped, start recording. If recording, stop.<br />// an audio queue object is created for each recording, and destroyed when the recording finishes.<br />- (IBAction) recordOrStop: (id) sender {<br /><br />	NSLog (@&quot;recordOrStop:&quot;);<br />	<br />	// if not recording, start recording<br />	if (self.audioRecorder == nil) {<br />	<br />		// before instantiating the recording audio queue object, <br />		//	set the audio session category<br />		UInt32 sessionCategory = kAudioSessionCategory_RecordAudio;<br />		AudioSessionSetProperty (<br />			kAudioSessionProperty_AudioCategory,<br />			sizeof (sessionCategory),<br />			&amp;sessionCategory<br />		);<br />			<br />		// the first step in recording is to instantiate a recording audio queue object<br />		AudioRecorder *theRecorder = [[AudioRecorder alloc] initWithURL: self.soundFileURL];<br /><br />		// if the audio queue was successfully created, initiate recording.<br />		if (theRecorder) {<br /><br />			self.audioRecorder = theRecorder;<br />			[theRecorder release];								// decrements the retain count for the theRecorder object<br />			<br />			[self.audioRecorder setNotificationDelegate: self];	// sets up the recorder object to receive property change notifications <br />																//	from the recording audio queue object<br /><br />			// activate the audio session immediately before recording starts<br />			AudioSessionSetActive (true);<br /><br />			NSLog (@&quot;sending record message to recorder object.&quot;);<br />			[self.audioRecorder record];						// starts the recording audio queue object<br />		}<br /><br />	// else if recording, stop recording<br />	} else if (self.audioRecorder) {<br /><br />			[self.audioRecorder setStopping: YES];				// this flag lets the property listener callback<br />																//	know that the user has tapped Stop<br />			NSLog (@&quot;sending stop message to recorder object.&quot;);<br />			[self.audioRecorder stop];							// stops the recording audio queue object. the object <br />																//	remains in existence until it actually stops, at<br />																//	which point the property listener callback calls<br />																//	this class&#39;s updateUserInterfaceOnAudioQueueStateChange:<br />																//	method, which releases the recording object.<br />			// now that recording has stopped, deactivate the audio session<br />			AudioSessionSetActive (false);<br />	}<br />}


<br /><br />// respond to a tap on the Play button. If stopped, start playing. If playing, stop.<br />- (IBAction) playOrStop: (id) sender {<br /><br />	NSLog (@&quot;playOrStop:&quot;);<br />	<br />	// if not playing, start playing<br />	if (self.audioPlayer == nil) {<br />	<br />		// before instantiating the playback audio queue object, <br />		//	set the audio session category<br />		UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;<br />		AudioSessionSetProperty (<br />			kAudioSessionProperty_AudioCategory,<br />			sizeof (sessionCategory),<br />			&amp;sessionCategory<br />		);<br />			<br />		AudioPlayer *thePlayer = [[AudioPlayer alloc] initWithURL: self.soundFileURL];<br />		<br />		if (thePlayer) {<br />		<br />			self.audioPlayer = thePlayer;<br />			[thePlayer release];								// decrements the retain count for the thePlayer object<br />			<br />			[self.audioPlayer setNotificationDelegate: self];	// sets up the playback object to receive property change notifications from the playback audio queue object<br /><br />			// activate the audio session immmediately before playback starts<br />			AudioSessionSetActive (true);<br />			NSLog (@&quot;sending play message to play object.&quot;);<br />			[self.audioPlayer play];<br />		}<br />		<br />	// else if playing, stop playing<br />	} else if (self.audioPlayer) {<br /><br />		NSLog (@&quot;User tapped Stop to stop playing.&quot;);<br />		[self.audioPlayer setAudioPlayerShouldStopImmediately: YES];<br />		<br />		NSLog (@&quot;Calling AudioQueueStop from controller object.&quot;);<br />		[self.audioPlayer stop];<br />		<br />		// the previous statement returns after the audioPlayer object is completely<br />		// stopped, which also ensures that the underlying audio queue object is <br />		// stopped, so now it&#39;s safe to release the audioPlayer object.<br />		[audioPlayer release];<br />		audioPlayer = nil;<br /><br />		// now that playback has stopped, deactivate the audio session<br />		AudioSessionSetActive (false);<br />	}&nbsp; <br />}


Je m'exuse si c'est un peu long.
J'ai essayé de récupérer le chemin dans lequel le fichier est enregistré et ça donne ça:

/var/mobile/Applications/5122F629-D8B7-469C-BA20-C37B67B37B5F/Documents/Recording1.caf


Auriez vous une idée sur l'origine du probléme mémoire ?

Réponses

  • SalmaSalma Membre
    02:28 modifié #2
    En plus je n'arrive plus à  écouter l'enregistrement alors que ça fonctionne sur le simulateur.
Connectez-vous ou Inscrivez-vous pour répondre.