How to download video and play video using media element in .net maui

Haider Ali Faizi 100 Reputation points
2023-09-12T17:18:39.97+00:00

I am working on .net maui toolkit media element player. Can anyone tell me how can i download video into local storage but hidden from user and also how can i show progress bar of downloading video. After store, how can I play it also using Media Element player of .net maui. I have seen a question (https://learn.microsoft.com/en-us/answers/questions/451647/how-to-download-video-to-local-stoarge-and-how-to) but where only they store video temporary not permanently.

Developer technologies | .NET | .NET MAUI
0 comments No comments
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,126 Reputation points Microsoft External Staff
    2023-09-13T06:03:31.8166667+00:00

    Hello,

    MediaElement does not include an API for downloading files.

    Downloading the video and playing the video are separate steps.

    For the download part of the file, you can download the file via HTTPClient during the event where the video starts playing.

    <toolkit:MediaElement Source="url_link"
                          MediaOpened="MediaElement_MediaOpened" />
    
    private async void MediaElement_MediaOpened(object sender, EventArgs e)
    {
        var media = sender as MediaElement;
        if (media != null)
        {
            var url = media.Source.ToString();
            using (var webclient = new HttpClient())
            {
    		// For information on how to download files using HTTPClient and calculate download progress, please search for Progress bar with HttpClient keywords.
            }
        }
    }
    

    how can i download video into local storage but hidden from user

    You could refer to File system helpers for downloading the video into app Cache directory.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.