Closed AbySwifter closed 5 years ago
我在buildPlayerItem中断点调试,发现
CompositionGenerator.swift 85行
timeline.videoChannel.enumerated().forEach({ (offset, provider) in
for index in 0..<provider.numberOfVideoTracks() {
let trackID: Int32 = getVideoTrackID(for: index) + Int32((offset % 2 + 1) * 1000)
if let compositionTrack = provider.videoCompositionTrack(for: composition, at: index, preferredTrackID: trackID) {
let info = mainVideoTrackInfo.first(where: { $0.track == compositionTrack })
if let info = info {
info.info.append(provider)
} else {
let info = TrackInfo.init(track: compositionTrack, info: [provider])
mainVideoTrackInfo.append(info)
}
}
}
这段代码中,provider.numberOfVideoTracks(),的值始终为0.PHAssetImageResource生成的TrackItem。
我解决了这个问题。在下面的方法里,添加了对Bundle的定义:
private static let emptyAsset: AVAsset? = {
let bundle = Bundle(for: ImageResource.self)
/// 这里添加的3行代码解决了上述问题
if let videoURL = bundle.url(forResource: "black_empty", withExtension: "mp4") {
return AVAsset(url: videoURL)
}
if let bundleURL = bundle.resourceURL?.appendingPathComponent("Cabbage.bundle") {
let resourceBundle = Bundle.init(url: bundleURL)
if let videoURL = resourceBundle?.url(forResource: "black_empty", withExtension: "mp4") {
return AVAsset(url: videoURL)
}
}
if let url = Bundle.main.url(forResource: "black_empty", withExtension: "mp4") {
let asset = AVAsset(url: url)
return asset
}
return nil
}()
这个修改欢迎提交 pr
好的,我会在最近提交PR
我参考VideoCat的Demo从相册中选择了图片
然后检查了,图片的选择,在 resource.prepare中,Image是存在的,status也是 available的。
这是buildItem的方法,视屏和livephoto都没有问题,只有图片无法正常播放,在播放器的时长也不对。
master分支。 xcode 10.2.2 swift 5.0