Last active
January 3, 2016 00:39
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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