使用AVAudioPlayer播放音乐文件
by Elton on 十二.07, 2009, under iPhone
AVAudioPlayer 提供了大量的特性,包括暂停播放,调整音量,监控音频的峰值和均值等等。 我们看下面的例子:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | AVAudioPlayer *player; NSString *path; // 设置音乐文件路径 path = [[NSBundle mainBundle] pathForResource:@"sound-file" ofType:@"mp3"]; // 判断是否可以访问这个文件 if ([[NSFileManager defaultManager] fileExistsAtPath:path]) { // 设置 player player = [[AVAudioPlayer alloc] initWithContentsOfURL: [NSURL fileURLWithPath:path] error:&error]; // 调节音量 (范围从0到1) player.volume = 0.4f; // 准备buffer,减少播放延时的时间 [player prepareToPlay]; // 设置播放次数,0为播放一次,负数为循环播放 [player setNumberOfLoops:0]; [player play]; } ... // 清理工作 if (player != nil) { if (player.isPlaying == YES) [player stop]; [player release]; } |



一月 5th, 2010 on 22:12
Lo stesso, indefinitamente
二月 21st, 2010 on 11:16
I just couldnt leave your web site before saying that I really loved the high quality facts you offer to all your visitors. Would be back generally to check up on new stuff in you post!
二月 24th, 2010 on 14:49
Nice site! I adore a couple of of the articles that have been written, and particularly the comments posted! I will definately be visiting again!
三月 8th, 2010 on 00:42
I just couldnt leave your web site prior to saying that I genuinely liked the quality facts you provide to your visitors. Will be back often to check up on new stuff in you article!
四月 10th, 2010 on 15:57
Congratulations for posting such a useful blog. Your blog is not only informative and also extremely artistic too. There normally are very few individuals who can write not so easy articles that creatively. Keep up the good work !!
六月 2nd, 2010 on 02:58
Stumbled across your post while searching through yahoo. I go through the first paragraph and its wonderful! I don’t have time to finish it now, but I have bookmarked your website and will understand the rest tonight. : )
六月 2nd, 2010 on 22:58
Hi, Thanks. I had been experiencing the same problem. Resolved now Regards.
六月 12th, 2010 on 15:50
nice post. thanks.
六月 13th, 2010 on 09:10
My cousin recommended this blog and she was totally right keep up the fantastic work!
六月 20th, 2010 on 20:51
Hi i am new on here, I found this board quite useful & its helped me loads. i will be able to give something back & help other people like its helped me.
六月 21st, 2010 on 01:42
Stumbled across your article while searching through yahoo. I read the 1st paragraph and its fantastic! I don’t have enough time to finish it now, but I have bookmarked your web site and will understand the rest tonight. : )
七月 27th, 2010 on 22:16
Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained!
八月 2nd, 2010 on 12:09
Aw, this was a really quality post. In theory I’d like to write like this too – taking time and real effort to make a good article… but what can I say… I procrastinate alot and never seem to get something done.
八月 5th, 2010 on 08:01
The nice thing about being a celebrity is that if you bore people they think it’s their fault. Henry Kissinger (1923-)
八月 9th, 2010 on 10:51
Excellent post I must say.. Simple but yet interesting and engaging.. Keep up the awesome work!
八月 9th, 2010 on 13:48
Very habitually I go to this webpage. It very greatly is satisfying to me. Thanks the author
八月 10th, 2010 on 13:22
Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with more information? It is extremely helpful for me.
八月 16th, 2010 on 15:19
Excellent post I must say.. Simple but yet interesting and engaging.. Keep up the awesome work!
八月 18th, 2010 on 07:16
The blog was absolutely fantastic! Lots of great information and inspiration, both of which we all need!
八月 19th, 2010 on 15:13
Hey, great website, I have personal experience with skin problems, it is great to see people discussing the best ways to minimise their effects on your life. I’ve just subscribed to your RSS feed. Please keep up posting.
八月 25th, 2010 on 01:29
Where can I get this lovely?
九月 2nd, 2010 on 14:58
Interesting blog, not like the others!
十月 14th, 2010 on 15:08
Awesome, thanks!
三月 14th, 2011 on 00:14
This is amazing! i have added it to my favorites.
九月 13th, 2011 on 03:26
I am really impressed with your writing abilities and also with the structure to your weblog. Is that this a paid subject or did you modify it yourself? Either way keep up the excellent high quality writing, it is rare to peer a nice weblog like this one nowadays..