Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Download videos from url to play offline

$
0
0

Hello!

I need to download videos from an url and play it offline.

Right now I download the videos and save ot in Byte[] .... is this correct? or do I have to download in another way?

My Code:
ViewModel - Call webApi to GetVideo

var video = await webApiService.GetVideo<Video>();

WebApi - ReadAsByteArray

var responseStream = await response.Content.ReadAsByteArrayAsync();

ViewModel - Dependency Service to Save Video File

string result = Xamarin.Forms.DependencyService.Get<IFileSystemService>().SaveVideo(video, "video01.mp4");

Project.Droid save as byte[]

public string SaveVideo(byte[] videoBytes, string fileName)
`{
if (videoBytes == null)
{
return null;
}

        var documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
        var filePath = Path.Combine(documentsPath, fileName);
        File.WriteAllBytes(filePath, videoBytes);

        return filePath;
    }`

Then I try to get the video but it doesnt work :|

I tried to ways first getting the bytes from ViewModel

var bytes = Xamarin.Forms.DependencyService.Get<IFileSystemService>().GetBytes(PathVideo);

        `if (bytes != null)
        {
            VideoBytes = bytes;
        }`

And Second getting the path

`var pathFiles = Xamarin.Forms.DependencyService.Get().GetFiles(directory);

VideoBytes = PathVideo;`

but Nothing works.

This is my XAML

<forms:MediaElement HorizontalOptions="Fill" BackgroundColor="Green" VerticalOptions="Center" HeightRequest="180" x:Name="Media" IsLooping="True" AreTransportControlsEnabled="true" Source="{Binding VideoBytes}"/>

I am using a nuget InTheHand to play video this work good if you play it from url but I still can't play offline.

Any sugestion?

Regards


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>