繁体   English   中英

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

[英]Stop AVPlayer music in another controller

所以我在名为AppDelegate.h的委托中拥有此变量:

AVAudioPlayer *introSound;

它在第一次加载期间连续播放。

[introSound stop];

我想要做的是从单独的控制器firstController.m停止它。

我试过了

[AppDelegate.introSound stop];

但是它抛出了一个错误,说:

错误:预期在'。'之前。 代币

是什么原因造成的?

我假设您的意思是编译器错误? AppDelegate引用该类,而不是作为您的应用程序委托的类的实例。 要从任何地方获取该信息,请执行以下操作:

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

您还需要确保introSound是一个属性,而不仅仅是AppDelegate的实例变量。

使用这种方式可以轻松,最佳地捕获视频/音频。

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