【问题标题】:How do I auto play Audio files?如何自动播放音频文件?
【发布时间】:2011-11-20 01:21:42
【问题描述】:

这是我所拥有的:

-(void)awakeFromNib {
    NSString *path = [[NSBundle mainBundle] pathForResource:***AUDIOFILE*** ofType:@"mp3"];
    AVAudioPlayer* theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] 
                                                                     error:NULL];
    [theAudio play];

编码很好,除了我不知道如何调出我的资源来播放声音或其他什么。

【问题讨论】:

  • 你永远不会在 Xcode 中播放音频文件——它只是一个 IDE

标签: iphone objective-c cocoa-touch audio


【解决方案1】:

如果您的音频文件在您的项目中,那么您只需提供不带扩展名的 Filename 来代替 *AUDIOFILE*

AVAudioPlayer 使用[theAudio prepareToPlay] 方法是一种很好的做法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-17
    • 1970-01-01
    • 2018-02-03
    • 1970-01-01
    相关资源
    最近更新 更多