简体   繁体   English

在另一个控制器中停止AVPlayer音乐

[英]Stop AVPlayer music in another controller

so I have this variable in my delegate named AppDelegate.h: 所以我在名为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. 我想要做的是从单独的控制器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. AppDelegate引用该类,而不是作为您的应用程序委托的类的实例。 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. 您还需要确保introSound是一个属性,而不仅仅是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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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