国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS獲取本地音頻文件(屬性/信息)

2020-07-26 02:25:16
字體:
來源:轉載
供稿:網友

本文實例為大家分享了iOS獲取本地音頻文件的具體代碼,供大家參考,具體內容如下

獲取本地音頻文件地址:

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 ];//隨便取一個,說明   //文件管理,取得文件屬性    NSFileManager *fm = [NSFileManager defaultManager];   NSDictionary *dictAtt = [fm attributesOfItemAtPath:filePath error:nil];       //取得音頻數據      NSURL *fileURL=[NSURL fileURLWithPath:filePath];   AVURLAsset *mp3Asset=[AVURLAsset URLAssetWithURL:fileURL options:nil];        NSString *singer;//歌手   NSString *song;//歌曲名    UIImage *image;//圖片     NSString *albumName;//專輯名   NSString *fileSize;//文件大小   NSString *voiceStyle;//音質類型   NSString *fileStyle;//文件類型   NSString *creatDate;//創建日期   NSString *savePath; //存儲路徑      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;//歌手       }       //      專輯名稱       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 = @"標準";   }else if(tempFlo > 10){     voiceStyle = @"高清";   }         NSArray *tempArr = [[NSArray alloc] initWithObjects:@"歌手:",@"歌曲名稱:",@"專輯名稱:",@"文件大小:",@"音質類型:",@"文件格式:",@"創建日期:",@"保存路徑:", 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)];        }    } 

附圖:

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 洛南县| 嘉黎县| 乐业县| 渭南市| 封开县| 长海县| 平塘县| 监利县| 札达县| 宁城县| 四平市| 大连市| 丰宁| 宾川县| 登封市| 孝感市| 木兰县| 裕民县| 镇安县| 和田县| 赤城县| 江西省| 云安县| 时尚| 铁岭市| 晋江市| 桃江县| 玉树县| 本溪| 色达县| 个旧市| 三亚市| 镇赉县| 吉林市| SHOW| 大同市| 宿松县| 天津市| 渭南市| 那坡县| 延寿县|