有什么办法可以停止在这里播放音频吗?像玩/停那种东西?
-(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/