iOS音樂的截取-創(chuàng)新互聯(lián)

最近接觸一個(gè)音頻的項(xiàng)目,之前接觸過,不過都是用系統(tǒng)自帶的去實(shí)現(xiàn),沒有仔細(xì)研究

創(chuàng)新互聯(lián)公司科技有限公司專業(yè)互聯(lián)網(wǎng)基礎(chǔ)服務(wù)商,為您提供成都電信服務(wù)器托管,高防物理服務(wù)器租用,成都IDC機(jī)房托管,成都主機(jī)托管等互聯(lián)網(wǎng)服務(wù)。

在網(wǎng)上找到了一個(gè)demo,挺好用,反正效果是實(shí)現(xiàn),非常不錯(cuò)。具體鏈接忘記了。

#pragma mark - 音視頻剪輯,如果是視頻把下面的類型換為AVFileTypeAppleM4V

// assetURL 本地路徑地址

//startTime 開始時(shí)間

//endTime 結(jié)束時(shí)間

//outputPath 裁剪完成后的地址

+ (void)cutAudioVideoResourcePath:(NSURL *)assetURL startTime:(CGFloat)startTime endTime:(CGFloat)endTime complition:(void (^)(NSURL *outputPath,BOOL isSucceed)) completionHandle{

  //  素材

  AVAsset *asset = [AVAsset assetWithURL:assetURL];

  //  導(dǎo)出素材

  AVAssetExportSession *exporter = [[AVAssetExportSessionalloc]initWithAsset:assetpresetName:AVAssetExportPresetAppleM4A];

  //剪輯(設(shè)置導(dǎo)出的時(shí)間段)

  CMTime start =CMTimeMakeWithSeconds(startTime, asset.duration.timescale);

  CMTime duration = CMTimeMakeWithSeconds(endTime - startTime,asset.duration.timescale);

  exporter.timeRange = CMTimeRangeMake(start, duration);

//  輸出路徑

  NSURL *outputPath = [self exporterPath];

  exporter.outputURL = [self exporterPath];

//  輸出格式

  exporter.outputFileType =AVFileTypeAppleM4A;

  exporter.shouldOptimizeForNetworkUse=YES;

//  合成后的回調(diào)

  [exporterexportAsynchronouslyWithCompletionHandler:^{

    switch ([exporter status]) {

      caseAVAssetExportSessionStatusFailed: {

        NSLog(@"合成失敗:%@",[[exporter error] description]);

        completionHandle(outputPath,NO);

      } break;

      caseAVAssetExportSessionStatusCancelled: {

        completionHandle(outputPath,NO);

      } break;

      caseAVAssetExportSessionStatusCompleted: {

        completionHandle(outputPath,YES);

      } break;

      default: {

        completionHandle(outputPath,NO);

      } break;

    }

  }];

}

#pragma mark - 輸出路徑

+ (NSURL *)exporterPath {

  NSInteger nowInter = (long)[[NSDatedate]timeIntervalSince1970];

  NSString *fileName = [NSString stringWithFormat:@"output%ld.mp4",(long)nowInter];

  NSString *documentsDirectory =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES).lastObject;

  NSString *outputFilePath =[documentsDirectory stringByAppendingPathComponent:fileName];

  if([[NSFileManagerdefaultManager]fileExistsAtPath:outputFilePath]){

    [[NSFileManagerdefaultManager]removeItemAtPath:outputFilePatherror:nil];

  }

  return [NSURL fileURLWithPath:outputFilePath];

}

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。

本文標(biāo)題:iOS音樂的截取-創(chuàng)新互聯(lián)
地址分享:http://muchs.cn/article10/dpgddo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)公司、企業(yè)網(wǎng)站制作、網(wǎng)頁設(shè)計(jì)公司、網(wǎng)站維護(hù)云服務(wù)器、網(wǎng)站改版

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站托管運(yùn)營