Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play video from a memory stream inside a xamarin iOS app

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?

like image 885
Kartik Avatar asked Oct 01 '22 09:10

Kartik


2 Answers

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")
like image 105
miguel.de.icaza Avatar answered Oct 05 '22 10:10

miguel.de.icaza


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.

like image 23
jonathanpeppers Avatar answered Oct 05 '22 12:10

jonathanpeppers