错误如下
dataCorrupted(Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "video_preview_play_info", intValue: nil), CodingKeys(stringValue: "live_transcoding_task_list", intValue: nil), _JSONKey(stringValue: "Index 2", intValue: 2), CodingKeys(stringValue: "url", intValue: nil)], debugDescription: "Invalid URL string.", underlyingError: nil))
调用代码
let playInfo = try await ali_client
.authorize()
.send(
AliyunpanScope.Video.GetVideoPreviewPlayInfo(
.init(
drive_id: file.drive_id,
file_id: file.file_id)))
错误原因
返回的json数据中url字段的值是空。
解决办法
修改Aliyunpan的AliyunpanFile.swift的源码,具体为
在LiveTranscodingTask结构体中自定义解码方法,捕获url的解析
即添加如下解析代码
public init(from decoder: Decoder) throws {
let container: KeyedDecodingContainer<AliyunpanFile.VideoPreviewPlayInfo.LiveTranscodingTask.CodingKeys> = try decoder.container(keyedBy: AliyunpanFile.VideoPreviewPlayInfo.LiveTranscodingTask.CodingKeys.self)
self.template_id = try container.decode(String.self, forKey: AliyunpanFile.VideoPreviewPlayInfo.LiveTranscodingTask.CodingKeys.template_id)
self.template_name = try container.decodeIfPresent(String.self, forKey: AliyunpanFile.VideoPreviewPlayInfo.LiveTranscodingTask.CodingKeys.template_name)
self.template_width = try container.decodeIfPresent(Int.self, forKey: AliyunpanFile.VideoPreviewPlayInfo.LiveTranscodingTask.CodingKeys.template_width)
self.template_height = try container.decodeIfPresent(Int.self, forKey: AliyunpanFile.VideoPreviewPlayInfo.LiveTranscodingTask.CodingKeys.template_height)
self.keep_original_resolution = try container.decodeIfPresent(Bool.self, forKey: AliyunpanFile.VideoPreviewPlayInfo.LiveTranscodingTask.CodingKeys.keep_original_resolution)
self.stage = try container.decodeIfPresent(String.self, forKey: AliyunpanFile.VideoPreviewPlayInfo.LiveTranscodingTask.CodingKeys.stage)
self.status = try container.decode(AliyunpanFile.VideoPreviewPlayInfo.Status.self, forKey: AliyunpanFile.VideoPreviewPlayInfo.LiveTranscodingTask.CodingKeys.status)
do {
self.url = try container.decodeIfPresent(URL.self, forKey: AliyunpanFile.VideoPreviewPlayInfo.LiveTranscodingTask.CodingKeys.url)
} catch {
print("视频url解析错误 wkun");
self.url = nil
}
}
![](https://img.haomeiwen.com/i14458179/ec9e7887478794ef.png)
网友评论