I am building a app in xamarin that users will use for playing movies. I need the app to play the movie from a memory stream and not from a url or file directly. Is there a player control or library that i can use to play the movie from a mmemory stream?
Since there is no API you can use, what you can do is stream your in-memory representation of the media file at a url.
Use the HttpListener class to create an HTTP server embedded in your application, have it listen say on port 9000, and then have the movie player use an NSUrl like this:
new NSUrl ("http://127.0.0.1:9000/myfile.mov")
Generally its best to use MPMoviePlayerViewController
(doc here) for playing videos on iOS. Sadly it requires an NSUrl
to play the video.
What you'll have to do in order to use it, is save your stream to a temporary file.
Such as:
string path = Path.GetTempFilename();
using (var yourStream = GetYourStream())
using (var fileStream = File.Create(path))
{
await yourStream.CopyToAsync(fileStream);
}
var controller = new MPMoviePlayerViewController(NSUrl.FromFilename(path));
//show the controller
Not quite ideal, but it should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With