iphone calls both if and else at the same time?
- by David Schiefer
Hi,
I need to determine what file type a file is and then perform a certain action for it. this seems to work fine for some types, however all media types such as videos and sound files get mixed up. I determine the file type by doing this:
BOOL matchedMP3 = ([[rowValue pathExtension] isEqualToString:@"mp3"]);
if (matchedMP3 == YES)
{
NSLog(@"Matched MP3");
}
I do this for various file types and just define an "else" for all the others. Here's the problem though. The iPhone calls them both. Here's what the log reveals:
2010-05-11 18:51:12.421 Test [5113:207] Matched MP3
2010-05-11 18:51:12.449 Test [5113:207] Matched ELSE
I've never seen anything like this before.
This is my "matchedMP3" function:
BOOL matchedMP3 = ([[rowValue pathExtension] isEqualToString:@"mp3"]);
if (matchedMP3 == YES)
{
NSLog(@"Matched MP3");
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSFileManager *manager = [NSFileManager defaultManager];
self.directoryContent = [manager directoryContentsAtPath:documentsDirectory];
NSString *errorMessage = [documentsDirectory stringByAppendingString:@"/"];
NSString *urlAddress = [errorMessage stringByAppendingString:rowValue];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:urlAddress]];
moviePlayer.movieControlMode = MPMovieControlModeDefault;
moviePlayer.backgroundColor = [UIColor blackColor];
[moviePlayer play];
}
and here's the else statement:
else {
NSLog(@"Matched ELSE");
[[NSUserDefaults standardUserDefaults] setObject:rowValue forKey:@"rowValue"];
NSString*rowValue = [[NSUserDefaults standardUserDefaults] objectForKey:@"rowValue"];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSFileManager *manager = [NSFileManager defaultManager];
self.directoryContent = [manager directoryContentsAtPath:documentsDirectory];
NSString *errorMessage = [documentsDirectory stringByAppendingString:@"/"];
NSString *urlAddress = [errorMessage stringByAppendingString:rowValue];
webViewHeader.prompt = rowValue;
[documentViewer setDelegate:self];
NSString *encodedString = [urlAddress stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//Create a URL object.
NSURL *url = [NSURL URLWithString:encodedString];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[documentViewer loadRequest:requestObj];
[navigationController pushViewController:webView animated:YES];
}
I can't see a reason why it wouldn't work. What happens is that both the webview and the MediaPlayer toggle their own player, so they overlap and play their sound/video a few secs apart from each other.
Any help would be appreciated & thank for you taking the time to read through my code.