【问题标题】:No Visible interface for 'AVAudioPlayer declares the selector initWithUrl:''AVAudioPlayer 声明选择器 initWithUrl:' 没有可见接口
【发布时间】:2014-01-19 14:58:39
【问题描述】:

我正在尝试播放按钮点击声音,我也应该能够管理点击声音以及音量按钮。

我所做的是 将 AVFoundationFramework 添加到项目中,

在.h文件中

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

在.m文件下的按钮点击方法

NSString *soundPath = [[NSBundle mainBundle] pathForResource:@"sound1" ofType:@"mp3"];
NSURL *soundUrl = [NSURL fileURLWithPath:soundPath];

AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithURL:soundUrl];

[player play];

但我收到上述错误。任何帮助将不胜感激。

【问题讨论】:

    标签: ios audio uibutton avfoundation


    【解决方案1】:

    这是"initWithContentsOfURL:" 而不是“initWithURL:”。

    如:

    AVAudioPlayer *player = [[AVAudioPlayer alloc] 
                              initWithContentsOfURL:soundUrl];
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多