-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
To Save Song in Document Directory #50
Comments
I too am interested in this. |
I also want this feature. But it seems not possible? |
i got this work with a little research.here is my code. + (void)p_cacheAVPlayerItem:(AVPlayerItem *)avPlayerItem filePath:(NSString *)filePath {
AVMutableComposition *composition = [AVMutableComposition composition];
CMTimeRange timeRange = CMTimeRangeMake(kCMTimeZero, avPlayerItem.asset.duration);
AVMutableCompositionTrack *compositionAudioTrack = [composition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
[compositionAudioTrack insertTimeRange:timeRange ofTrack:[[avPlayerItem.asset tracksWithMediaType:AVMediaTypeAudio] objectAtIndex:0] atTime:kCMTimeZero error:nil];
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:composition presetName:AVAssetExportPresetAppleM4A];
exportSession.outputFileType = AVFileTypeAppleM4A;
NSURL *outputURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@.m4a", filePath]];
exportSession.outputURL = outputURL;
[exportSession exportAsynchronouslyWithCompletionHandler:^{
switch(exportSession.status){
case AVAssetExportSessionStatusExporting:
NSLog(@"Exporting...");
break;
case AVAssetExportSessionStatusCompleted:
NSLog(@"Export completed, wohooo!!");
break;
case AVAssetExportSessionStatusWaiting:
NSLog(@"Waiting...");
break;
case AVAssetExportSessionStatusFailed:
NSLog(@"Failed with error: %@", exportSession.error);
break;
default:
NSLog(@"dont know what happened.");
break;
}
}];
} |
Huh. If that works, it's a much less roundabout way than how I managed to implement it. |
@iBenjamin great work, been looking for something like that for a long time. I initially used what @JacobSyndeo did, it works but is not pretty. I am seeing one issue though. It seems like the file that is saved is missing some parts, the music skips. Did you get that issue as well? If yes, how did you go about fixing this? If no, any ideas what might be causing this? Once again, great work figuring that out and thanks for your help in advance. |
@iBenjamin Any update on @jaischeema 's issue? |
@kevinlin505 I encountered that issue as well. I worked around it by only caching the file if it exactly matched the byte size of the original on the server. (My server tells this to my app in advance.) |
Hi ,
How to store Cached song in Document Directory.
Thanks,
Shabana
The text was updated successfully, but these errors were encountered: