I am new in MVVMCross and currently struggling with a binding issue. Trying to bind the URL of an video with the VideoView component in android.
- Is there any Mvx.MvxBind tag that can do it automatically?
- Otherwise, how can i pass the URL from the MvxViewModel to the MvxActivity?
If the first option is not possible i will try to get the URL and play the video as explained here: http://developer.xamarin.com/recipes/android/media/video/play_video/
Thanks in advance.
MvvmCross is very flexible. What you're asking for is not something that is built-in, but you can easily extend MvvmCross to add support for it.
MvvmCross has what are called Binding Builders. This is where you register custom Target Bindings. A binding takes a type, like VideoView, and a property name like "VideoUri".
When MvvmCross sees a binding attribute like:
local:MvxBind="VideoUri MyVideoUri"
it will take the property value from MyVideoUri, then call the custom binding, which ulimiately will callvideoView.SetVideoURI()
.Here are the steps you need to take.
1) In your Android project, edit Setup.cs and add the following, to register your custom binding builder.
2) Create a custom binding builder that subclasses the default Android binding builder:
3) Create a custom target binding for type VideoView and property "VideoUri":
To use it in your layout, simply create the following:
1) In your layout.xml
2) In your ViewModel, add a property for MyVidoeUri
3) In you View, you can start the video like this:
Look at the source for MvxAndroidBindingBuilder to see the current bindings. https://github.com/MvvmCross/MvvmCross/blob/bbf9a2ac76e74d9404f4b57036c6e29dfe2cc6c3/Cirrious/Cirrious.MvvmCross.Binding.Droid/MvxAndroidBindingBuilder.cs
Hope this helps.