简体   繁体   English

iPhone在启动画面上播放声音

[英]iPhone play sound on splash screen

I just want to play a little ding on when the splash screen loads. 我只想在启动屏幕加载时播放一些提示。 I'm guesing that goes in the RootViewControler.m under viewDidLoad. 我猜这是在viewDidLoad下的RootViewControler.m中。 As for playing the audio file I'm googled and found a lot of things I haven't been able to make work. 至于播放音频文件,我被谷歌搜索了,发现了很多我无法完成的工作。

What type of audio file should it be? 它应该是哪种类型的音频文件? wav mp3 etc. or does it matter. WAV mp3等。

I'm not sure what ofType@"caf" is, but here is what I have found, when I try it I get AVAudioplayer undeclared (which I'm thinking is a total newb error but don't know): 我不确定ofType @“caf”是什么,但这里是我发现的,当我尝试它时,我得到AVAudioplayer未声明(我认为这是一个总的新错误,但不知道):

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    NSURL* musicFile = [NSURL fileURLWithPath:[[NSBundle mainBundle] 
                                               pathForResource:@"click"
                                               ofType:@"caf"]];
    AVAudioPlayer *click = [[AVAudioPlayer alloc] initWithContentsOfURL:musicFile error:nil];
    [click play];
    [click release];
    [super viewDidLoad];
}

Thank you for any help, R 谢谢您的帮助,R

I think the problem is that you haven't added the AVFoundation framework. 我认为问题在于您尚未添加AVFoundation框架。 Once you add the AVFoundation.framework, you'll need to #import <AVFoundation/AVAudioPlayer.h> and hopefully it will work. 添加AVFoundation.framework后,您需要#import <AVFoundation/AVAudioPlayer.h> ,希望它可以工作。

From the Apple Documentation : pathForResource:ofType: Apple文档获取pathForResource:ofType:

Returns the full pathname for the resource identified by the specified name and file extension. 返回由指定名称和文件扩展名标识的资源的完整路径名。

  - (NSString *)pathForResource:(NSString *)name ofType:(NSString *)extension

The program looks for a file called click.caf in your main bundle. 该程序在主包中查找名为click.caf的文件。 The warning about AVPlayer being undeclared means that you have to add the AVFoundationFramework to your project and import the proper .h - file with #import <AVFoundation/AVAudioPlayer.h> . 有关AVPlayer未声明的警告意味着您必须将AVFoundationFramework添加到项目中并使用#import <AVFoundation/AVAudioPlayer.h>导入正确的.h文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM