PropertyChanged, wie damit umgehen?

  • C#

Es gibt 3 Antworten in diesem Thema. Der letzte Beitrag () ist von ErfinderDesRades.

    PropertyChanged, wie damit umgehen?

    Hallo ihr Lieben,

    ich versuche mich gerade an der NYoutubeDL Library, welche den Zugang zur youtube-dl Library in .NET ermöglicht.

    Der Download funktioniert, allerdings habe ich Probleme den Status in einer ProgressBar wieder zu geben.

    Die Library: gitlab.com/BrianAllred/NYoutubeDL

    Mein Code:

    C#-Quellcode

    1. public void StartDownload(string url)
    2. {
    3. client.Options.FilesystemOptions.Output = @"C:\Users\Admin\Desktop\test\testasync.mp3";
    4. client.Options.PostProcessingOptions.ExtractAudio = true;
    5. client.VideoUrl = url;
    6. client.YoutubeDlPath = Directory.GetCurrentDirectory() + @"\lib\dl.exe";
    7. client.PrepareDownloadAsync();
    8. client.DownloadAsync();
    9. client.Info.PropertyChanged += delegate
    10. {
    11. DownloadInfo info = new DownloadInfo();
    12. progressBar1.Value = info.VideoProgress;
    13. };
    14. }


    Was mache ich falsch? Ganz wage wird es hier erklärt, für viele wahrscheinlich eine ausreichende Erklärung, ich kann damit allerdings nichts anfangen und würde es gerne verstehen.

    C#-Quellcode

    1. Subscribe to download information updates. Hard subscription is optional, the DownloadInfo class implements INotifyPropertyChanged.
    2. youtubeDl.Info.PropertyChanged += delegate { <your code here> };


    Grüße
    Meine Projekte:

    WizSearch: 100%
    Ansehen
    Wahrscheinlich gehört die info nicht zum aktuellen Client und bekommt deshalb keine Informationen?

    Ich habe es jetzt so versucht:

    C#-Quellcode

    1. client.Info.PropertyChanged += (o, args) =>
    2. {
    3. DownloadInfo info = (DownloadInfo)o;
    4. string status = info.Status;
    5. this.InvokeIfRequired(() => richTextBox1.AppendText(info.VideoProgress.ToString()));
    6. this.InvokeIfRequired(() => richTextBox1.AppendText(status));
    7. };


    Ich bekomme auch etwas angezeigt, allerdings erst NACHDEM der Download fertig ist. Warum ist das so?
    Meine Projekte:

    WizSearch: 100%
    Ansehen
    Das ist zwar nicht die Antwort auf meine Frage, aber immerhin hast du das ursprünglich geschilderte Problem gelöst - und nun ein Neues - also definitiv ein Fortschritt.
    (Wenn ich auch der Ansicht bin, ein Programmierer sollte die Frage besser beantworten können als mit "Wahrscheinlich...?")

    Vielleicht liegt dein neues Problem an der Reihenfolge, also probierma

    C#-Quellcode

    1. public void StartDownload(string url){
    2. client.Options.FilesystemOptions.Output = @"C:\Users\Admin\Desktop\test\testasync.mp3";
    3. client.Options.PostProcessingOptions.ExtractAudio = true;
    4. client.VideoUrl = url;
    5. client.YoutubeDlPath = Directory.GetCurrentDirectory() + @"\lib\dl.exe";
    6. client.PrepareDownloadAsync();
    7. client.Info.PropertyChanged += delegate {
    8. DownloadInfo info = new DownloadInfo();
    9. progressBar1.Value = info.VideoProgress;
    10. };
    11. client.DownloadAsync();
    12. }
    Mehr fällt mir aber auch nicht ein - ich kenne dieses NYoutubeDL - Dingens nicht.


    Ah - vielleicht musses auch mittm Async-Pattern gestrickt werden - probierma:

    C#-Quellcode

    1. async public void StartDownload(string url){
    2. client.Options.FilesystemOptions.Output = @"C:\Users\Admin\Desktop\test\testasync.mp3";
    3. client.Options.PostProcessingOptions.ExtractAudio = true;
    4. client.VideoUrl = url;
    5. client.YoutubeDlPath = Directory.GetCurrentDirectory() + @"\lib\dl.exe";
    6. client.PrepareDownloadAsync();
    7. client.Info.PropertyChanged += delegate {
    8. DownloadInfo info = new DownloadInfo();
    9. progressBar1.Value = info.VideoProgress;
    10. };
    11. await client.DownloadAsync();
    12. }
    Aber sicher bin ich nicht - wie gesagt: k.A.