简体   繁体   中英

Stop AVPlayer music in another controller

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];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM