Проблемы с воспроизведением аудио (mp3) на Xcode - PullRequest
1 голос
/ 29 декабря 2011

У меня есть следующая проблема в моем приложении. Когда я нажимаю кнопку «Воспроизведение», начинает воспроизводиться mp3, а также прекращается работа приложения.

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

И 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];
}

стек ошибок.

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'

Если я перемещу код внутри playCall в initWithNibName, он будет работать нормально. Может ли кто-нибудь помочь мне понять, какую ошибку я совершил?

Заранее благодарю

1 Ответ

1 голос
/ 29 декабря 2011

причина: '- [SongDetailsViewController playNote:]: нераспознанный селектор, отправленный экземпляру 0x1bcdb0' в xib, вы установили IBAction playCall на воспроизведение кнопки или есть другое имя действия?

...