【问题标题】:Stop AVPlayer music in another controller在另一个控制器中停止 AVPlayer 音乐
【发布时间】:2010-09-18 12:46:46
【问题描述】:

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

AVAudioPlayer *introSound;

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

[introSound stop];

我想做的是从一个单独的控制器 firstController.m 中阻止它。

我试过了

[AppDelegate.introSound stop];

但它抛出了一个错误说:

错误:在 '.' 之前应为 ':'令牌

这是什么原因造成的?

【问题讨论】:

    标签: ios avfoundation avplayer


    【解决方案1】:

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

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

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

    【讨论】:

    • 谢谢!这成功了。虽然我将其添加为: AppDelegateappDelegate = (AppDelegate) [[UIApplication sharedApplication] delegate];非常感谢!
    【解决方案2】:

    用这种方式捕捉视频/音频,简单又好用。这样做

    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];
    }
    

    【讨论】:

    • 再一次,您的回答不能解决 OP 遇到的问题。请在回答之前正确阅读问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多