欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

iPhone 播放音頻聲音文件

系統(tǒng) 2483 0

播放音頻聲音文件

?

iphone開發(fā)中播放聲音文件主要使用AVAudioPlayer 類,它的功能非常強大支持播放音頻的格式也非常的多,我們可以把它看成一個高級的音樂播放器,它支持的播放格式有

■ AAC

■ AMR(AdaptiveMulti-Rate, aformatforspeech)

■ ALAC(AppleLossless)

■ iLBC(internetLowBitrateCodec, anotherformatforspeech)

■ IMA4(IMA/ADPCM)

■ linearPCM(uncompressed)

■ μ-lawanda-law

■ MP3(MPEG-1audiolayer3

今天主要介紹一下播放mp3 .

?

AVAudioPlayer 是 AVFoundation.framework 中定義的一個類,所以使用要先在工程中引入AVFoundation.framework 如圖所示點擊”+”號將AVFoundation導入。

?

將音頻文件放入資源文件夾中

下面我開始介紹代碼中如何調用AVAudioPlayer 播放音頻文件

?

聲明類

      //
//  playSoundViewController.h
//  playSound
//
//  Created by  宣雨松 on 11-7-10.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//
 
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
@interface playSoundViewController : UIViewController {
 
 IBOutlet UIButton * playSound;//播放音樂  
 IBOutlet UIButton * playPause;//播放暫停  
 IBOutlet UIButton * playStop;//播放停止  
 //定義一個聲音的播放器
 AVAudioPlayer *player;
}
 
-(IBAction)playSoundPressed:(id)pressed;
-(IBAction)playPausePressed:(id)pressed;
-(IBAction)playStopPressed:(id)pressed;
@end
    

?

實現(xiàn)類

      //
//  playSoundViewController.m
//  playSound
//
//  Created by  宣雨松 on 11-7-10.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//
 
#import "playSoundViewController.h"
 
@implementation playSoundViewController
 
- (void)dealloc
{
 [super dealloc];
 //程序的嚴謹性 在顯示對象關閉后把相應的對象清空
 //時刻謹記
 [playSound release];
 [player release];
}
 
- (void)didReceiveMemoryWarning
{
 // Releases the view if it doesn't have a superview.
 [super didReceiveMemoryWarning];
 
 // Release any cached data, images, etc that aren't in use.
}
 
#pragma mark - View lifecycle
 
 
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
 [super viewDidLoad];
 //在這里實現(xiàn)聲音的播放代碼
 //找到mp3在資源庫中的路徑 文件名稱為sound 類型為mp3
 NSString *path = [[NSBundle mainBundle] pathForResource:@"sound" ofType:@"mp3"];
 //在這里判斷以下是否能找到這個音樂文件
 if (path) {
 //從path路徑中 加載播放器
 player = [[AVAudioPlayer alloc]initWithContentsOfURL:[[NSURL alloc]initFileURLWithPath:path]error:nil];
 //初始化播放器
 [player prepareToPlay];
 
 //設置播放循環(huán)次數(shù),如果numberOfLoops為負數(shù) 音頻文件就會一直循環(huán)播放下去
 player.numberOfLoops = -1;
 
 //設置音頻音量 volume的取值范圍在 0.0為最小 0.1為最大 可以根據(jù)自己的情況而設置
 player.volume = 0.5f;
 
 NSLog(@"播放加載");
 }
 
}
 
-(void)playSoundPressed:(id)pressed
{
 //點擊按鈕后開始播放音樂
 //當player有值的情況下并且沒有在播放中 開始播放音樂
 if (player) 
 {
 if (![player isPlaying]) 
 {
 [player play];
 NSLog(@"播放開始");
 }
 }
}
 
-(void)playPausePressed:(id)pressed
{
 //暫停播放聲音
 if (player) {
 if ([player isPlaying]) {
 [player pause];
 NSLog(@"播放暫停");
 }
 }
}
 
-(void)playStopPressed:(id)pressed
{
 //停止播放聲音
 if (player) {
 if ([player isPlaying]) {
 [player stop];
 NSLog(@"播放停止");
 }
 }
}
 
 
- (void)viewDidUnload
{
 [super viewDidUnload];
 // Release any retained subviews of the main view.
 // e.g. self.myOutlet = nil;
}
 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
 // Return YES for supported orientations
 return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
 
@end
    

?

原文鏈接: http://blog.csdn.net/xys289187120/article/details/6595919

?

iPhone 播放音頻聲音文件


更多文章、技術交流、商務合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 国产在线精品一区 | caoporn视频| 人妻熟女久久久久久久 | 国产成人精品高清在线观看99 | 欧美大片一区二区三区 | 色综合精品久久久久久久 | 亚洲视频黄色 | 高清中文字幕免费观在线 | 三级精品在线观看 | 中文字幕日本视频 | 亚洲一区二区三区高清网 | 成人免费毛片aaaaaa片 | 精品久久久久久久久久 | 欧洲免费无线码二区5 | 亚洲欧美综合人成野草 | 成人精品视频一区二区三区尤物 | 国产在线一区二区 | www.天天操| 碰碰碰人人澡人人爱摸 | 日本粉嫩一区二区三区视频 | 国产综合亚洲精品一区二 | 国产精品岛国久久久久久 | 九九国产 | 午夜视频久久 | 免费看一级欧美毛片视频 | 国产午夜精品一区二区三区嫩草 | 亚洲va国产va | 亚洲国产区 | 日本欧美国产 | 五月综合激情在线 | 久久夜色精品国产亚洲噜噜 | 亚洲精品小视频 | 成人在线网 | 一级片网 | 久久久久久久久久免观看 | 欧美日韩一区二区三在线 | 亚洲第一区第二区 | 成人网18视频网站 | 一级做a爰性色毛片免费 | 日韩一级大片 | 中文字幕日韩在线 |