Forum Cross Platform with Xamarin

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.

Best Answer


  • jimuttjimutt SEMember
    edited July 2016

    @AdamP Thank you, I've got a working solution now. Yes, I am aware of the deprecation, I'm only using Silverlight due to some compatibility requirements of some other plugins which I were using earlier. I might look into moving over to WP RT instead in the future though.

Sign In or Register to comment.