ios - 在iPhone应用程序中播放/暂停声音

标签 ios audio

有什么办法可以停止在这里播放音频吗?像玩/停那种东西?

 -(IBAction)PlaySound:(id)sender{

audioTitle = [NSString stringWithFormat:@"Audio %@", audioInteger];
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundfileURLREF;
soundfileURLREF = CFBundleCopyResourceURL(mainBundle, (CFStringRef) audioTitle, CFSTR ("mp3"), NULL);
UInt32 SoundID;
AudioServicesCreateSystemSoundID(soundfileURLREF, &SoundID);
AudioServicesPlaySystemSound(SoundID);

}

最佳答案

这是使用AVAudioPlayer类的简单播放/暂停/停止示例。

在viewDidLoad中创建播放:

var audioPath = NSBundle.mainBundle().pathForResource("bach1", ofType: "mp3")

    var error : NSError? = nil

    player = AVAudioPlayer(contentsOfURL: NSURL(string: audioPath!), error: &error)

内部播放按钮:
player.play()

内部暂停按钮:
player.pause()

内部停止按钮:
player.stop()
player.currentTime = 0;

关于ios - 在iPhone应用程序中播放/暂停声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29802133/

相关文章:

ios - 在 objective-c 中创建用于实时音视频广播的rtsp客户端

android - 在android中,如何提高麦克风的输入以进行录音?

php - sox的音频水印在php中不起作用

java - 我需要有关为何为什么要获得NPE以及如何在播放时停止剪辑的帮助

iOS 仅将一项服务宣传为外设 BTLE

ios - 将数据从 UIViewController 传递到 AppDelegate

ios - 如何通过按下按钮调用电话 - XCode

ios - CoreData 中的 NSData 未正确保存

android - 实时输出转换后的麦克风输入?

audio - 如何在Weka中使用MFCC进行音频分类?