123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- //
- // BFMusicManager.swift
- // BFRecordScreenKit
- //
- // Created by Harry on 2022/3/4.
- //
- import Foundation
- import BFMediaKit
- import BFCommonKit
- import BFNetRequestKit
- import Alamofire
- class BFMusicManager {
-
- public class func downloadMusic(model: PQVoiceModel, complete:(@escaping () -> Void)) {
- // BFNetRequestAdaptor.postRequestData(url: "", parames: [:], commonParams: commonParams(), encoding: JSONEncoding.default, isJsonEncodingNormal: true, timein)
- if let path = model.musicPath, let url = URL(string: path) {
-
- let request = URLRequest(url: url)
- let session = URLSession.shared
- let downloadTask = session.downloadTask(with: request,
- completionHandler: { (location:URL?, response:URLResponse?, error:Error?)
- -> Void in
- print("location:\(location)")
- if let locationPath = location?.path {
- BFMusicManager.moveLocation(locationPath: locationPath, model:model)
- }
-
- complete()
- })
- downloadTask.resume()
- }
-
-
- }
-
- fileprivate class func moveLocation(locationPath: String, model: PQVoiceModel) {
- let fileManager = FileManager.default
- let fileName = (model.musicPath! as NSString).lastPathComponent
- let documnets = bgMusicDirectory + fileName + ".mp3"
- createDirectory(path: bgMusicDirectory)
- do {
- try fileManager.moveItem(atPath: locationPath, toPath: documnets)
- model.wavFilePath = documnets
- } catch {
- BFLog(1, message: "移动失败, \(error)")
- }
- print("new location:\(documnets)")
- }
- }
|