música parada AVPlayer en otro controlador
-
03-10-2019 - |
Pregunta
así que tengo esta variable en mi delegado nombrado AppDelegate.h:
AVAudioPlayer *introSound;
Se reproduce continuamente durante la primera carga.
[introSound stop];
Lo que quiero hacer es evitar que un controlador separado, firstController.m.
He intentado
[AppDelegate.introSound stop];
pero arrojó un error que dice:
Error: Se esperaba ':' antes ''. contador
¿Qué está causando esto?
Solución
supongo que quiere decir un error de compilación? AppDelegate refiere a la clase, no a la instancia de la clase que es su delegado aplicación. Para conseguir que desde cualquier lugar, haga lo siguiente:
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
[appDelegate.introSound stop];
También es necesario asegurarse de que introSound es una propiedad, no sólo una variable de instancia de AppDelegate.
Otros consejos
utilizar esta forma de captura vídeos / audios en esta sencilla y best.do
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];
}