iOS獲取本地音頻文件(屬性/信息)
本文實(shí)例為大家分享了iOS獲取本地音頻文件的具體代碼,供大家參考,具體內(nèi)容如下
獲取本地音頻文件地址:
NSString *songsDirectory=MUSIC_FILE_ALL;//沙盒地址 NSBundle *songBundle=[NSBundle bundleWithPath:songsDirectory]; NSString *bundlePath=[songBundle resourcePath]; NSArray *arrMp3=[NSBundle pathsForResourcesOfType:@"mp3" inDirectory:bundlePath]; for (NSString *filePath in arrMp3) { [self.wMp3URL addObject:filePath]; }
解析音頻文件屬性:
-(void)mDefineUpControl{ NSString *filePath = [self.wMp3URL objectAtIndex: 0 ];//隨便取一個(gè),說(shuō)明 //文件管理,取得文件屬性 NSFileManager *fm = [NSFileManager defaultManager]; NSDictionary *dictAtt = [fm attributesOfItemAtPath:filePath error:nil]; //取得音頻數(shù)據(jù) NSURL *fileURL=[NSURL fileURLWithPath:filePath]; AVURLAsset *mp3Asset=[AVURLAsset URLAssetWithURL:fileURL options:nil]; NSString *singer;//歌手 NSString *song;//歌曲名 UIImage *image;//圖片 NSString *albumName;//專(zhuān)輯名 NSString *fileSize;//文件大小 NSString *voiceStyle;//音質(zhì)類(lèi)型 NSString *fileStyle;//文件類(lèi)型 NSString *creatDate;//創(chuàng)建日期 NSString *savePath; //存儲(chǔ)路徑 for (NSString *format in [mp3Asset availableMetadataFormats]) { for (AVMetadataItem *metadataItem in [mp3Asset metadataForFormat:format]) { if([metadataItem.commonKey isEqualToString:@"title"]){ song = (NSString *)metadataItem.value;//歌曲名 }else if ([metadataItem.commonKey isEqualToString:@"artist"]){ singer = (NSString *)metadataItem.value;//歌手 } // 專(zhuān)輯名稱(chēng) else if ([metadataItem.commonKey isEqualToString:@"albumName"]) { albumName = (NSString *)metadataItem.value; }else if ([metadataItem.commonKey isEqualToString:@"artwork"]) { NSDictionary *dict=(NSDictionary *)metadataItem.value; NSData *data=[dict objectForKey:@"data"]; image=[UIImage imageWithData:data];//圖片 } } } savePath = filePath; float tempFlo = [[dictAtt objectForKey:@"NSFileSize"] floatValue]/(1024*1024); fileSize = [NSString stringWithFormat:@"%.2fMB",[[dictAtt objectForKey:@"NSFileSize"] floatValue]/(1024*1024)]; NSString *tempStrr = [NSString stringWithFormat:@"%@", [dictAtt objectForKey:@"NSFileCreationDate"]] ; creatDate = [tempStrr substringToIndex:19]; fileStyle = [filePath substringFromIndex:[filePath length]-3]; if(tempFlo <= 2){ voiceStyle = @"普通"; }else if(tempFlo > 2 && tempFlo <= 5){ voiceStyle = @"良好"; }else if(tempFlo > 5 && tempFlo < 10){ voiceStyle = @"標(biāo)準(zhǔn)"; }else if(tempFlo > 10){ voiceStyle = @"高清"; } NSArray *tempArr = [[NSArray alloc] initWithObjects:@"歌手:",@"歌曲名稱(chēng):",@"專(zhuān)輯名稱(chēng):",@"文件大小:",@"音質(zhì)類(lèi)型:",@"文件格式:",@"創(chuàng)建日期:",@"保存路徑:", nil nil]; NSArray *tempArrInfo = [[NSArray alloc] initWithObjects:singer,song,albumName,fileSize,voiceStyle,fileStyle,creatDate,savePath, nil nil]; for(int i = 0;i < [tempArr count]; i ++){ NSString *strTitle = [tempArr objectAtIndex:i]; UILabel *titleLab = [[UILabel alloc] initWithFrame:CGRectMake(5, 5+i*30, 16*[strTitle length], 25)]; [titleLab setText:strTitle]; [titleLab setTextColor:[WASharedFontStyle mGetSharedFontColor]]; [titleLab setFont:[UIFont systemFontOfSize:16]]; [self.wInfoSV addSubview:titleLab]; NSString *strInfo = [tempArrInfo objectAtIndex:i]; UILabel *infoLab = [[UILabel alloc] initWithFrame:CGRectMake(titleLab.frame.origin.x+titleLab.bounds.size.width+5, 5+i*30, self.view.bounds.size.width-(titleLab.frame.origin.x+titleLab.bounds.size.width+5)-5, 25)]; [infoLab setText:strInfo]; [infoLab setTextColor:[WASharedFontStyle mGetSharedFontColor]]; [infoLab setFont:[UIFont systemFontOfSize:16]]; [self.wInfoSV addSubview:infoLab]; if(i == [tempArr count]-1){ [infoLab setFrame:CGRectMake(titleLab.frame.origin.x+titleLab.bounds.size.width+5, 5+i*30, self.view.bounds.size.width-(titleLab.frame.origin.x+titleLab.bounds.size.width+5)-5, 30*4)]; [infoLab setLineBreakMode:NSLineBreakByWordWrapping]; [infoLab setFont:[UIFont systemFontOfSize:12]]; [infoLab setNumberOfLines:0]; } [self.wInfoSV setContentSize:CGSizeMake(self.view.bounds.size.width, i*45)]; } }
附圖:
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 詳解iOS App中調(diào)用AVAudioPlayer播放音頻文件的用法
- 小程序ios音頻播放沒(méi)聲音問(wèn)題的解決
- 詳解iOS應(yīng)用中播放本地視頻以及選取本地音頻的組件用法
- IOS中微信小程序播放緩存的音頻文件的方法
- iOS開(kāi)發(fā)中音頻工具類(lèi)的封裝以及音樂(lè)播放器的細(xì)節(jié)控制
- iOS開(kāi)發(fā)實(shí)現(xiàn)音頻播放功能
- iOS中的音頻服務(wù)和音頻AVAudioPlayer音頻播放器使用指南
- 解決ios微信下vue項(xiàng)目組件切換并自動(dòng)播放音頻問(wèn)題
- iOS開(kāi)發(fā)中音頻視頻播放的簡(jiǎn)單實(shí)現(xiàn)方法
- iOS使用音頻處理框架The Amazing Audio Engine實(shí)現(xiàn)音頻錄制播放
相關(guān)文章
C++ 中exit(),_exit(),return,abort()函數(shù)的區(qū)別
這篇文章主要介紹了C++ 中exit(),_exit(),return,abort()函數(shù)的區(qū)別的相關(guān)資料,需要的朋友可以參考下2016-12-12iOS開(kāi)發(fā)微信收款到賬語(yǔ)音提醒功能思路詳解
這篇文章主要介紹了iOS開(kāi)發(fā)微信收款到賬語(yǔ)音提醒功能思路詳解,需要的朋友可以參考下2017-09-09詳解iOS App中UISwitch開(kāi)關(guān)組件的基本創(chuàng)建及使用方法
UISwitch組件就是我們平時(shí)在iOS設(shè)置菜單中開(kāi)到的那種左右滑動(dòng)的開(kāi)關(guān)按鈕,當(dāng)然我們?cè)陂_(kāi)發(fā)時(shí)可以進(jìn)行更多的自定義,這里我們就來(lái)詳解iOS App中UISwitch開(kāi)關(guān)組件的基本創(chuàng)建及使用方法2016-05-05IOS開(kāi)發(fā)環(huán)境windows化攻略
本人主要介紹了IOS開(kāi)發(fā)環(huán)境windows化攻略,需要的朋友可以參考下2013-06-06iOS的XMPPFramework簡(jiǎn)單介紹(實(shí)現(xiàn)及時(shí)通信)
這篇文章主要介紹了iOS的XMPPFramework簡(jiǎn)單介紹(實(shí)現(xiàn)及時(shí)通信),實(shí)現(xiàn)了基于XMPP協(xié)議通信的開(kāi)發(fā),有需要的朋友可以了解一下。2016-11-11iOS中使用UIDatePicker制作時(shí)間選擇器的實(shí)例教程
這篇文章主要介紹了iOS中使用UIDatePicker制作時(shí)間選擇器的實(shí)例教程,實(shí)例中未選中的時(shí)間項(xiàng)目會(huì)講解一個(gè)將其變透明的方法,非常給力,需要的朋友可以參考下2016-05-05IOS 獲取網(wǎng)絡(luò)圖片大小實(shí)例詳解
這篇文章主要介紹了IOS 獲取網(wǎng)絡(luò)圖片大小實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下2017-06-06