IOS拼接MP3,歌曲文件合成。
发布日期:2021-10-02 15:44:22
浏览次数:1
分类:技术文章
本文共 1783 字,大约阅读时间需要 5 分钟。
其实就是把MP3文件转成NSData,然后再进行拼合。
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- // Do any additional setup after loading the view, typically from a nib.
- //音频文件路径
- NSString *mp3Path1 = [[NSBundle mainBundle] pathForResource:@"1" ofType:@"mp3"];
- NSString *mp3Path2 = [[NSBundle mainBundle] pathForResource:@"2" ofType:@"mp3"];
- NSString *mp3Path3 = [[NSBundle mainBundle] pathForResource:@"3" ofType:@"mp3"];
- //音频数据
- NSData *sound1Data = [[NSData alloc] initWithContentsOfFile: mp3Path1];
- NSData *sound2Data = [[NSData alloc] initWithContentsOfFile: mp3Path2];
- NSData *sound3Data = [[NSData alloc] initWithContentsOfFile: mp3Path3];
- //合并音频
- NSMutableData *sounds = [NSMutableData alloc];
- [sounds appendData:sound1Data];
- [sounds appendData:sound2Data];
- [sounds appendData:sound3Data];
- //保存音频
- NSLog(@"data length:%d", [sounds length]);
- [sounds writeToFile:[self filePathWithName:@"tmp.mp3"] atomically:YES];
- player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[self filePathWithName:@"tmp.mp3"]] error:nil];
- player.delegate = self;
- [player prepareToPlay];
- }
- - (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
- {
- MPMusicPlayerController *ipodPlayer = [MPMusicPlayerController iPodMusicPlayer];
- if ([ipodPlayer playbackState] == MPMusicPlaybackStateInterrupted) {
- [ipodPlayer play];
- }
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (NSString *)filePathWithName:(NSString *)filename
- {
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *documentsDirectory = [paths objectAtIndex:0];
- return [documentsDirectory stringByAppendingPathComponent:filename];
- }
- - (IBAction)buttonClick:(id)sender {
- [player play];
- }
转载地址:https://blog.csdn.net/jinyeweiyang/article/details/41286289 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
路过,博主的博客真漂亮。。
[***.116.15.85]2024年03月03日 07时18分34秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
苹果笔记本的end键_笔记本用户的大烦恼:触控板,想好好用你不容易
2019-04-21
趣玩机器人什么时候成立的_【直播回顾】当我们谈机器人集成调试的时候在谈什么...
2019-04-21
vue 地理位置定位_HTML5地理位置
2019-04-21
pac代理模式什么意思_托管仓库租赁电商仓储运营模式托管什么意思
2019-04-21
validated 验证数组_在 Laravel 中处理请求验证的智能方法
2019-04-21
java 拼接路径优雅方式_Java安全编码实践总结
2019-04-21
realme x2 深度测试打不开_搭载65W超级闪充,realme真我X7手机充电评测
2019-04-21
整数取反编程_【每日编程185期】数字的补数
2019-04-21
能用别的软件吗_手机软件能用蓝牙传送吗
2019-04-21
为什么图片要2的倍数_为什么宝宝喜欢流“口水”?这种2种原因父母要知道,建议收藏...
2019-04-21
下载了XAMPP怎样打开MYSQL_xampp mysql安装启动
2019-04-21
pdo转mysql_mysql转mysqli或pdo
2019-04-21
mysql如果没有表就创建_mysql – 改变表是否存在或创建如果没有
2019-04-21
ireport连接mysql_ireport 4.5教程之数据源介绍
2019-04-21
mysql多维模型_数据仓库数据库设计方法---关系模型和多维模型比较分析
2019-04-21
局域网聊天程序 java MySQL_java 基于TCP/IP协议的局域网聊天小程序
2019-04-21
r glm 中的p值_假设检验中的P值
2019-04-21