开发者

(iPhone) Can I do AudioServicesPlaySystemSound Looping with scheduler?

开发者 https://www.devze.com 2022-12-17 07:17 出处:网络
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 schedule

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号