问题描述
结果我得到的是所有的时间负数
在一种新的形式,我添加了一个长变量:
长totalBytes = 0;
公共静态INT fileuploadpercentages = 0;
然后我有这样的事件:
私人无效videosInsertRequest_ProgressChanged(IUploadProgress OBJ)
{
stringProgressReport [1] = obj.Status.ToString();
如果(stringProgressReport [1] ==上传)
{
fileuploadpercentages =(int)的Math.Round(((双)obj.BytesSent)/ totalBytes * 100);
uploadstatus =上传文件;
}
}
当我使用就行了一个破发点
fileuploadpercentages =(int)的Math.Round(((双)obj.BytesSent)/ totalBytes * 100);
我看到BytesSent = 786432个
然后我继续下去。
现在我看到BytesSent = 1572864
下一页BytesSent = 2359296
的
问题是totalBytes所有的时间0
我想要得到的是百分比进度1%2%3%......直到100%,如果它的跳跃是不可能的。那些1%,2%,3%,那么其他的跳跃,但我想在fileuploadpercentages百分比上传进度
负数我fileuploadpercentages得到的是:-2147483648
这事件是我使用YouTube的上传文件的一部分。
这是我上传的方法到YouTube:在这个方法我注册到1videosInsertRequest_ProgressChanged1事件
UserCredential UC = NULL ;
私人无效UploadVideo(字符串文件名,字符串VideoTitle,串影片说明)
{
试
{
变种youtubeService =新YouTubeService(新BaseClientService.Initializer()
{
HttpClientInitializer =凭证,
=应用程序名称Assembly.GetExecutingAssembly()的GetName()名称
。});
video.Snippet =新VideoSnippet();
video.Snippet.Title = VideoTitle;
video.Snippet.Description =视频描述;
video.Snippet.Tags =新的字符串[] {TAG1,标签2};
video.Status =新VideoStatus();
video.Status.PrivacyStatus =公开;使用
(VAR FILESTREAM =新的FileStream(文件名,FileMode.Open))
{
const int的KB = 0x400的;
VAR minimumChunkSize = 256 * KB;
VAR videosInsertRequest = youtubeService.Videos.Insert(视频,
片段,状态,文件流,视频/ *);
videosInsertRequest.ProgressChanged + = videosInsertRequest_ProgressChanged;
videosInsertRequest.ResponseReceived + =
videosInsertRequest_ResponseReceived;
//默认块大小为10MB,这里将使用1MB。
videosInsertRequest.ChunkSize = minimumChunkSize * 3;
DT = DateTime.Now;
videosInsertRequest.Upload();
}
}
赶上(例外错误)
{
串errorss = errors.ToString();
}
}
初始化 totalBytes = fileStream.Length;
在 videosInsertRequest.Upload();
The result I get is all the time a negative number.
In a new form, I added a long variable:
long totalBytes = 0;
public static int fileuploadpercentages = 0;
Then I have this event:
private void videosInsertRequest_ProgressChanged(IUploadProgress obj)
{
stringProgressReport[1] = obj.Status.ToString();
if (stringProgressReport[1] == "Uploading")
{
fileuploadpercentages = (int)Math.Round(((double)obj.BytesSent) / totalBytes * 100);
uploadstatus = "uploading file";
}
}
When I'm using a break point on the line:
fileuploadpercentages = (int)Math.Round(((double)obj.BytesSent) / totalBytes * 100);
I see that BytesSent = 786432Then I continue.
Now I see that BytesSent = 1572864
Next BytesSent = 2359296
The problem is totalBytes all the time 0
What I want to get is the percentages progress 1% 2% 3%...untill 100% if it's not possible in jumps of ones 1% 2% 3% then other jumps but i want to get in fileuploadpercentages the percentages upload progress.
The negative number i get in fileuploadpercentages is: -2147483648
This event is part of the youtube file upload I'm using.This is my upload method to youtube: In this method I register to the 1videosInsertRequest_ProgressChanged1 event.
UserCredential uc = null;
private void UploadVideo(string FileName, string VideoTitle, string VideoDescription)
{
try
{
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = Assembly.GetExecutingAssembly().GetName().Name
});
video.Snippet = new VideoSnippet();
video.Snippet.Title = VideoTitle;
video.Snippet.Description = VideoDescription;
video.Snippet.Tags = new string[] { "tag1", "tag2" };
video.Status = new VideoStatus();
video.Status.PrivacyStatus = "public";
using (var fileStream = new FileStream(FileName, FileMode.Open))
{
const int KB = 0x400;
var minimumChunkSize = 256 * KB;
var videosInsertRequest = youtubeService.Videos.Insert(video,
"snippet,status", fileStream, "video/*");
videosInsertRequest.ProgressChanged +=videosInsertRequest_ProgressChanged;
videosInsertRequest.ResponseReceived +=
videosInsertRequest_ResponseReceived;
// The default chunk size is 10MB, here will use 1MB.
videosInsertRequest.ChunkSize = minimumChunkSize * 3;
dt = DateTime.Now;
videosInsertRequest.Upload();
}
}
catch (Exception errors)
{
string errorss = errors.ToString();
}
}
Initialize totalBytes = fileStream.Length;
before videosInsertRequest.Upload();
这篇关于我如何计算百分比进展,我一直在获得负数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!