如何设置 YouTube api 在上传视频时更频繁地触发事件 ProgressChanged?
How can I set YouTube api to fire event ProgressChanged more frequently when uploading video?
我可以看到每上传 10MB 就会触发一次事件,但我想更频繁地获取进度。
假设文件大小小于10MB,则起点和终点之间将没有进度信息。
我尝试了InsertMediaUpload.GetProgress()
,但它只是return ProgressChanged 的上传值,而不是当前值。
您可以通过在 InsertMediaUpload
请求中更改 ChunkSize
属性 来实现此目的。
The default chunk size is 10MB, but you can change it by setting the ChunkSize property on the request to any multiple of 256KB.
我使用可用的样本 here 对此进行了测试。
在 Run()
和
中设置 ChunkSize
之后
videosInsertRequest.ChunkSize = 262144;
或
videosInsertRequest.ChunkSize = ResumableUpload.MinimumChunkSize;
我可以看到 videosInsertRequest_ProgressChanged
处理程序被更频繁地调用。
我认为可以通过在视频上传时检查 GetProgress().BytesSent
来增加进度报告,但这也只会在每次 "chunk" 后更新(因此我们可以获得的最频繁的报告是由 ChunkSize
设置并在 ProgressChanged
处理程序中捕获)。
我可以看到每上传 10MB 就会触发一次事件,但我想更频繁地获取进度。
假设文件大小小于10MB,则起点和终点之间将没有进度信息。
我尝试了InsertMediaUpload.GetProgress()
,但它只是return ProgressChanged 的上传值,而不是当前值。
您可以通过在 InsertMediaUpload
请求中更改 ChunkSize
属性 来实现此目的。
The default chunk size is 10MB, but you can change it by setting the ChunkSize property on the request to any multiple of 256KB.
我使用可用的样本 here 对此进行了测试。
在 Run()
和
ChunkSize
之后
videosInsertRequest.ChunkSize = 262144;
或
videosInsertRequest.ChunkSize = ResumableUpload.MinimumChunkSize;
我可以看到 videosInsertRequest_ProgressChanged
处理程序被更频繁地调用。
我认为可以通过在视频上传时检查 GetProgress().BytesSent
来增加进度报告,但这也只会在每次 "chunk" 后更新(因此我们可以获得的最频繁的报告是由 ChunkSize
设置并在 ProgressChanged
处理程序中捕获)。