(iPhone) Can I do AudioServicesPlaySystemSound Looping with scheduler?
Can I do AudioServicesPlaySystemSound Looping with scheduler? One problem is I cannot get开发者_运维技巧 the sound duration. Is there any way to get the duration so I can dynamically create a scheduler that loops the sound? As far as I know AudioService does not have built-in looping and other necessry functions, and that's really a pain.
The audio session is different from the thing playing audio. The session manages mixer levels and the basic routing to different things like headphones and speakers and what-not. To loop things is a property of the player.
If you don't need the low-level audio stuff, you might be able to get by with MPMusicPlayerController which has a repeatMode
property you can take advantage of.
Alternatively, there is also the AVAudioPlayer which you can listen for delegate messages and start the playback once it stops to simulate looping yourself.
You don't need to use AVAudioPlayer for this, because you can register callbacks with AudioServices, too.
See the answer in How to vibrate continuously; just replace the vibrate SystemSoundID with your own sound.
精彩评论