开发者

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 fro开发者_JAVA百科m 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];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜