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

时间:2010-09-18 12:46:47

标签: ios avfoundation avplayer

所以我在我的委托AppDelegate.h中有这个变量:

AVAudioPlayer *introSound;

在首次加载时它会连续播放。

[introSound stop];

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

我试过

[AppDelegate.introSound stop];

但它提出错误说:

  

错误:预期':'之前'。'令牌

造成这种情况的原因是什么?

2 个答案:

答案 0 :(得分:2)

我认为你的意思是编译错误? AppDelegate引用类,而不是作为应用程序委托的类的实例。要从任何地方获得,请执行以下操作:

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

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

答案 1 :(得分:1)

使用这种方式捕捉视频/音频简单和最好。这个

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];
}
相关问题