美文网首页
iOS如何合并mp3格式的文件

iOS如何合并mp3格式的文件

作者: RunningMan_Fly | 来源:发表于2017-12-07 16:56 被阅读31次

    如果使用的AVAssetExportSession只支持合成m4a文件,其他的各种库也都是从caf、pcm合成的

    所以这里使用数据流的形式把MP3文件转成NSData,然后再进行拼合。

    //音频文件路径

    NSString *mp3Path1 = [[NSBundle mainBundle] pathForResource:@"mouse" ofType:@"mp3"];

    NSString *mp3Path2 = [[NSBundle mainBundle] pathForResource:@"large" ofType:@"mp3"];

    NSString *mp3Path3 = [[NSBundle mainBundle] pathForResource:@"strong" 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];

    相关文章

      网友评论

          本文标题:iOS如何合并mp3格式的文件

          本文链接:https://www.haomeiwen.com/subject/wecjixtx.html