Skip to content

Commit

Permalink
[CastIt] Improved the progress indicator while downloading ffmpeg
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfteam committed Sep 22, 2020
1 parent e4d1281 commit 2158c91
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CastIt/Common/Utils/FileUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ private static bool IsVideoOrMusicFile(string mrl, bool checkForVideo)
: AppConstants.AllowedMusicFormats.Contains(ext, StringComparer.OrdinalIgnoreCase);
}

private static string GetBytesReadable(long i)
public static string GetBytesReadable(long i)
{
// Get absolute value
long absolute_i = i < 0 ? -i : i;
Expand Down
30 changes: 29 additions & 1 deletion CastIt/ViewModels/Dialogs/DownloadDialogViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
using MvvmCross.Logging;
using MvvmCross.Navigation;
using MvvmCross.Plugin.Messenger;
using MvvmCross.ViewModels;
using System;
using System.Threading.Tasks;
using Xabe.FFmpeg;
using Xabe.FFmpeg.Downloader;

namespace CastIt.ViewModels.Dialogs
Expand All @@ -17,6 +19,8 @@ public class DownloadDialogViewModel : BaseDialogViewModelResult<bool>
private readonly ITelemetryService _telemetryService;

private bool _isDownloading;
private double _downloadedProgress;
private string _downloadedProgressText;
#endregion

#region Properties
Expand All @@ -25,6 +29,18 @@ public bool IsDownloading
get => _isDownloading;
set => SetProperty(ref _isDownloading, value);
}

public double DownloadedProgress
{
get => _downloadedProgress;
set => this.RaiseAndSetIfChanged(ref _downloadedProgress, value);
}

public string DownloadedProgressText
{
get => _downloadedProgressText;
set => this.RaiseAndSetIfChanged(ref _downloadedProgressText, value);
}
#endregion

public DownloadDialogViewModel(
Expand Down Expand Up @@ -61,7 +77,19 @@ private async Task DownloadMissingFiles()
{
var path = FileUtils.GetFFMpegFolder();
Logger.Info($"{nameof(DownloadMissingFiles)}: Downloading missing files. Save path is = {path}");
await FFmpegDownloader.GetLatestVersion(FFmpegVersion.Official, path);
var progress = new Progress<ProgressInfo>((p) =>
{
var downloaded = (double)p.DownloadedBytes / p.TotalBytes * 100;
if (downloaded > 100)
downloaded = 100;
if (downloaded > DownloadedProgress)
{
DownloadedProgressText = $"{FileUtils.GetBytesReadable(p.DownloadedBytes)} / {FileUtils.GetBytesReadable(p.TotalBytes)}";
DownloadedProgress = downloaded;
}
});
await Task.Delay(500);
await FFmpegDownloader.GetLatestVersion(FFmpegVersion.Official, path, progress).ConfigureAwait(false);
filesWereDownloaded = true;
}
catch (Exception e)
Expand Down
25 changes: 20 additions & 5 deletions CastIt/Views/Dialogs/DownloadDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,30 @@
<LineBreak />
<Run Text="{Binding [ClickCancelToCloseTheApp], Mode=OneWay}" />
</TextBlock>
<ProgressBar
<StackPanel
Grid.Row="0"
Grid.Column="0"
Grid.ColumnSpan="2"
Height="20"
Margin="16,16,16,0"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
IsIndeterminate="True"
Style="{StaticResource AppProgressBarStyle}"
Visibility="{Binding IsDownloading, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}" />
Orientation="Vertical"
Visibility="{Binding IsDownloading, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}">

<ProgressBar
Height="20"
VerticalAlignment="Center"
Maximum="100"
Minimum="0"
Style="{StaticResource AppProgressBarStyle}"
Value="{Binding DownloadedProgress, Mode=OneWay}" />

<TextBlock
Margin="0,10,0,0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Text="{Binding DownloadedProgressText}" />
</StackPanel>
<Button
Grid.Row="1"
Grid.Column="0"
Expand Down

0 comments on commit 2158c91

Please sign in to comment.