Best way for looping and using background sounds in iphone?

大憨熊 提交于 2019-12-11 15:08:07

问题


Lets say I am dragging my finger on screen and I have 1 second .caf sound file in my bundle.

So what is the best way to play my sound file in a loop till i am dragging my fingers. And it should stop whenever I remove touches.

I know touches implementation. Just post your views about using sound file.


回答1:


See AVAudioPlayer class, it worked pretty well for me for similar behaviour described in your question.




回答2:


This is how I did it. At the moment, I don't know of a more efficient method...but here's what I used to loop my background sound. Hope this helps.

NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/yourAudio.caf", [[NSBundle mainBundle] resourcePath]]];

audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:NULL];
audioPlayer.numberOfLoops = -1;
[audioPlayer play];


来源:https://stackoverflow.com/questions/6594900/best-way-for-looping-and-using-background-sounds-in-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!