音视频
来源:互联网 发布:淘宝买家超级会员等级 编辑:程序博客网 时间:2024/04/28 23:42
1.录音
NSString*path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES)lastObject];
path = [path stringByAppendingPathComponent:@"123.MP3"];
NSURL *url = [NSURLURLWithString:path];
//1.1创建录音对象
// settings 录音文件质量的
NSDictionary *setting = [NSDictionarydictionary];
AVAudioRecorder *recorder = [[AVAudioRecorderalloc]initWithURL:urlsettings:settingerror:nil];
//2.开始
path = [path stringByAppendingPathComponent:@"123.MP3"];
NSURL *url = [NSURLURLWithString:path];
//1.1创建录音对象
// settings 录音文件质量的
NSDictionary *setting = [NSDictionarydictionary];
AVAudioRecorder *recorder = [[AVAudioRecorderalloc]initWithURL:urlsettings:settingerror:nil];
//2.开始
[recorderrecord];
2.播放音效
//1.获取文件
NSString *path = @"/Users/apple/Desktop/123.MP3";
NSURL *url = [NSURLfileURLWithPath:path];
SystemSoundID soundID = 0;
//1.返回值 2.&
//桥接
AudioServicesCreateSystemSoundID((__bridgeCFURLRef _Nonnull)(url), &soundID);
//2.播放
//没有震动效果
AudioServicesPlaySystemSound(soundID);
//有震动效果
NSString *path = @"/Users/apple/Desktop/123.MP3";
NSURL *url = [NSURLfileURLWithPath:path];
SystemSoundID soundID = 0;
//1.返回值 2.&
//桥接
AudioServicesCreateSystemSoundID((__bridgeCFURLRef _Nonnull)(url), &soundID);
//2.播放
//没有震动效果
AudioServicesPlaySystemSound(soundID);
//有震动效果
// AudioServicesPlayAlertSound(soundID);
3.播放多个文件,工具类
#import<Foundation/Foundation.h>
@interfaceCZPlayMusicTool : NSObject
//播放音乐
+ (void)playAudioWithName:(NSString*)name;
//暂停音乐
+ (void)pauseAudioWithName:(NSString*)name;
//停止音乐
+ (void)stopAudioWithNmae:(NSString*)name;
@interfaceCZPlayMusicTool : NSObject
//播放音乐
+ (void)playAudioWithName:(NSString*)name;
//暂停音乐
+ (void)pauseAudioWithName:(NSString*)name;
//停止音乐
+ (void)stopAudioWithNmae:(NSString*)name;
@end
#import"CZPlayMusicTool.h"
#import <AVFoundation/AVFoundation.h>
staticNSMutableDictionary *_players;
@implementationCZPlayMusicTool
+ (void)initialize{
_players = [NSMutableDictionarydictionary];
}
//播放音乐
+ (void)playAudioWithName:(NSString*)name{
AVAudioPlayer *player = _players[name];
if (player == nil) {
NSString *path = [[NSBundlemainBundle]pathForResource:nameofType:nil];
NSURL *url = [NSURLfileURLWithPath:path];
player = [[AVAudioPlayeralloc]initWithContentsOfURL:urlerror:nil];
[_playerssetObject:playerforKey:name];
}
//开始播放
[player play];
}
//暂停音乐
+ (void)pauseAudioWithName:(NSString*)name{
AVAudioPlayer *player = _players[name];
if (player) {
[player pause];
}
}
//停止音乐
+ (void)stopAudioWithNmae:(NSString*)name{
AVAudioPlayer *player = _players[name];
if (player) {
[player stop];
}
#import <AVFoundation/AVFoundation.h>
staticNSMutableDictionary *_players;
@implementationCZPlayMusicTool
+ (void)initialize{
_players = [NSMutableDictionarydictionary];
}
//播放音乐
+ (void)playAudioWithName:(NSString*)name{
AVAudioPlayer *player = _players[name];
if (player == nil) {
NSString *path = [[NSBundlemainBundle]pathForResource:nameofType:nil];
NSURL *url = [NSURLfileURLWithPath:path];
player = [[AVAudioPlayeralloc]initWithContentsOfURL:urlerror:nil];
[_playerssetObject:playerforKey:name];
}
//开始播放
[player play];
}
//暂停音乐
+ (void)pauseAudioWithName:(NSString*)name{
AVAudioPlayer *player = _players[name];
if (player) {
[player pause];
}
}
//停止音乐
+ (void)stopAudioWithNmae:(NSString*)name{
AVAudioPlayer *player = _players[name];
if (player) {
[player stop];
}
}
- (IBAction)play:(id)sender {
[CZPlayMusicTool playAudioWithName:@"咖啡.mp3"];
}
- (IBAction)stop:(id)sender {
[CZPlayMusicToolplayAudioWithName:@"煎饼侠.mp3"];
}
- (IBAction)anting:(id)sender {
[CZPlayMusicToolpauseAudioWithName:@"煎饼侠.mp3"];
}
- (IBAction)djkfs:(id)sender {
[CZPlayMusicToolstopAudioWithNmae:@"咖啡.mp3"];
}
- (IBAction)stop2:(id)sender {
[CZPlayMusicToolstopAudioWithNmae:@"煎饼侠.mp3"];
[CZPlayMusicTool playAudioWithName:@"咖啡.mp3"];
}
- (IBAction)stop:(id)sender {
[CZPlayMusicToolplayAudioWithName:@"煎饼侠.mp3"];
}
- (IBAction)anting:(id)sender {
[CZPlayMusicToolpauseAudioWithName:@"煎饼侠.mp3"];
}
- (IBAction)djkfs:(id)sender {
[CZPlayMusicToolstopAudioWithNmae:@"咖啡.mp3"];
}
- (IBAction)stop2:(id)sender {
[CZPlayMusicToolstopAudioWithNmae:@"煎饼侠.mp3"];
}
0 0
- 音视频
- 音视频
- 音视频
- 音视频
- Android音视频-视频基础
- Android实现视频剪切、视频拼接以及音视频合并
- 音视频支持和音视频播放
- win音视频--Dshow视频采集显示
- win音视频--qt视频显示
- 视频开发之外部音视频输入
- 视频开发之外部音视频输入
- 音视频技术 视频抖动优化
- 音视频技术 视频抖动优化
- 音视频开发平台 视频录制技术
- 音视频技术 视频开发参考资料
- 音视频处理-ffmpeg+sdl视频播放
- 音视频聊天开发: 1 视频采集
- 视频终端测试,音视频性能检测
- Android中几种常用的定时器和延时方法
- 二维码扫描,真机
- OCI动态链接ORACLE
- WIFI之3GControl模块调度草图
- 字体:获取字体尺寸
- 音视频
- Do_TextView
- poj1125 Dijkstra
- 测试利用Binder进行双向通信
- Ugly Number
- WIFI之系统部署环境
- EAS8.0解决方案需要构建的jar目录
- Python——参数(1)
- ASP.NET母版与内容页相对路径的问题