0

I have a viewmodel for searching for videos which works great. I have added a play button and upon clicking I want to load a view that renders a VideoView. The search viewmodel contains enough data to generate the video's URL.

What is the best way to render the VideoView?

I've found this example but it appears to be an older version of MvvmCross: https://gist.github.com/Alphapage/3945799

Should I create custom control like N=18 - Android Custom Controls - N+1 Days of MvvmCross? http://www.youtube.com/watch?v=s1LhXdCTsn4&feature=youtube_gdata

If I create a custom control how should I pass the video's URL to the VideoView and start it playing?

I'm sure this is easy to do but I can't find a working example.

Thanks in advance

1 Answer 1

2

You could create a custom view as Stuart does, but rather than inheriting from View inherit from VideoView.

Then create a property called VideoUri, and when ever it's set call the SetVideoUri and start method on the base object. E.g.

Please note the following code was written in notepad, so may need some tweaking :)

public class BindableVideoView : VideoView { private Uri _videoUri = default(Uri); public Uri VideoUri { get{ return _videoUri;} set{ if(_videoUri!=value) { if(base.IsPlaying) { base.StopPlayback(); } } base.SetVideoURI(value); base.Start(); } } } 

You could do things like expose a property for IsPlaying and then your viewmodel could two-way bind to that so your viewmodel would know when you have finished playing the video

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.