You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PhotoPicker无法选取长视频且加载进度停滞的问题求助

PhotoPicker无法选取长视频且加载进度停滞的问题求助

大家好,我最近在做SwiftUI项目里的单视频选取功能,是照着苹果的示例代码来写的,目前的核心代码如下:

@Published var videoSelection: PhotosPickerItem? = nil {
    didSet {
        if let videoSelection {
            let progress = loadTransferable(from: videoSelection)
            
            videoState = .loading(progress)
        } else {
            videoState = .empty
        }
    }
}

enum VideoState {
    case empty, loading(Progress), success(URL), failure(any Error)
}
@Published var videoState: VideoState? {
    didSet {
        print(videoState)
    }
}

对应的加载方法是这样的:

private func loadTransferable(from videoSelection: PhotosPickerItem) -> Progress {
    return videoSelection.loadTransferable(type: Movie.self) { result in
        switch result {
        case .success(let movie?):
            if let url = movie.url {
                self.videoState = .success(url)
            } else {
                self.videoState = .failure(NSError(domain: "VideoError", code: -1, userInfo: [NSLocalizedDescriptionKey: "无法获取视频URL"]))
            }
        case .success(nil):
            self.videoState = .failure(NSError(domain: "VideoError", code: -2, userInfo: [NSLocalizedDescriptionKey: "未获取到视频内容"]))
        case .failure(let error):
            self.videoState = .failure(error)
        }
    }
}

现在遇到了一个棘手的问题:选取短视频的时候流程完全正常,进度能正常更新,最后也能成功拿到视频URL;但只要选长视频,加载进度就直接停滞住了,完全没有任何推进,也不会触发后面的成功或失败回调。有没有小伙伴遇到过类似的情况?求指点一下怎么解决这个问题,万分感谢!

备注:内容来源于stack exchange,提问作者dz902

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.17 09:33:01