【问题标题】:Play sound with back button storyboard. Objective C使用后退按钮故事板播放声音。目标 C
【发布时间】:2013-05-22 16:17:43
【问题描述】:

在 Xcode 的 Storyboard 模式下。当您使用导航控制器时,后退按钮会自动出现。

通常要播放我的声音,我会从选择器或操作中调用我的任务。

如何使用返回按钮播放此声音?由于后退按钮会自动出现在我的视图中,我该如何编写代码?

- (void)myTask {
NSString* resourcePath = [[NSBundle mainBundle] resourcePath];
resourcePath = [resourcePath stringByAppendingString:@"/pop.wav"];
NSLog(@"Path to play: %@", resourcePath);
NSError* err;

//Initialize our player pointing to the path to our resource
player = [[AVAudioPlayer alloc] initWithContentsOfURL:
          [NSURL fileURLWithPath:resourcePath] error:&err];

if( err ){
    //bail!
    NSLog(@"Failed with reason: %@", [err localizedDescription]);
}
else{
    //set our delegate and begin playback
    player.delegate = self;
    [player play];
}
}

问候

布莱克

【问题讨论】:

    标签: objective-c audio uinavigationcontroller avaudioplayer


    【解决方案1】:

    你可以在- (void)viewWillDisappear:(BOOL)animated { // in here }玩它

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-16
      • 1970-01-01
      相关资源
      最近更新 更多