开发者

Best way for looping and using background sounds in iphone?

开发者 https://www.devze.com 2023-03-18 03:48 出处:网络
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 i开发者_开发知识

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 i开发者_开发知识库t should stop whenever I remove touches.

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


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


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];
0

精彩评论

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