gpt4 book ai didi

ios - 在 iOS 中播放歌曲

转载 作者:行者123 更新时间:2023-11-28 22:13:12 24 4
gpt4 key购买 nike

我试图在 iOS 中播放歌曲,但它给我一条错误消息。

头文件.h

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

@interface PRPViewController : UIViewController{
AVAudioPlayer *audioPlayer;
IBOutlet UIButton *start;
}

-(IBAction)play;

@end

执行文件.m

NSURL *url = [NSURL fileURLWithPath:
[NSString stringWithFormat:@"%@/bobmarley.mp3",
[[NSBundle mainBundle] resourcePath]]];

NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsofURL:url error:&error];
audioPlayer.numberOfLoops = 0;

[audioPlayer play];

但是它说

No visible @interface for AVAudioPlayer declares the selector 'initWithContentsofUrl:error:'

我该怎么办?

最佳答案

Of 中的“O”应该大写。在 Objective-C 中,拼写很重要,包括大写。 initWithContentsofURLinitWithContentsOfURL 是两个不同的东西。

(顺便说一句,这是尽可能多地使用自动完成的一个很好的理由。自动完成机制比你更清楚如何拼写声明的方法的名称!)

关于ios - 在 iOS 中播放歌曲,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22384259/

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