I get the following console errors when recording a sound.. Any ideas what I'm doing wrong? The recordings work, except that the outputs are REALLY soft.
TIA
2011-04-17 12:51:25.707 FlashCards[18561:1210f] Cannot find executable for CFBundle/CFPlugIn 0x5a64780 </Library/Audio/Plug-Ins/HAL/DVCPROHDAudio.plugin> (not loaded)
2011-04-17 12:51:25.708 FlashCards[18561:1210f] Cannot find function pointer NewPlugIn for factory C5A4CE5B-0BB8-11D8-9D75-0003939615B6 in CFBundle/CFPlugIn 0x5a64780 </Library/Audio/Plug-Ins/HAL/DVCPROHDAudio.plugin> (not loaded)
2011-04-17 12:51:25.712 FlashCards[18561:1210f] Cannot find executable for CFBundle/CFPlugIn 0x5c69e90 </Library/Audio/Plug-Ins/HAL/iSightAudio.plugin> (not loaded)
2011-04-17 12:51:25.713 FlashCards[18561:1210f] Cannot find function pointer iSightAudioNewPlugIn for factory 9BE7661E-8AEF-11D7-8692-000A959F49B0 in CFBundle/CFPlugIn 0x5c69e90 </Library/Audio/Plug-Ins/HAL/iSightAudio.plugin> (not loaded)
2011-04-17 12:51:25.729 FlashCards[18561:c503] start recording
As requested, I am adding code:
.h file snippet:
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <CoreAudio/CoreAudioTypes.h>
#import <AudioToolbox/AudioToolbox.h>
#protocol BackViewControllerDelegate;
#interface BackViewController : UIViewController <UITextViewDelegate, AVAudioRecorderDelegate, AVAudioPlayerDelegate, UIAlertViewDelegate>
{
AVAudioRecorder *audioRecorder;
AVAudioPlayer *audioPlayer;
IBOutlet UIButton *playButton;
IBOutlet UIButton *recordButton;
IBOutlet UIActivityIndicatorView *autoCog;
BOOL toggle;
}
#property (nonatomic, retain) IBOutlet UIButton *playButton;
#property (nonatomic, retain) IBOutlet UIButton *recordButton;
#property (nonatomic, retain) IBOutlet UIActivityIndicatorView *autoCog;
-(IBAction) recordAudio;
-(IBAction) playAudio;
.m snippet
#synthesize playButton;
#synthesize recordButton;
#synthesize autoCog;
- (void)viewWillAppear:(BOOL)animated {
NSLog(#"%s", __FUNCTION__);
[super viewWillAppear:animated];
//Start the toggle in false mode. PREMISE: WHEN WE GET HERE FIRST, WE ARE NOT RECORDING
toggle = NO;
NSError *error = nil;
//Instantiate an instance of the AVAudioSession object.
AVAudioSession * audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error: &error];
//Activate the session
[audioSession setActive:YES error: &error];
}
-(void) playAudio
{
NSLog(#"%s", __FUNCTION__);
if (audioPlayer.playing) {
[audioPlayer stop];
}
if (toggle == NO)
{
recordButton.enabled = NO;
if (audioPlayer)
[audioPlayer release];
NSError *error;
// GET THE APPROPRIATE SOUND FILE NAME
.....
//CHECK FOR EXISTING SOUNDFILE
if (![[NSFileManager defaultManager] fileExistsAtPath:soundFilePath])
{
UIAlertView *someError = [[UIAlertView alloc] initWithTitle: #"Oops!" message: #"There is not a sound for this word. Press REC to record one. Press cancel to stop" delegate: self
cancelButtonTitle: #"REC" otherButtonTitles:#"CANCEL", nil];
[someError show];
[someError release];
}
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
AudioSessionSetProperty (
kAudioSessionProperty_OverrideCategoryDefaultToSpeaker,
sizeof (doChangeDefaultRoute),
&doChangeDefaultRoute
);
audioPlayer = [[AVAudioPlayer alloc]
initWithContentsOfURL:soundFileURL
error:&error];
audioPlayer.volume = 1.0;
audioPlayer.delegate = self;
if (error){
NSLog(#"Error: %#",
[error localizedDescription]);
}
else
{
[audioPlayer play];
}
}
recordButton.enabled = YES;
//NSLog(#"end of playAudio");
}
I've seen these warnings before, what happens is you copied another older project? if so this is what i did, I simply created a new blank project with the newest version of Xcode, and then started copying the old files into it.
this seemed to clear out those errors.
Related
I've been working on a app that displays the current location of the user in a UILabel using the core location framework in Xcode When a button is clicked the app calls the CLLocationManager that gets the users latitude and longitude. I also included reverse geocoding to present the coordinates in a human readable form. I have this code here.
Header file
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#interface ViewController : UIViewController <CLLocationManagerDelegate>
#property (strong, nonatomic) IBOutlet UILabel *latitudeLabel;
#property (strong, nonatomic) IBOutlet UILabel *longitudeLabel;
#property (strong, nonatomic) IBOutlet UILabel *addressLabel;
- (IBAction)getCurrentLocation:(id)sender;
#end
Implementation file
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController {
CLLocationManager *locationManager;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
locationManager = [[CLLocationManager alloc] init];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)getCurrentLocation:(id)sender {
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
}
#pragma mark - CLLocationManagerDelegate
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(#"didFailWithError: %#", error);
UIAlertView *errorAlert = [[UIAlertView alloc]
initWithTitle:#"Error" message:#"Failed to Get Your Location" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[errorAlert show];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(#"didUpdateToLocation: %#", newLocation);
CLLocation *currentLocation = newLocation;
if (currentLocation != nil) {
_longitudeLabel.text = [NSString stringWithFormat:#"%.8f", currentLocation.coordinate.longitude];
_latitudeLabel.text = [NSString stringWithFormat:#"%.8f", currentLocation.coordinate.latitude];
}
}
#end
I got this output
Message from debugger: Terminated due to signal 15
I know that ABPersonView is not KVO complaint. My issue is that despite declared property of ABPersonView being retained every time I access the property I get different object. Am I doing something wrong or is this correct that every time there was a change in ABPersonView I have to update model with new ABPerson object? Using El Capitan GM.
ABPersonView:
#property (readwrite, retain) ABPerson *person;
// An ABPerson record for display.
// Raises if person originates from ABAddressBook's +sharedAddressBook.
// Person must be exist in an ABAddressBook created and manipulated on the main thread only.
// When person is nil, displays an empty selection state.
Code:
#import "AppDelegate.h"
#import AddressBook;
static void * ABPersonVCContext = &ABPersonVCContext;
#interface AppDelegate ()
#property (weak) IBOutlet NSWindow *window;
#property (strong) ABPerson *person;
#property (strong) ABPersonView *personView;
#property (strong) ABAddressBook *book;
#property (assign, getter=isEditing) BOOL editing;
#property NSTimer *timer;
#end
#implementation AppDelegate
- (instancetype)init {
self = [super init];
if (self) {
_book = [[ABAddressBook alloc] init];
NSString *vCardRepresentation = #"BEGIN:VCARD\r\nVERSION:3.0\r\nN:AA;BB;;;\r\nFN:\r\nEND:VCARD\r\n";
NSData *vCardData = [vCardRepresentation dataUsingEncoding:NSUTF8StringEncoding];
_person = [[ABPerson alloc] initWithVCardRepresentation:vCardData];
[_book addRecord:_person];
[self addObserver:self forKeyPath:#"editing"
options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
context:ABPersonVCContext];
#ifdef DEBUG
NSLog(#"%s %d %s", __FILE__, __LINE__, __PRETTY_FUNCTION__);
NSLog(#"%#",_person);
#endif
}
return self;
}
- (void)awakeFromNib
{
self.personView = [[ABPersonView alloc] initWithFrame:self.window.contentView.frame];
self.personView.person = self.person;
[self.window.contentView addSubview:self.personView];
self.timer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:#selector(reverseEditing) userInfo:NULL repeats:YES];
[self.timer fire];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if (context == ABPersonVCContext) {
if ([keyPath isEqualTo:#"editing"]) {
#ifdef DEBUG
NSLog(#"%s %d %s", __FILE__, __LINE__, __PRETTY_FUNCTION__);
NSLog(#"%#",self.personView.person);
#endif
}
} else {
#try {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
#catch (NSException *exception) {
;
}
#finally {
;
}
}
}
- (void)reverseEditing
{
self.editing = !self.editing;
}
#end
EDIT:
The new object comes from different addressBook instance:
(lldb) po [newPerson addressBook]
<ABAddressBook: 0x6080000d50e0>
(lldb) po self.book
<ABAddressBook: 0x6080000c4130>
(lldb) po [self.person addressBook]
<ABAddressBook: 0x6080000c4130>
EDIT2:
Even registering for notifications does not help because different object is being modified.
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:#selector(changeOccured:) name:kABDatabaseChangedNotification object:nil];
[nc addObserver:self selector:#selector(changeOccured:) name:kABDatabaseChangedExternallyNotification object:nil];
Unfortunately every call to person property of personView triggers ABPersonViewAPIAdapter that converts CNContact to ABPerson. So if one doesn't want to use CNContact on El Capitan he has to propagate edited ABPerson back to the model object.
One can try following code (hope this will save some time to someone)
NSLog(#"%#",[self.personView performSelector:#selector(addressBook) withObject:nil]);
NSLog(#"%#",[self.personView performSelector:#selector(_APIAdapter) withObject:nil]);
NSLog(#"%#",[self.personView performSelector:#selector(_contact) withObject:nil]);
I'm working on a simple Cocoa application that retrieve the meters from an AVAudioRecorder.
Here is my code:
#interface AppDelegate () <AVAudioRecorderDelegate>
#property (weak) IBOutlet NSWindow *window;
#property (strong) AVAudioRecorder *recorder;
#property (strong) NSURL *dump;
#end
#implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSDictionary *settings = #{AVSampleRateKey: #(44100.0),
AVNumberOfChannelsKey: #2,
AVFormatIDKey: #(kAudioFormatAppleLossless),
AVEncoderAudioQualityKey: #(AVAudioQualityHigh)
};
NSError *error = nil;
self.dump = [[NSURL alloc] initFileURLWithPath: [NSTemporaryDirectory() stringByAppendingString: #"dump"]];
self.recorder = [[AVAudioRecorder alloc] initWithURL: self.dump
settings: settings
error: &error];
NSLog(#"Recorder, got error? %#", error);
self.recorder.delegate = self;
[self.recorder prepareToRecord];
self.recorder.meteringEnabled = YES;
[self.recorder record];
}
#end
I also have a timer that retrieves the meters every second. It works on my laptop but on my iMac, for some reason I have a BAD_ACCESS on "com.apple.audio.IOThread.client (8)" when I call record.
Any idea ?
Thanks!
I am writing to a file in an sandboxed app and later trying to set the tags for it using -[NSURL setResourceValue:theTags forKey:NSURLTagNamesKey error:&theTaggingError];. I am not getting any errors (i.e, tags are successfully applied once) but eventually file is kind of replaced and tags are lost. This is only in sandboxed app; if I turn off sandboxing things work fine. In sandboxed mode, if I set tags without writing to the file - again things work fine.
In essence, I am unable to set tags of a file after writing to it. How can I fix it? Any insights?
Sample Code:
#import <Cocoa/Cocoa.h>
#interface AppDelegate : NSObject <NSApplicationDelegate>
{
NSWindow *_window;
NSURL *_saveURL;
NSSavePanel *_savePanel;
}
#property (assign) IBOutlet NSWindow *window;
#property (retain) NSURL *saveURL;
#property (retain) NSSavePanel *savePanel;
- (IBAction)writeAndTag:(id)sender;
- (IBAction)justTag:(id)sender;
#end
#implementation AppDelegate
#synthesize window = _window;
#synthesize saveURL = _saveURL;
#synthesize savePanel = _savePanel;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
self.savePanel = [NSSavePanel savePanel];
}
- (IBAction)writeAndTag:(id)sender
{
[self.savePanel beginSheetModalForWindow:self.window completionHandler:^(NSInteger result) {
self.saveURL = [self.savePanel URL];
NSString *testString = #"Hello!";
NSError *error = nil;
[testString writeToFile:[self.saveURL path] atomically:NO encoding:NSUTF8StringEncoding error:&error];
if(error)
{
NSLog(#"Err in saving: %#" ,error);
error = nil;
}
// Tag is lost here
BOOL success = [self.saveURL setResourceValue:[NSArray arrayWithObjects:#"Test", nil] forKey:NSURLTagNamesKey error:&error];
NSLog(#"Tagging success: %#", (success)?#"YES":#"NO");
if(error)
{
NSLog(#"Err in tagging: %#" ,error);
}
}];
}
- (IBAction)justTag:(id)sender
{
// Works fine
[self.saveURL setResourceValue:[NSArray arrayWithObjects:#"Test", nil] forKey:NSURLTagNamesKey error:NULL];
}
#end
I wrote a Cocoa Application and I got EXC_BAD_ACCESS error when I'm closing an application window. I read that this error usually means problems with memory, but I have ARC mode on and I don't need care about releasing e.t.c. (xCode forbids me to call this functions and manage memory automatically).
Error is pointing at line return NSApplicationMain(argc, (const char **)argv); in main function.
Here's my application's code:
.h file:
#interface MainDreamer : NSWindow <NSWindowDelegate>
{
NSTextField *dreamField;
NSTableView *dreamTable;
NSImageView *dreamview;
NSMutableArray *dreamlist;
NSMutableArray *dataset;
}
#property (nonatomic, retain) IBOutlet NSTextField *dreamField;
#property (nonatomic, retain) IBOutlet NSTableView *dreamTable;
#property (nonatomic, retain) IBOutlet NSImageView *dreamview;
#property (nonatomic, retain) IBOutlet NSMutableArray *dreamlist;
#property (nonatomic, retain) IBOutlet NSMutableArray *dataset;
#property (assign) IBOutlet NSWindow *window;
#end
.m file:
#implementation MainDreamer
#synthesize window;
#synthesize dataset;
#synthesize dreamField;
#synthesize dreamlist;
#synthesize dreamview;
#synthesize dreamTable;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification{
NSString *applicationPath = [[NSBundle mainBundle] bundlePath];
NSString *filename = [applicationPath stringByAppendingPathComponent:#"dreams"];
NSLog(self.description);
dreamlist = [[NSMutableArray alloc] init];
dataset = [[NSMutableArray alloc] init];
dataset = [NSKeyedUnarchiver unarchiveObjectWithFile:filename];
if([dataset count] != 0) {
int i = 0;
while (i < [dataset count]) {
Dream *dr = [[Dream alloc] init];
dr = [dataset objectAtIndex:i];
[dreamlist addObject: dr.dreamname];
i++;
}
}
[dreamTable reloadData];
}
-(void)applicationWillTerminate:(NSNotification *)notification{
NSString *applicationPath = [[NSBundle mainBundle] bundlePath];
NSString *filename = [applicationPath stringByAppendingPathComponent:#"dreams"];
[NSKeyedArchiver archiveRootObject:dataset toFile:filename];
NSLog(#"finish");
}
- (void) mouseUp:(NSEvent *)theEvent{
long index = [dreamTable selectedRow];
Dream *dr = [[Dream alloc] init];
dr = [dataset objectAtIndex:index];
dr.dreampicture = dreamview.image;
[dataset replaceObjectAtIndex:index withObject:dr];
NSLog(self.description);
}
- (void) tableViewSelectionDidChange: (NSNotification *) notification{
long row = [dreamTable selectedRow];
Dream *dr = [[Dream alloc] init];
dr = [dataset objectAtIndex: row];
if(dr.dreampicture != NULL)
dreamview.image = dr.dreampicture;
NSLog(#"selected row changed");
}
Class "Dream":
#interface Dream : NSObject <NSCoding>
{
NSString *dreamname;
NSImage *dreampicture;
}
#property (retain) NSString* dreamname;
#property (retain) NSImage* dreampicture;
-(id)initWithCoder:(NSCoder *)aDecoder;
-(void)encodeWithCoder:(NSCoder *)aCoder;
#end
What is wrong, why EXC_BAD_ACCESS occurs?I remind that I have xCode 4 with Automatic Reference Counting (ARC)
Thanks
UPDATE
I used Profile to find zombie event. So I found out this: An Objective-C message was sent to a deallocated object(zombie( at adress 0x108d85230)
Responsible Caller - [NSApplication(NSWindowCache) _checkForTerminateAfterLastWindowClosed: saveWindows:]
I had this function in code:
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender{
return TRUE;
}
However after I putted it in comments, this zombie event continue to occur.
The crash is caused by the fact that you made the window your application's delegate. When you close the window, that is the last release that kills it off, and if it's the last window you had up, it causes the application to ask its delegate whether it should quit. Since the window you just killed off is the application's delegate, you get that crash.
Longer explanation and suggestion of solution in my answer on your subsequent question.
This is wrong:
dataset = [[NSMutableArray alloc] init]; // WRONG
dataset = [NSKeyedUnarchiver unarchiveObjectWithFile:filename];
Why? You first allocate an empty array, and store that in the instance variable dataset. But in the next line, you replace the empty array with whatever +unarchiveObjectWithFile: returns. Why is this a problem? Well, if you read the docs, you'll see that it returns nil if the file is not found. This means that you now replace the empty array with nil, and all messages you send to dataset will be ignored (messages to nil are silently ignored in Objective-C)
I assume you actually want load the dataset from file, and only if that failed, start with an empty dataset:
dataset = [NSKeyedUnarchiver unarchiveObjectWithFile:filename];
if (dataset==nil) dataset = [[NSMutableArray alloc] init];
You have a similar error later on:
Dream *dr = [[Dream alloc] init]; // WRONG
dr = [dataset objectAtIndex:index];
You create a Dream object, and then replace it immediately with something from the dataset. What you actually want to do is:
Dream *dr;
dr = [dataset objectAtIndex:index];
or shorter:
Dream *dr = [dataset objectAtIndex:index];
Then again, you could replace the while loop with a fast-enumeration-style for loop:
for (Dream *dr in dataset) {
[dreamlist addObject: dr.dreamname];
}
Finally, to get to a point, I don't think the EXC_BAD_ACCESS actually occurs in main.h. I assume you use Xcode 4. Please use the thread/stack navigator in the right sidebar when debugging to find the actual position where the error occurs.
It could be that the error actually occurs in applicationWillTerminate:, because you try to archive dataset, which is probably nil, and it's probably not allowed to archive nil.
With ARC you should use strong and weak instead of retain and assign.