Skip to content

Instantly share code, notes, and snippets.

@JulesMoorhouse
Last active January 3, 2016 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JulesMoorhouse/8384223 to your computer and use it in GitHub Desktop.
Save JulesMoorhouse/8384223 to your computer and use it in GitHub Desktop.
iOS mp3 duration to plist, the plist can then be manually copied to the plist.
NSString *plistFilename = [[NSBundle mainBundle] pathForResource:@"voice_list" ofType:@"plist"];
NSMutableDictionary *plist = [[NSMutableDictionary alloc] initWithContentsOfFile:plistFilename];
for (NSInteger xt = 1; xt < 13; ++xt) {
for (NSInteger row = 1; row < 13; ++row) {
NSString *sum = [NSString stringWithFormat:@"mel%ldx%lde%d", (long)row, (long)xt, (row * xt)];
NSMutableDictionary *sumDict = [plist objectForKey:sum];
AVURLAsset* audioAsset = [AVURLAsset URLAssetWithURL:[[NSBundle mainBundle] URLForResource:sum withExtension:@"mp3"] options:nil];
CMTime audioDuration = audioAsset.duration;
float audioDurationSeconds = CMTimeGetSeconds(audioDuration);
if (audioDurationSeconds > 0) {
[sumDict setValue:[NSNumber numberWithFloat:audioDurationSeconds] forKey:@"to_all"];
[sumDict setValue:[NSNumber numberWithFloat:audioDurationSeconds] forKey:@"to_eq"];
}
}
}
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *docsDir = documentPaths[0];
NSString *filePathInDocsDir = [docsDir stringByAppendingPathComponent:@"voice_list.plist"];
if ([plist writeToFile:filePathInDocsDir atomically:YES]) {
NSLog(@"Successfully finished writing to file");
} else {
NSLog(@"failed to write");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment