//
// ViewController.m
// PlayAudio
//
// Created by hq on 16/5/12.
// Copyright © 2016年 hanqing. All rights reserved.
//
#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
SystemSoundID sysId=0;
//我们音频文件的路径
NSURL *url=[[NSBundle mainBundle] URLForResource:@"aaa.wav" withExtension:nil];
CFURLRef urlRef=(__bridge CFURLRef)url;
AudioServicesCreateSystemSoundID(urlRef, &sysId);
//声音+震动
AudioServicesPlayAlertSound(sysId);
//声音 AudioServicesPlaySystemSound(sysId);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
ios最简单的播放音频程序
最新推荐文章于 2025-05-17 13:12:42 发布
本文提供了一个简单的iOS应用示例,展示了如何使用Objective-C在应用中加载并播放音频文件。该示例通过ViewController类实现,利用了AVFoundation框架来创建SystemSoundID,并播放指定资源路径下的音频。
1400

被折叠的 条评论
为什么被折叠?



