问题描述
我希望能够循环播放实时照片,以便连续播放。
到目前为止,我正在尝试使用 PHLivePhotoViewDelegate
来完成此操作。
import Foundation
import SwiftUI
import PhotosUI
import iOSShared
struct LiveImageView: UIViewRepresentable {
let view: PHLivePhotoView
let model:LiveImageviewmodel?
let delegate = LiveImageLargeMediaDelegate()
init(fileGroupUUID: UUID) {
let view = PHLivePhotoView()
// Without this,in landscape mode,I don't get proper scaling of the image.
view.contentMode = .scaleAspectFit
self.view = view
// Using this to replay live image repeatedly.
view.delegate = delegate
model = LiveImageviewmodel(fileGroupUUID: fileGroupUUID)
guard let model = model else {
return
}
model.getLivePhoto(previewImage: nil) { livePhoto in
view.livePhoto = livePhoto
}
}
func makeUIView(context: Context) -> UIView {
return view
}
func updateUIView(_ uiView: UIView,context: Context) {
guard let model = model else {
return
}
guard !model.started else {
return
}
model.started = true
view.startPlayback(with: .full)
}
}
class LiveImageLargeMediaDelegate: NSObject,PHLivePhotoViewDelegate {
func livePhotoView(_ livePhotoView: PHLivePhotoView,didEndplaybackWith playbackStyle: PHLivePhotoViewPlaybackStyle) {
livePhotoView.stopPlayback()
dispatchQueue.main.asyncAfter(deadline: .Now() + .milliseconds(200)) {
livePhotoView.startPlayback(with: .full)
}
}
}
但没有完全成功。似乎音频确实再次播放,但不是视频。 livePhotoView.stopPlayback
和异步方面只是我尝试的其他更改。我也试过没有这些。
请注意,我不希望用户必须手动更改实时照片(例如,请参阅 NSPredicate to not include Loop and Bounce Live Photos)。
想法?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)