Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5960387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:49:11+00:00 2026-05-22T18:49:11+00:00

I am developing a video recording application and I would like to be able

  • 0

I am developing a video recording application and I would like to be able to integrate a music file selected by the user from the iPod library. Please share your inputs as to how I can achieve this requirement. Sample code is helpful.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:49:12+00:00Added an answer on May 22, 2026 at 6:49 pm

    Finally succeeded Integrate a selected music file into video

    Using AVAssetExportSession we can merge Video and audio together using AVMutableComposition.

    Thanks for update all of you!!

    //This method merges the audio and video.

    - (void)mergeAudioAtUrl:(NSURL *)audioUrl withVideoAtUrl:(NSURL *)videoUrl toUrl:(NSURL *)outputUrl
      {
    
    //_imageCaptureCount = [_imagesArray count]*100;
    
    AVURLAsset* audioAsset = [[AVURLAsset alloc]initWithURL:audioUrl options:nil];
    AVURLAsset* videoAsset = [[AVURLAsset alloc]initWithURL:videoUrl options:nil];
    
    AVMutableComposition* mixComposition = [AVMutableComposition composition];
    
    
    if([[audioAsset tracksWithMediaType:AVMediaTypeAudio] count])
    {
        AVMutableCompositionTrack *compositionCommentaryTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio 
                                                                                            preferredTrackID:kCMPersistentTrackID_Invalid];
    
        [compositionCommentaryTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, videoAsset.duration) 
                                            ofTrack:[[audioAsset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0] 
                                             atTime:kCMTimeZero error:nil];
    }
    AVMutableCompositionTrack *compositionVideoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo 
                                                                                   preferredTrackID:kCMPersistentTrackID_Invalid];
    [compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, videoAsset.duration) 
                                   ofTrack:[[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] 
                                    atTime:kCMTimeZero error:nil];
    
    [audioAsset release];
    [videoAsset release];
    
    AVAssetExportSession* _assetExport = [[AVAssetExportSession alloc] initWithAsset:mixComposition 
                                                                          presetName:AVAssetExportPresetPassthrough];   
    
    NSURL    *exportUrl = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/Documents/%@Video.mp4", NSHomeDirectory(),pcNameString]];
    
    if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/Documents/%@Video.mp4", NSHomeDirectory(),pcNameString]]) 
    {
        [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/Documents/%@Video.mp4", NSHomeDirectory(),pcNameString] error:nil];
    }
    
    _assetExport.outputFileType = @"com.apple.quicktime-movie"; //com.apple.m4v-video
    _assetExport.outputURL = exportUrl;
    _assetExport.shouldOptimizeForNetworkUse = YES;
    
    [_assetExport exportAsynchronouslyWithCompletionHandler:
     ^(void ) {      
         // your completion code here
        // NSLog(@"completed");
    
         removeProgresBarFlag = YES;
    
    
        /* NSString* savedVideoFilePath = [NSString stringWithFormat:@"%@/Documents/PC%d.mp4", NSHomeDirectory(),[videosListArray count]];
    
         if(UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(savedVideoFilePath))
         {
             [[UIApplication sharedApplication]beginIgnoringInteractionEvents];
             UISaveVideoAtPathToSavedPhotosAlbum(savedVideoFilePath, self, nil, nil);
             [[UIApplication sharedApplication]endIgnoringInteractionEvents];
    
         } */
    
    
         NSMutableDictionary* videoDetailDict = [[NSMutableDictionary alloc] initWithCapacity:0];
    
         NSStringEncoding encoding;
         NSError* error;
    
         NSString * persistentID;
         NSFileManager* fileManager = [NSFileManager defaultManager];
    
         if([fileManager fileExistsAtPath:PRESENTSONGS_FILE_PATH])
             persistentID = [NSString stringWithContentsOfFile:PRESENTSONGS_FILE_PATH usedEncoding:&encoding error:&error];
         else 
             persistentID = @"";
    
         [videoDetailDict setObject:persistentID forKey:KSong];
    
         if([fileManager fileExistsAtPath:PRESENTIMAGES_FILE])
         {
    
             NSMutableArray* currentImagesArray = [[NSMutableArray alloc] initWithContentsOfFile:IMAGESDATA_FILE_PATH];
             NSMutableArray* durationArray = [[NSMutableArray alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/videoduration.plist", [[NSBundle mainBundle] resourcePath]]];
             [videoDetailDict setObject:[durationArray objectAtIndex:[currentImagesArray count]-1] forKey:KfileSize];
             [durationArray release];
    
    
             [videoDetailDict setObject:currentImagesArray forKey:KImagesList];
             if([fileManager fileExistsAtPath:TEMPVIDEO_FILE_PATH])
             [fileManager removeItemAtPath:TEMPVIDEO_FILE_PATH error:nil];
    
             NSString* mainPath;
    
                 mainPath = [NSString stringWithFormat:@"%@/Documents/%@File",NSHomeDirectory(),pcNameString];
    
             if([fileManager fileExistsAtPath:mainPath])
                 [fileManager removeItemAtPath:mainPath error:nil];
    
             [fileManager createDirectoryAtPath:mainPath withIntermediateDirectories:NO attributes:nil error:nil];
    
    
             for(int i=0;i<[currentImagesArray count];i++)
             {
                 [fileManager copyItemAtPath:[NSString stringWithFormat:@"%@%@",PRESENTIMAGES_FILE,[currentImagesArray objectAtIndex:i]] toPath:[NSString stringWithFormat:@"%@/%@",mainPath,[currentImagesArray objectAtIndex:i]] error:nil];
             }
             [currentImagesArray release];
    
         }
    
         if([fileManager fileExistsAtPath:KMESSAGE_FILEPATH])
         {
             NSMutableDictionary* currentMessageDictioanry = [[NSMutableDictionary alloc] initWithContentsOfFile:KMESSAGE_FILEPATH];
             [videoDetailDict setObject:currentMessageDictioanry forKey:Kmessage];
             [currentMessageDictioanry release];
         }
    
         [videoDetailDict setObject:pcNameString forKey:KPostCardName]; //[NSString stringWithFormat:@"PostCard Video%d",[videosListArray count]]
         //[videosListArray insertObject:videoDetailDict atIndex:0];
         [videosListArray addObject:videoDetailDict];
         [videoDetailDict release];
         [videosListArray writeToFile:VIDEOS_FILE_PATH atomically:YES];
    
     }       
     ];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing an application for video capture and I would like to implement
I am developing an application for video recording and I want to overlay the
I am developing an application which uses both video recording and photo shoting.So i
i am developing an application which requires recording a video in the background while
I am developing a mac application that involves audio playback. I would like to
I am developing an application. In that my requirement is access the video from
i am developing a video player i silverlight i wanna something to prevent recording
I am developing a piece of software that records video from a live source
i am developing an application in which i am trying to record a video
I am developing a small flash application. In my application a user can draw

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.