[英]Cannot call value of non-function type '[AVAssetTrack]'
When i am importing Swift library in objective c project then i am facing this problem but its working with swift project. 当我在目标C项目中导入Swift库时,我遇到了这个问题,但它与swift项目一起使用。 Here is the class.
这是课程。 Please review
请查阅
I import library via pod. 我通过pod导入库。
Then add swift bridging file and then build after then run application then its give me error. 然后添加快速桥接文件,然后在运行应用程序之后构建,然后给我错误。
Code: 码:
final class FDAudioContext {
/// The audio asset URL used to load the context
public let audioURL: URL
/// Total number of samples in loaded asset
public let totalSamples: Int
/// Loaded asset
public let asset: AVAsset
// Loaded assetTrack
public let assetTrack: AVAssetTrack
private init(audioURL: URL, totalSamples: Int, asset: AVAsset, assetTrack: AVAssetTrack) {
self.audioURL = audioURL
self.totalSamples = totalSamples
self.asset = asset
self.assetTrack = assetTrack
}
public static func load(fromAudioURL audioURL: URL, completionHandler: @escaping (_ audioContext: FDAudioContext?) -> ()) {
let asset = AVURLAsset(url: audioURL, options: [AVURLAssetPreferPreciseDurationAndTimingKey: NSNumber(value: true as Bool)])
guard let assetTrack = asset.tracks(withMediaType: AVMediaType.audio).first else {
NSLog("FDWaveformView failed to load AVAssetTrack")
completionHandler(nil)
return
}
asset.loadValuesAsynchronously(forKeys: ["duration"]) {
var error: NSError?
let status = asset.statusOfValue(forKey: "duration", error: &error)
switch status {
case .loaded:
guard
let formatDescriptions = assetTrack.formatDescriptions as? [CMAudioFormatDescription],
let audioFormatDesc = formatDescriptions.first,
let asbd = CMAudioFormatDescriptionGetStreamBasicDescription(audioFormatDesc)
else { break }
let totalSamples = Int((asbd.pointee.mSampleRate) * Float64(asset.duration.value) / Float64(asset.duration.timescale))
let audioContext = FDAudioContext(audioURL: audioURL, totalSamples: totalSamples, asset: asset, assetTrack: assetTrack)
completionHandler(audioContext)
return
case .failed, .cancelled, .loading, .unknown:
print("FDWaveformView could not load asset: \(error?.localizedDescription ?? "Unknown error")")
}
completionHandler(nil)
}
}
xcode 9.3 try xcode 9.3试试
public static func load(fromAudioURL audioURL: URL, completionHandler: @escaping (_ audioContext: FDAudioContext?) -> ()) {
let asset = AVURLAsset(url: audioURL, options: [AVURLAssetPreferPreciseDurationAndTimingKey: NSNumber(value: true as Bool)])
/// guard let assetTrack = asset.tracks(withMediaType: AVMediaType.audio).first else {
guard let assetTrack = asset.tracks(withMediaType: AVMediaTypeAudio).first else {
NSLog("FDWaveformView failed to load AVAssetTrack")
completionHandler(nil)
return
}
am also facing this issue and change like below. 我也面临着这个问题,并进行如下更改。
guard let assetTrack = asset.tracks(withMediaType: AVMediaTypeAudio).first else {
NSLog("FDWaveformView failed to load AVAssetTrack")
completionHandler(nil)
return
}
this may works for you. 这可能适合您。
guard let assetTrack = asset.tracks.first else {
NSLog("FDWaveformView failed to load AVAssetTrack")
completionHandler(nil)
return
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.