문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

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];
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top