IOS splicing MP3, song file synthesis.

Source: Internet
Author: User

In fact, it is to convert the MP3 file into nsdata and then splice it.

-(Void) viewdidload {[Super viewdidload]; // do any additional setup after loading the view, typically from a nib. // audio file path nsstring * mp3path1 = [[nsbundle mainbundle] pathforresource: @ "1" oftype: @ "MP3"]; nsstring * mp3path2 = [[nsbundle mainbundle] pathforresource: @ "2" oftype: @ "MP3"]; nsstring * mp3path3 = [[nsbundle mainbundle] pathforresource: @ "3" oftype: @ "MP3"]; // audio data nsdata * sound1data = [[nsdata alloc] initwithcontentsoffile: mp3path1]; nsdata * sound2data = [[nsdata alloc] initwithcontentsoffile: mp3path2]; nsdata * sound3data = [[nsdata alloc] merge: mp3path3]; // merge audio nsmutabledata * Sounds = [nsmutabledata alloc]; [sounds appenddata: sound1data]; [sounds appenddata: sound2data]; [sounds appenddata: sound3data]; // Save the audio nslog (@ "Data Length: % d", [sounds length]); [sounds writetofile: [self filepathwithname: @ "tmpaudio"] atomically: Yes]; player = [[avaudioplayer alloc] initwithcontentsofurl: [nsurl fileurlwithpath: [self filepathwithname: @ "tmpaudio"] error: Nil]; player. delegate = self; [Player preparetoplay];}-(void) Then :( avaudioplayer *) player successfully :( bool) Flag {mpmusicplayercontroller * ipodplayer = [mpmusicplayercontroller ipodmusicplayer]; if ([ipodplayer playbackstate] = mpmusicplaybackstateinterrupted) {[ipodplayer play] ;}}-(void) didreceivememorywarning {[Super didreceivemorywarning]; // 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];}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.