Question

so I have this variable in my delegate named AppDelegate.h:

AVAudioPlayer *introSound;

It plays continuously during first load.

[introSound stop];

What I want to do is stop it from a separate controller, firstController.m.

I tried

[AppDelegate.introSound stop];

but it threw an error saying:

error: expected ':' before '.' token

What is causing this?

Was it helpful?

Solution

I assume you mean a compiler error? AppDelegate refers to the class, not to the instance of the class that is your application delegate. To get that from anywhere, do this:

AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
[appDelegate.introSound stop];

You also need to make sure that introSound is a property, not just an instance variable of AppDelegate.

OTHER TIPS

use this way catch videos/audios in simple and best.do this

NSMutableURLRequest *request1 = [[[NSMutableURLRequest alloc] init] autorelease];
[request1 setHTTPMethod:@"GET"];
NSError *error;
NSURLResponse *response;

NSString *documentFolderPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSFileManager *fileManager1 = [NSFileManager defaultManager];
NSString *videosFolderPath = [documentFolderPath stringByAppendingPathComponent:@"videos"]; 
//NSString* videosFolderPath = [@"~/Documents/bar.mp3" stringByExpandingTildeInPath];
NSLog(@"video  path:%@",videosFolderPath);
//Check if the videos folder already exists, if not, create it!!!
BOOL isDir;
if (([fileManager1 fileExistsAtPath:videosFolderPath isDirectory:&isDir] && isDir) == FALSE) {
    //[[NSFileManager defaultManager] createDirectoryAtPath:videosFolderPath attributes:nil];
    [fileManager1 createDirectoryAtPath:videosFolderPath withIntermediateDirectories:YES attributes:nil error:nil];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top