gpt4 book ai didi

IOS:当我返回 View 时停止音频

转载 作者:行者123 更新时间:2023-12-03 02:23:54 25 4
gpt4 key购买 nike

当我从一个 View 退出时,我开始播放 clang ,当我返回这个 View 时,我想停止这个 clang (wma)

当我退出 IbAction 时,我有以下代码:

NSString *path = [NSString stringWithFormat:@"%@/%@",
[[NSBundle mainBundle] resourcePath],
@"file.wav"];

NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];

AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID);
AudioServicesPlaySystemSound(soundID);

但是当我返回 View 时,我尝试在 viewWillAppear 中写入
AudioServicesRemoveSystemSoundCompletion(soundID);
AudioServicesDisposeSystemSoundID(soundID);

但它不起作用,你能帮帮我吗?

最佳答案

viewWillAppear:在某些情况下不会调用。您可以使用通知中心 ([NSNotificationCenter defaultCenter]) 或委托(delegate)让您现在查看何时停止音乐。
有一些方法,如 postNotification:addObserver: ,检查它们。

关于IOS:当我返回 View 时停止音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7901482/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com