IOS拼接MP3,歌曲文件合成。
来源:互联网 发布:淘宝的来历,知乎 编辑:程序博客网 时间:2024/04/30 14:04
其实就是把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];
- }
0 0
- IOS拼接MP3,歌曲文件合成。
- IOS拼接MP3,歌曲文件合成。
- IOS使用AVAudioPlayer播放mp3歌曲文件并监听来电打断
- IOS使用AVAudioPlayer播放mp3歌曲文件并监听来电打断
- IOS使用AVAudioPlayer播放mp3歌曲文件并监听来电打断
- 如何读取MP3歌曲文件标志信息
- NOKIA C6-00 MP3歌曲文件乱码
- android获取MP3文件的歌曲信息
- iOS图片拼接,图片文字合成总结
- 如何使用Quartz库播放MP3歌曲文件
- mp3文件后128字节歌曲信息读写操作
- C# 获取mp3文件的歌曲时间长度
- iOS多个视频拼接合成为一个视频
- C#读mp3歌曲信息
- 【音乐拼接】mp3格式
- 新手mp3播放器心得(一)---- 获取所有歌曲(遍历文件获取、媒体库获取)
- ios封装生成合成.a文件
- ios和安卓上传MP3文件
- 做几个leetcode数组题二
- uva 11542 Square(数学:高斯消元)
- Ubuntu终端安装JDK.bin提示权限不够
- UINavigationController--导航控制器(UINavigationBar、UIToolBar)
- 很有意思的一篇文章——写小论文论(转自吴志峰教授的blog_写不出论文的几种人)
- IOS拼接MP3,歌曲文件合成。
- 只需手动增加一行代码即可让Laravel4运行在SAE
- 【Cocos2d-x】集成wxSqlite3到Cocos2d-x
- CodeForces 484B Maximum Value
- Map 详细用法
- 全选 函数
- Android源码--创建系统service
- 如何给history命令记录加上时间戳
- index leaf/branch block说明