[英]Stop sound in iPhone
SystemSoundID soundID;
NSString *path = [[NSBundle mainBundle] pathForResource:@"static" ofType:@"caf"];
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path], &soundID);
AudioServicesPlaySystemSound(soundID);
我在我的應用程序中實現了上面的代碼。
它運作完美,但問題是我不知道如何阻止它。
即聲音是10秒。
10秒之前 如果用戶點擊按鈕,應該停止聲音? 我怎么能這樣做?
嘗試AudioServicesDisposeSystemSoundID,它立即停止聲音。 如果您打算再次使用它,則需要重新創建聲音。
使用以下指令處理系統聲音對象和相關資源:
AudioServicesDisposeSystemSoundID(soundID);
我建議使用AVFoundation框架。 這是一個關於如何使用AVAudioPlayer播放,暫停和停止聲音的精彩教程。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.