Остановить музыку AVPlayer в другом контроллере

StackOverflow https://stackoverflow.com/questions/3741740

  •  03-10-2019
  •  | 
  •  

Вопрос

Поэтому у меня есть эта переменная в моем делегате имени appdelegate.h:

AVAudioPlayer *introSound;

Он непрерывно играет во время первой нагрузки.

[introSound stop];

То, что я хочу сделать, это остановить его от отдельного контроллера, firstcontroller.m.

Я старался

[AppDelegate.introSound stop];

Но он бросил ошибку:

Ошибка: Ожидается «:« раньше ». токен

Чем это вызвано?

Это было полезно?

Решение

Я предполагаю, что вы имеете в виду ошибку компилятора? AppDelegate относится к классу, а не к экземпляру класса, который является вашим делегатом приложения. Чтобы получить это из любого места, сделайте это:

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

Вам также необходимо убедиться, что InnoSound - это свойство, а не просто переменная экземпляра 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 с атрибуция
Не связан с StackOverflow
scroll top