Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用MediaElement WPF下载进度_C#_Wpf - Fatal编程技术网

C# 使用MediaElement WPF下载进度

C# 使用MediaElement WPF下载进度,c#,wpf,C#,Wpf,我使用MediaElement播放流音乐,并通过下载进度获得该文件的下载百分比,但它始终为0或1。如何获得该文件的实际加载百分比。 谢谢下载进度是一个介于0和1之间的百分比值。所以你必须把它乘以100。 我认为我们需要根据条件手动增加进度条的值,下面是代码示例 //Create a Delegate that matches //the Signature of the ProgressBar's SetValue method private delegate void UpdateProg

我使用MediaElement播放流音乐,并通过下载进度获得该文件的下载百分比,但它始终为0或1。如何获得该文件的实际加载百分比。
谢谢下载进度是一个介于0和1之间的百分比值。所以你必须把它乘以100。
我认为我们需要根据条件手动增加进度条的值,下面是代码示例

//Create a Delegate that matches 
//the Signature of the ProgressBar's SetValue method
private delegate void UpdateProgressBarDelegate(
        System.Windows.DependencyProperty dp, Object value);


private void Process()
{
    //Configure the ProgressBar
    ProgressBar1.Minimum = 0;
    ProgressBar1.Maximum = short.MaxValue;
    ProgressBar1.Value = 0;

    //Stores the value of the ProgressBar
    double value = 0;

    //Create a new instance of our ProgressBar Delegate that points
    // to the ProgressBar's SetValue method.
    UpdateProgressBarDelegate updatePbDelegate = 
        new UpdateProgressBarDelegate(ProgressBar1.SetValue);

    //Tight Loop: Loop until the ProgressBar.Value reaches the max
    do
    {
        value += 1;

        /*Update the Value of the ProgressBar:
            1) Pass the "updatePbDelegate" delegate
               that points to the ProgressBar1.SetValue method
            2) Set the DispatcherPriority to "Background"
            3) Pass an Object() Array containing the property
               to update (ProgressBar.ValueProperty) and the new value */
        Dispatcher.Invoke(updatePbDelegate, 
            System.Windows.Threading.DispatcherPriority.Background, 
            new object[] { ProgressBar.ValueProperty, value });
    }
    while (ProgressBar1.Value != ProgressBar1.Maximum);
}

这里是完整的

DownloadProgress是一个介于0和1之间的百分比值。但DownloadProgress不是文件的下载进度,DownloadProgress是数据包的下载进度,甚至mediaElement也可以。我去获取文件的下载进度。