2015-04-22 89 views
0

有什么方法可以停止播放音频吗?就像一个玩/停止类的东西?在iPhone应用程序中播放/暂停声音

-(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); 

} 
+2

[停止声音在iPhone]可能的重复(http://stackoverflow.com/questions/1512121/stop-sound-in-iphone) – Wez

+0

第一步:停止使用AudioServicesPlaySystemSound并让自己成为一个真正的声音播放器(即AVAudioPlayer)。 – matt

回答

0

这是一个简单的播放/暂停/停止使用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; 
+0

@ BenHeyderman是否帮助你,还是你需要更多的澄清? – studev18

相关问题