gpt4 book ai didi

iphone - 在 Xcode 上播放音频 (mp3) 的问题

转载 作者:行者123 更新时间:2023-11-29 13:42:39 25 4
gpt4 key购买 nike

我的应用程序存在以下问题。当我按下播放按钮时,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 中,它就可以正常工作。有人可以帮我弄清楚我犯了什么错误吗?

提前致谢

最佳答案

原因:'-[SongDetailsViewController playNote:]: 无法识别的选择器发送到实例 0x1bcdb0'在 xib 中,您是否将 playCall IBAction 设置为您的按钮播放或有另一个 Action 名称?

关于iphone - 在 Xcode 上播放音频 (mp3) 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8669210/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com