IOS:当我返回视图时停止音频
当我从视图中退出时,我会启动一首顺口溜,当我返回此视图时,我想停止此顺口溜(wma),
当我在 IbAction 中退出时,我有以下代码:
NSString *path = [NSString stringWithFormat:@"%@/%@",
[[NSBundle mainBundle] resourcePath],
@"file.wav"];
NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID);
AudioServicesPlaySystemSound(soundID);
但是当我返回视图时,我尝试在 viewWillAppear 中写入,
AudioServicesRemoveSystemSoundCompletion(soundID);
AudioServicesDisposeSystemSoundID(soundID);
但是它不起作用,你能帮我吗?
When I exit from a view I start a jingle and when i return in this view I want to stop this jingle (wma)
when I exit in IbAction I have this code:
NSString *path = [NSString stringWithFormat:@"%@/%@",
[[NSBundle mainBundle] resourcePath],
@"file.wav"];
NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID);
AudioServicesPlaySystemSound(soundID);
but when I return in the view I try to write in viewWillAppear
AudioServicesRemoveSystemSoundCompletion(soundID);
AudioServicesDisposeSystemSoundID(soundID);
but it don't work, can you help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
viewWillAppear:
在某些情况下不会被调用。您可以使用通知中心([NSNotificationCenter defaultCenter]
)或委托让您立即查看何时停止音乐。有一些方法,例如
postNotification:
和addObserver:
,检查它们。viewWillAppear:
not will be called in some cases. You can use notification center ([NSNotificationCenter defaultCenter]
) or delegate to let your view now when to stop music.There are some methods like
postNotification:
andaddObserver:
, check them.