【问题标题】:AudioServicesCreateSystemSoundID not playing mp3 filesAudioServicesCreateSystemSoundID 不播放 mp3 文件
【发布时间】:2011-09-25 12:11:54
【问题描述】:

谁能回答如何使用AudioServicesCreateSystemSoundID() 播放mp3 文件?我试过了,但没用。

我用下面的代码sn-p播放mp3

NSURL *soundURL   = [[NSBundle mainBundle] URLForResource:fileName withExtension:extension];

soundFileURLRef = (CFURLRef) [soundURL retain];

// Create a system sound object representing the sound file.
AudioServicesCreateSystemSoundID ( soundFileURLRef,&soundFileObject);

【问题讨论】:

  • 你能展示你尝试了什么吗?
  • NSURL *soundURL = [[NSBundle mainBundle] URLForResource:fileName withExtension:extension]; //文件名和扩展名在调用函数时给出。 soundFileURLRef = (CFURLRef) [soundURL 保留]; AudioServicesCreateSystemSoundID (soundFileURLRef,&soundFileObject);
  • 请不要在 cmets 部分发布代码 sn-ps,因为它们无法正确格式化并且完全不可读。继续更新您的原始问题。

标签: ios objective-c audio mp3 playback


【解决方案1】:

我在使用这个例子时遇到了同样的问题。也许你的声音样本太大/太长了。

NSString *path = [[NSBundle mainBundle] pathForResource:@"tap" ofType:@"aif"];

NSURL *url = [NSURL fileURLWithPath:path];AudioServicesCreateSystemSoundID((__bridge CFURLRef)url, &mBeep);

AudioServicesPlaySystemSound(mBeep);

由于音频文件太长,它无法正常工作。我尝试了来自苹果示例http://developer.apple.com/library/ios/#samplecode/SysSound/Introduction/Intro.html“tap.aif”的声音,效果很好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-25
    • 1970-01-01
    • 2017-06-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多