iOS的8:AudioServicesPlaySystemSound不播放声音时AudioServicesDisposeSystemSoundID是后来被称为 [英] iOS 8: AudioServicesPlaySystemSound is not playing Sound when AudioServicesDisposeSystemSoundID is called afterwards

查看:1881
本文介绍了iOS的8:AudioServicesPlaySystemSound不播放声音时AudioServicesDisposeSystemSoundID是后来被称为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当调用 AudioServicesPlaySystemSound ,它起着创造良好的SystemSound previous。但是,当我打电话的 AudioServicesDisposeSystemSoundID 直接算账,声音不播放。看来,因为它会被玩过前作的声音 - 资源配置。

但在此#1,问的人说,这是必要的处置系统 - 健全以避免内存泄漏。

如何为这两种方法的正确方法是什么?要我调用Dispose法具有定时一些秒钟后?或创建创造的声音,一旦资源在播放方法的第一次调用独立的,并在单例的dealloc配置资源?

   - (无效){playSound
    NSURL * URL = [[一个NSBundle mainBundle] URLForResource:@SentMessage
                                           withExtension:@WAV];    SystemSoundID mBeep;
    AudioServicesCreateSystemSoundID((__桥CFURLRef)的网址,和放大器; mBeep);    AudioServicesPlaySystemSound(mBeep);
    AudioServicesDisposeSystemSoundID(mBeep);
}


解决方案

您可以使用 AudioServicesAddSystemSoundCompletion 来注册一个回调时,你的声音播放完被调用。你可以处置系统的声音在那里。

或者在你的类的的dealloc

When calling AudioServicesPlaySystemSound, it plays well the previous created SystemSound. But when i call AudioServicesDisposeSystemSoundID directly afterwards, the sound is not played. It seems as the Sound-Resource is disposed before it would have been played.

But on this Stackoverflow-Question the people say, that it is necessary to dispose the System-Sound to avoid memory leaks.

How is the correct way for both methods? Shall i call the Dispose-Method with a timer some seconds later? Or create a singleton which creates the Sound-Resource once at the first call of the Play-Method and dispose the Resource at dealloc of the singleton?

- (void) playSound {
    NSURL *url   = [[NSBundle mainBundle] URLForResource: @"SentMessage"
                                           withExtension: @"wav"];

    SystemSoundID mBeep;
    AudioServicesCreateSystemSoundID((__bridge CFURLRef)url,  &mBeep );

    AudioServicesPlaySystemSound(mBeep);
    AudioServicesDisposeSystemSoundID(mBeep);  
}

解决方案

You can use AudioServicesAddSystemSoundCompletion to register a callback to be called when your sound finishes playing. You could dispose of the system sound there.

Or in your class's dealloc.

这篇关于iOS的8:AudioServicesPlaySystemSound不播放声音时AudioServicesDisposeSystemSoundID是后来被称为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆