【问题标题】:Stop sound in iPhone在 iPhone 中停止声音
【发布时间】:2018-08-17 19:35:13
【问题描述】:
SystemSoundID soundID;
NSString *path = [[NSBundle mainBundle] pathForResource:@"static" ofType:@"caf"]; 
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path], &soundID);
AudioServicesPlaySystemSound(soundID);

我已经在我的应用程序中实现了上述代码。

效果很好,但问题是我不知道如何阻止它。

即声音为 10 秒。

10 秒前。如果用户点击按钮,声音应该停止?我该怎么做?

【问题讨论】:

    标签: iphone xcode audio


    【解决方案1】:

    试试 AudioServicesDisposeSystemSoundID,它会立即停止声音。如果您打算再次使用它,则需要重新创建声音。

    【讨论】:

      【解决方案2】:

      使用以下指令处置系统声音对象和相关资源:

      AudioServicesDisposeSystemSoundID(soundID);
      

      【讨论】:

        【解决方案3】:

        我建议使用 AVFoundation 框架。 Here 是一个关于如何使用 AVAudioPlayer 播放、暂停和停止声音的精彩教程。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2012-07-14
          • 2014-04-21
          • 1970-01-01
          • 1970-01-01
          • 2010-12-17
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多