【问题标题】:.mp3 & .wav Files in XcodeXcode 中的 .mp3 和 .wav 文件
【发布时间】:2012-12-13 03:03:58
【问题描述】:

我在 xcode 中进行了以下设置,但没有声音出现。我之前有 2 个 .wav 文件可以使用,但其他 .mp3 和 .wav 文件无法使用,我想知道它是编写的代码还是声音文件?文件的比特率或大小有什么限制吗?请参阅下面的代码。我还将声音文件添加到项目中。

**ViewController.h** 
import UIKit/UIKit.h

import AVFoundation/AVFoundation.h

import AudioToolbox/AudioToolbox.h

@interface ViewController :UIViewController 


-(IBAction)AntlerRabbit;



@end


**ViewController.m**

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController


-(IBAction)AntlerRabbit {

CFBundleRef mainBundle = CFBundleGetMainBundle();

CFURLRef soundFileURLRef;

soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"AntlerRabbit",         CFSTR("aiff"), NULL);

UInt32 soundID;

AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);

AudioServicesPlaySystemSound(soundID);

}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end

然后我转到 MainStoryboard.storyboard 并放置一个按钮并将其链接到“AntlerRabbit”,但模拟器中没有任何反应

【问题讨论】:

    标签: xcode mp3 audio


    【解决方案1】:

    答案就在这里:

    Using Audio in Xcode

    模拟器没有声音是因为你在使用的时候,

    AudioServicesPlaySystemSound
    

    声音最长不得超过 30 秒。我使用的声音略高于它。如果有人知道如何使用超过 30 秒的声音文件,请发布代码:) 将不胜感激。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-19
      • 2016-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-12
      相关资源
      最近更新 更多