如何实现声音到存在的应用程序,没有的Cocos2D [英] How to implement sound into an existent app, without Cocos2D

查看:115
本文介绍了如何实现声音到存在的应用程序,没有的Cocos2D的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,iOS的SDK下载页面上,有样品code;我使用的计算器应用程序(iPhoneUnitTests)。我想知道,如果有可能的声音添加到按钮presses上的已建成的应用程序,轻松。

For example, on the iOS SDK download page, there's sample code; I'm using the calculator app (iPhoneUnitTests). I would like to know if it is possible to add sounds to the button presses on the app that's already built, easily.

推荐答案

这其实是打短的声音,像按钮听起来很简单。下面是一个简单的例子。

It is actually very simple to play short sounds, like button sounds. Here is a quick example.

您必须链接AudioToolbox.framework二进制

SoundExampleViewController.h;

SoundExampleViewController.h;

#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>
@interface SoundExampleViewController : UIViewController{
    SystemSoundID mySoundID;
}
@end

SoundExampleViewController.m:

SoundExampleViewController.m:

#import "SoundExampleViewController.h"
@implementation SoundExampleViewController
- (void)viewDidLoad{
    [super viewDidLoad];
    NSString *path = [[NSBundle mainBundle] pathForResource:@"SoundFileName" ofType:@"wav"]; 
    AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:path],&mySoundID);
}
- (void)viewDidUnload{
    [super viewDidUnload];
    AudioServicesDisposeSystemSoundID(mySoundID);
}
@end

然后发挥你只需拨打: AudioServicesPlaySystemSound(mySoundID);

这篇关于如何实现声音到存在的应用程序,没有的Cocos2D的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆