简体   繁体   中英

Xamarin Forms Media Plugin, Get stream or StorageFile from MediaFile

For a PCL application I'm developing I'm using the media plugin for Xamarin Forms by jamesmontemagno ( Github Repo ). I am mainly using the plugin for capturing photos through the device's camera, for this I'm using the TakeVideoAsync method ( Task<MediaFile> TakeVideoAsync(StoreVideoOptions options); ). It returns a [MediaFile][2] object.

The issue I'm facing is that I need to send the image as an email attachment. For this I will implement an "EmailSender" class which will have different implementations for every target platforms (I'm using the PCL approach). Right now I'm working on a Windows Phone 8.1 (Silverlight) implementation. I would like to use Windows.ApplicationModel.Email.EmailManager to send a Windows.ApplicationModel.Email.EmailMessage . An example implementation can be seen in this Stackoverflow answer (Look at the "ComposeEmail" method).


What I need help with: I want to find a way of retrieving the image file (perhaps either as an StorageFile or RandomAccessStream) in order to make an EmailAttachment object from it. From the MediaFile returned by the TakeVideoAsync method in the media plugin I can get a System.IO.Stream , but I haven't found any way of converting it to a RandomAccessStream with the functionality of the .NET version my Xamarin Windows Phone 8.1

All suggestions will be very appreciated.

A Stream object in Windows Phone 8.1 has a .AsRandomStream() extension method in the System.Runtime.WindowsRuntime library. IRandomStream has a .ToStream() extension method in same lib. You can also create a new RandomStream with IRandomAccessStream randomAccessStream = new InMemoryRandomAccessStream(); Hope that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM