2017-11-08 4 views
-2

Swiftライブラリを目的のプロジェクトにインポートするとき、この問題に直面していますが、迅速なプロジェクトで作業しています。 ここにクラスがあります。私はポッドを経由してライブラリをインポート関数型でない値を呼び出すことができません。[AVAssetTrack]

  1. を確認してください。

  2. 次に、迅速なブリッジファイルを追加してから、アプリケーションを実行してからエラーが発生します。

  3. は、ここで問題にHere is the problem

コードです:また、この問題に直面して

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) 
    } 
} 
+0

assetTrackはキャストについて言及する必要がある配列を返します。[AVAssetTrack] –

答えて

-1
guard let assetTrack = asset.tracks.first else { 
      NSLog("FDWaveformView failed to load AVAssetTrack") 
      completionHandler(nil) 
      return 
     } 
+3

コードのみの回答は低品質とみなされます。このコードが問題をどのように修正するかについての説明を追加できますか? – Dijkgraaf

0

午前、以下のように変更します。あなたのために、このかもしれ作品{ のNSLog( "FDWaveformViewはAVAssetTrackのロードに失敗しました") completionHandler(ゼロ) リターン }

他の1次回:

ガードはassetTrack = asset.tracks(AVMediaTypeAudio withMediaType)をしましょう。

関連する問題