Issues with playing Audio (mp3) on Xcode

1

I have the following problem on my application. When I press the Play button, the mp3 starts playing and also terminates the application.

SongDetailsViewController.h

#import <AVFoundation/AVFoundation.h>
#import <UIKit/UIKit.h>

@interface SongDetailsViewController : UIViewController <AVAudioPlayerDelegate> {
    AVAudioPlayer *player;
    NSString *songID;
    NSString *species;
}
- (void) dismissModal:(id)sender;
- (IBAction) playCall:(id)sender;
- (IBAction) pauseCall:(id)sender;
- (IBAction) stopCall:(id)sender;

@property (nonatomic, retain)     AVAudioPlayer       *player;
@property (nonatomic, copy)     NSString            *songID;
@property (nonatomic, copy)     NSString            *species;
@end

And SongDetailsViewController.m

- (IBAction) pauseCall:(id)sender{
    [player pause];
}
- (IBAction) stopCall:(id)sender
{
    [player stop];
}

- (IBAction) playCall:(id)sender{
    NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);    
    NSString *documentsDir = [documentPaths objectAtIndex:0];
    NSString *songPath = [documentsDir stringByAppendingPathComponent:@"songs"];
    NSString *mySongPath = [songPath stringByAppendingPathComponent:[songID stringByAppendingString:@".mp3"]];

    NSURL *file = [[NSURL alloc] initFileURLWithPath:mySongPath];
    player = [[AVAudioPlayer alloc] initWithContentsOfURL:file error:nil];
    player.delegate=self;
    [player prepareToPlay];
    [player play];
}

Error Stack.

2011-12-29 20:04:40.508 Bird Call Player[6266:307] -[SongDetailsViewController playNote:]: unrecognized selector sent to instance 0x1bcdb0
2011-12-29 20:04:40.531 Bird Call Player[6266:307] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SongDetailsViewController playNote:]: unrecognized selector sent to instance 0x1bcdb0'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x344aaed3 __exceptionPreprocess + 114
    1   libobjc.A.dylib                     0x33975811 objc_exception_throw + 24
    2   CoreFoundation                      0x344ac683 -[NSObject(NSObject) doesNotRecognizeSelector:] + 102
    3   CoreFoundation                      0x344541d9 ___forwarding___ + 508
    4   CoreFoundation                      0x34453f90 _CF_forwarding_prep_0 + 48
    5   CoreFoundation                      0x34452719 -[NSObject(NSObject) performSelector:withObject:withObject:] + 24
    6   UIKit                               0x31b30141 -[UIApplication sendAction:to:from:forEvent:] + 84
    7   UIKit                               0x31b300e1 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 32
    8   UIKit                               0x31b300b3 -[UIControl sendAction:to:forEvent:] + 38
    9   UIKit                               0x31b2fe05 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 356
    10  UIKit                               0x31b30453 -[UIControl touchesEnded:withEvent:] + 342
    11  UIKit                               0x31b2eddd -[UIWindow _sendTouchesForEvent:] + 368
    12  UIKit                               0x31b2e757 -[UIWindow sendEvent:] + 262
    13  UIKit                               0x31b299ff -[UIApplication sendEvent:] + 298
    14  UIKit                               0x31b29337 _UIApplicationHandleEvent + 5110
    15  GraphicsServices                    0x3026c04b PurpleEventCallback + 666
    16  CoreFoundation                      0x3443fce3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 26
    17  CoreFoundation                      0x3443fca7 __CFRunLoopDoSource1 + 166
    18  CoreFoundation                      0x3443256d __CFRunLoopRun + 520
    19  CoreFoundation                      0x34432277 CFRunLoopRunSpecific + 230
    20  CoreFoundation                      0x3443217f CFRunLoopRunInMode + 58
    21  GraphicsServices                    0x3026b5f3 GSEventRunModal + 114
    22  GraphicsServices                    0x3026b69f GSEventRun + 62
    23  UIKit                               0x31ad0123 -[UIApplication _run] + 402
    24  UIKit                               0x31ace12f UIApplicationMain + 670
    25  Bird Call Player                    0x000026cb main + 122
    26  Bird Call Player                    0x00002114 start + 40
)
terminate called after throwing an instance of 'NSException'

If I move the code inside the playCall into the initWithNibName it works fine. Can someone help me to figure out what is the mistake I have done?

Thanking you in advance

iphone
ios
mp3
avaudioplayer
asked on Stack Overflow Dec 29, 2011 by iShah • edited Dec 29, 2011 by Jeff Wolski

1 Answer

1

reason: '-[SongDetailsViewController playNote:]: unrecognized selector sent to instance 0x1bcdb0' in xib did you set your playCall IBAction to your button play or there is another action name?

answered on Stack Overflow Dec 29, 2011 by Andrew

User contributions licensed under CC BY-SA 3.0